/* ── Dialog shell (revamp F4) ───────────────────────────────────────────────
   One pattern for every centred dialog: 16px radius, the deepest shadow,
   a 20px title with a one-line description, the body, and the actions
   right-aligned in the footer. Used by static/lib/ask.js (confirm, text,
   secret, notice) and the template dialogs (annotate, resolve conflict,
   negotiation pack, vendor wizard). P1: fades and scales in from 98%. */

.dialog, .ask-dialog, .annotate-box, .wide-modal-box {
    color: var(--text);
    background: var(--surface);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3), inset 0 0 0 1px var(--border);
    animation: dialog-in var(--dur-enter) var(--ease-out);
}
.dialog, .ask-dialog { width: min(440px, calc(100vw - 32px)); padding: 0; }
/* app.css's reset (`* { margin: 0 }`) removes the browser's `margin: auto`
   that centres a modal <dialog>: every ask.js dialog opened in the top-left
   corner (staging QA 2026-10-07). Put the centring back. */
dialog.dialog, dialog.ask-dialog { margin: auto; max-height: calc(100vh - 32px); }
.dialog::backdrop, .ask-dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }

/* Template dialogs bring their own scrim element. */
.annotate-modal, .wide-modal {
    position: fixed; inset: 0;
    z-index: var(--z-modal);
    display: flex; align-items: center; justify-content: center;
    padding: 24px 16px;
    background: var(--overlay-bg);
}
.annotate-modal[hidden], .wide-modal[hidden] { display: none; }

.dialog-form, .ask-form { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5); }
.annotate-box { width: 420px; max-width: 100%; padding: var(--sp-5); position: relative; }
.wide-modal-box { width: 760px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; }

.dialog-head { display: grid; gap: 4px; }
.dialog-title, .ask-title, .annotate-box h3, .wide-modal-header h3 {
    margin: 0;
    font-size: var(--fs-title);
    line-height: 28px;
    font-weight: 650;
    letter-spacing: -0.015em;
    color: var(--text);
}
.annotate-box h3 { margin-bottom: var(--sp-4); }
.dialog-desc, .ask-message, .annotate-hint {
    margin: 0;
    font-size: var(--fs-13);
    line-height: 1.5;
    color: var(--text-2);
}
.annotate-hint { margin-bottom: var(--sp-3); }
.annotate-hint:empty { display: none; }

/* Fields: label above, control below (forms.css carries the control). */
.dialog-field, .ask-field, .annotate-field {
    display: grid;
    gap: 6px;
    font-size: var(--fs-13);
    font-weight: 500;
    color: var(--text);
}
.annotate-field { margin-bottom: var(--sp-3); }
.annotate-field[hidden] { display: none; }
.ask-field input, .ask-field select, .ask-field textarea, .ask-secret input,
.annotate-field select, .annotate-field input {
    width: 100%;
    min-height: var(--control-h);
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--fs-14);
    font-weight: 400;
    box-sizing: border-box;
}
/* A warning line in a dialog (askText `warning`): the shared .notice-warn,
   without the page gutter; the icon sits on the first line of the text. */
.ask-form .notice { margin: 0; align-items: flex-start; flex-wrap: nowrap; }
.ask-form .notice .notice-ico { margin-top: 2px; }
.ask-secret { display: flex; gap: var(--sp-2); }
.ask-secret input { font-family: var(--mono); }
.dialog-error, .annotate-error { margin: 0 0 var(--sp-3); font-size: var(--fs-12); color: var(--error); }
.annotate-error[hidden], .dialog-error[hidden] { display: none; }

/* Footer: actions right-aligned, primary last. */
.dialog-foot, .ask-actions, .annotate-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-top: var(--sp-2);
}

.wide-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-3);
    padding: 20px 24px 8px;
    border: 0;
}
.wide-modal-body { padding: 8px 24px 24px; overflow-y: auto; }
/* Revamp finish: what used to be inline styles on these modals. */
.wide-modal-box.is-narrow { width: 520px; }
.wide-modal-actions { display: flex; gap: var(--sp-2); }
.annotate-check { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); font-size: var(--fs-13); color: var(--text); }
.vendor-hint { margin: -4px 0 var(--sp-2); }
.wizard-done { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-3); font-size: var(--fs-13); color: var(--text); }

/* Side form (revamp F1): the same dialog shell docked to the right edge,
   full height, for editing one record next to its list. Native <dialog>
   with showModal(): focus stays inside, Escape cancels. */
.dialog.dialog-side {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(460px, 100vw);
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    overflow-y: auto;
    animation: dialog-side-in var(--dur-enter) var(--ease-out);
}
.dialog-side .dialog-form { min-height: 100%; }
.dialog-side .dialog-foot { margin-top: auto; padding-top: var(--sp-3); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); align-items: start; }
.field-row .field, .dialog-side .field { align-content: start; }
.field-checks { display: grid; gap: var(--sp-2); font-size: var(--fs-13); }
.field-checks label { display: flex; align-items: flex-start; gap: var(--sp-2); }
.field-checks input { margin-top: 2px; }
@keyframes dialog-side-in {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .dialog.dialog-side { animation: none; }
}
@media (max-width: 520px) {
    .field-row { grid-template-columns: minmax(0, 1fr); }
    .dialog.dialog-side { border-radius: 0; }
}

@keyframes dialog-in {
    from { opacity: 0; transform: scale(0.98); }
    to   { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
    .annotate-box, .dialog-form, .ask-form { padding: var(--sp-4); }
}
