/* Shared CRUD dialogs. Only the body scrolls; actions remain reachable. */
.app-modal { width: min(580px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 48px); margin: auto; padding: 0; overflow: hidden; color: var(--fg); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: 0 24px 80px #0005; }
.app-modal::backdrop { background: #090f1c99; backdrop-filter: blur(3px); }
.app-modal[open] { animation: modal-enter .16s ease-out; }
.app-modal-form { display: flex; flex-direction: column; max-height: calc(100dvh - 50px); margin: 0; min-height: 0; }
.app-modal-header { display: flex; align-items: flex-start; gap: 14px; padding: 25px 26px 21px; border-bottom: 1px solid var(--line); flex: none; }
.app-modal-heading { min-width: 0; flex: 1; }
.app-modal-header h2 { margin: 0; font-size: 20px; font-weight: 650; line-height: 1.4; letter-spacing: -.03em; overflow-wrap: anywhere; }
.app-modal-header p { margin: 6px 0 0; color: var(--fg-muted); font-size: 12px; line-height: 1.75; }
.app-modal-symbol { display: grid; place-items: center; width: 38px; height: 38px; flex: none; color: var(--accent); background: var(--accent-soft); border-radius: 11px; }
.app-modal-symbol .ico { width: 20px; height: 20px; }
.app-modal-close { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border: 0; border-radius: 8px; color: var(--fg-muted); background: transparent; cursor: pointer; }
.app-modal-close:hover { background: var(--surface-3); color: var(--fg); }
.app-modal-close .ico { width: 19px; height: 19px; }
.app-modal-close:disabled { opacity: .4; cursor: wait; }
.app-modal-body { padding: 22px 26px 24px; overflow-y: auto; overscroll-behavior: contain; min-height: 0; scrollbar-width: thin; }
.app-modal-fields { border: 0; padding: 0; margin: 0; min-width: 0; }
.app-modal-field + .app-modal-field { margin-top: 19px; }
.app-modal-field label { color: var(--fg); margin: 0 0 7px; font-size: 12px; }
.app-modal-field input:not([type=checkbox]), .app-modal-field textarea, .app-modal-field select { font-size: 13px; padding: 11px 12px; width: 100%; border-radius: 8px; }
.app-modal-field textarea { resize: vertical; min-height: 90px; line-height: 1.75; }
.app-modal-field .inline-check { display: flex; gap: 8px; align-items: center; margin: 0; }
.app-modal-field input[type=checkbox] { accent-color: var(--accent); }
.app-modal-hint { margin: 7px 0 0; font-size: 11px; line-height: 1.7; color: var(--fg-muted); }
.app-modal-preview { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 15px; margin-bottom: 22px; }
.app-modal-preview strong { display: block; font-size: 11px; color: var(--fg-muted); margin-bottom: 7px; }
.app-modal-preview p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; font-size: 13px; }
.app-modal-error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; font-size: 12px; line-height: 1.7; padding: 10px 12px; margin: 18px 0 0; overflow-wrap: anywhere; }
.app-modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 17px 26px; border-top: 1px solid var(--line); background: var(--surface); flex: none; }
.app-modal-footer .btn { font-size: 12px; min-height: 40px; }
.app-modal-footer > span { font-size: 11px; color: var(--fg-muted); margin-right: auto; }
.app-modal-danger .app-modal-symbol { color: var(--danger); background: var(--danger-soft); }
.app-modal .btn.modal-destructive { background: var(--danger); color: #fff; }
.app-modal :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-modal input:focus-visible, .app-modal textarea:focus-visible, .app-modal select:focus-visible { outline: none; }
.app-modal-confirm { width: min(460px, calc(100vw - 32px)); }
.app-modal-confirm .app-modal-body:has(.app-modal-error.hidden):not(:has(.app-modal-field,.app-modal-preview)) { display: none; }
.knowledge-editor-modal { width: min(680px, calc(100vw - 32px)); }
.knowledge-editor-modal .knowledge-form { padding: 0; }
.knowledge-editor-modal .knowledge-form label:first-child { margin-top: 0; }
.knowledge-editor-modal .knowledge-field-hint { margin-bottom: 0; }
.knowledge-editor-modal #kbAnswer { min-height: 160px; }
.knowledge-editor-modal .knowledge-form-footer { margin: 0; }
.knowledge-editor-modal .knowledge-form-footer > div { margin: 0; }
@keyframes modal-enter { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .app-modal[open] { animation: none; } }
@media (prefers-color-scheme: dark) { .app-modal { color-scheme: dark; } .app-modal-error { color: #ffa6a6; } }
@media (max-width: 560px) {
  .app-modal { width: calc(100vw - 20px); max-height: calc(100dvh - 24px); border-radius: 14px; }
  .app-modal-form { max-height: calc(100dvh - 26px); }
  .app-modal-header { padding: 19px 17px 17px; gap: 11px; }
  .app-modal-header h2 { font-size: 18px; }
  .app-modal-symbol { display: none; }
  .app-modal-body { padding: 19px 17px; }
  .app-modal-footer { padding: 14px 17px; flex-wrap: wrap; }
  .app-modal-footer > span { width: 100%; }
  .app-modal-footer .btn { padding: 9px 12px; }
}
