/* ==========================================================================
   dialog.css — the ONE dialog system for Owlet.
   Anatomy (used by every dialog):
     <div class="dialog">                        (backdrop, flex-centered)
       <div class="dialog-box dialog--md" role="dialog" aria-modal="true">
         <header class="dlg-head">  icon | title + subtitle | X  </header>
         <div class="dlg-body">     scrolls on its own           </div>
         <footer class="dlg-foot">  right-aligned actions        </footer>
       </div>
     </div>
   Sizes: --sm 420px, --md 560px, --lg 880px. Mobile => bottom sheet.
   ========================================================================== */

/* ---------- backdrop ---------- */
.dialog {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--surface-overlay);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: dlg-fade var(--dur-base) var(--ease-out);
}
@keyframes dlg-fade { from { opacity: 0; } }

/* ---------- box ---------- */
.dialog-box {
    display: flex;
    flex-direction: column;
    width: 440px;
    max-width: 100%;
    max-height: 80vh;
    padding: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-3);
    color: var(--text-1);
    overflow: hidden;
    animation: dlg-in var(--dur-base) var(--ease-out);
}
@keyframes dlg-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
.dialog--sm { width: 420px; }
.dialog--md { width: 560px; }
.dialog--lg { width: 880px; }

/* ---------- header ---------- */
.dlg-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 56px;
    padding: 0 var(--space-4) 0 var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    flex: 0 0 auto;
}
/* Small tinted square that carries the dialog's icon. */
.dlg-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
}
.dlg-icon .icon { width: 16px; height: 16px; }
.dlg-titles { flex: 1; min-width: 0; }
.dlg-title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    color: var(--text-1);
}
.dlg-sub {
    color: var(--text-3);
    font-size: var(--fs-sm);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* X close button: 32px visual, ~40px hit area via negative margin bleed. */
.dlg-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    margin: -4px;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-3);
    flex: 0 0 auto;
}
.dlg-x:hover { background: var(--state-hover); color: var(--text-1); }
.dlg-x .icon { width: 16px; height: 16px; }

/* ---------- body (scrolls on its own) ---------- */
.dlg-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--space-6);
}
.dlg-body > * + * { margin-top: var(--space-4); }

/* ---------- footer ---------- */
.dlg-foot {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    border-top: 1px solid var(--border-subtle);
}
.dlg-foot .dlg-foot-note { margin-right: auto; color: var(--text-3); font-size: var(--fs-sm); }

/* ==========================================================================
   Shared components (used inside dialogs AND menus)
   ========================================================================== */

/* ---------- setting row: label + helper left, control right ---------- */
.set-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
}
.set-row-text { flex: 1; min-width: 0; }
.set-label {
    display: block;
    font-size: var(--fs-base);
    font-weight: var(--fw-medium);
    color: var(--text-1);
}
.set-desc {
    display: block;
    color: var(--text-3);
    font-size: var(--fs-sm);
    margin-top: 2px;
    line-height: 1.4;
}
.set-control { flex: 0 0 auto; display: flex; align-items: center; gap: var(--space-2); }
/* Rows grouped inside a card with 1px dividers. */
.set-group {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    overflow: hidden;
}
.set-group .set-row + .set-row { border-top: 1px solid var(--border-subtle); }
/* Consistent control column: controls never stretch wider than this. */
.set-control > select,
.set-control > input[type="text"],
.set-control > input[type="password"],
.set-control > input[type="number"] { width: 220px; }
.set-control > input[type="number"] { width: 96px; }
/* Tiny "Saved" check that fades in near a changed row. */
.set-saved {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--success);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease-out);
}
.set-saved.is-on { opacity: 1; }

/* ---------- switch ---------- */
.switch { position: relative; display: inline-flex; flex: 0 0 auto; }
.switch input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}
.switch-track {
    position: relative;
    display: block;
    width: 36px;
    height: 20px;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    transition: background var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
}
.switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-3);
    transition: transform var(--dur-fast) var(--ease-out),
                background var(--dur-fast) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: var(--text-on-accent); }
.switch input:focus-visible + .switch-track {
    outline: var(--focus-width) solid var(--focus-ring, var(--accent));
    outline-offset: var(--focus-offset);
}
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch input:disabled { cursor: not-allowed; }

/* ---------- selectable option card (radio/checkbox inside, visually hidden) ---------- */
.opt-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2); }
.opt-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    color: var(--text-1);
    text-align: left;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease-out),
                background var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out);
}
.opt-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.opt-card:hover { border-color: var(--border-strong); background: var(--surface-3); }
.opt-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.opt-card:focus-within {
    outline: var(--focus-width) solid var(--focus-ring, var(--accent));
    outline-offset: var(--focus-offset);
}
.opt-card .opt-check {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    color: var(--accent);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease-out);
}
.opt-card.is-selected .opt-check { opacity: 1; }
.opt-card .opt-icon { color: var(--text-2); }
.opt-card.is-selected .opt-icon { color: var(--accent); }
.opt-title { font-size: var(--fs-base); font-weight: var(--fw-medium); }
.opt-desc { color: var(--text-3); font-size: var(--fs-sm); line-height: 1.35; }
.opt-card[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
/* Tiny fake preview used by the theme cards. */
.opt-preview {
    display: block;
    height: 44px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    margin-bottom: var(--space-1);
    overflow: hidden;
}

/* ---------- segmented control ---------- */
.seg {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--surface-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}
.seg-item {
    padding: 0 var(--space-3);
    height: var(--control-h-sm);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: var(--fs-sm);
    display: inline-flex;
    align-items: center;
}
.seg-item:hover { color: var(--text-1); }
.seg-item.is-active { background: var(--surface-4); color: var(--text-1); font-weight: var(--fw-medium); }

/* ---------- input with leading icon + inline button ---------- */
.field {
    position: relative;
    display: flex;
    align-items: center;
}
.field > input {
    width: 100%;
    height: var(--control-h-lg);
    padding: 0 var(--space-3) 0 calc(var(--space-3) + 18px);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-1);
    font-size: var(--fs-base);
    font-family: inherit;
}
.field > input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 1px var(--accent);
}
.field > .field-icon {
    position: absolute;
    left: var(--space-3);
    color: var(--text-3);
    pointer-events: none;
    display: inline-flex;
}
.field > .field-icon .icon { width: 14px; height: 14px; }
/* Copy/eye button parked inside the field's right edge. */
.field > .field-btn {
    position: absolute;
    right: var(--space-1);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: calc(var(--control-h-lg) - 8px);
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--surface-4);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    cursor: pointer;
}
.field > .field-btn:hover { color: var(--text-1); border-color: var(--border-strong); }
.field > .field-btn .icon { width: 13px; height: 13px; }
.field.has-btn > input { padding-right: calc(var(--space-3) + 76px); }
.field.has-iconbtn > input { padding-right: calc(var(--space-3) + 30px); }
.field > input[readonly] { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-2); }

/* ---------- kbd chip (one style everywhere) ---------- */
kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 20px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: var(--fs-2xs);
    line-height: 1;
}
.kbd-sep { color: var(--text-3); font-size: var(--fs-2xs); margin: 0 2px; }

/* ---------- status pill ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    height: 20px;
    padding: 0 var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    color: var(--text-2);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    white-space: nowrap;
}
.pill .icon { width: 12px; height: 12px; }
.pill--ok { color: var(--success); border-color: var(--success); background: var(--success-soft); }
.pill--warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.pill--err { color: var(--error); border-color: var(--error); background: var(--error-soft); }
.pill--info { color: var(--info); border-color: var(--info); background: var(--info-soft); }
.pill--accent { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- empty state (icon + title + hint + action) ---------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-8) var(--space-4);
    text-align: center;
}
.empty-state .icon { width: 28px; height: 28px; color: var(--text-3); }
.empty-state-title { font-weight: var(--fw-semibold); color: var(--text-1); }
.empty-state-hint { color: var(--text-3); font-size: var(--fs-sm); max-width: 34ch; }
.empty-state .btn { margin-top: var(--space-2); }

/* ---------- inline alert (icon + text — never colour only) ---------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    font-size: var(--fs-sm);
    color: var(--text-2);
    line-height: 1.4;
}
.alert .icon { width: 14px; height: 14px; flex: 0 0 auto; margin-top: 2px; }
.alert--info { border-color: var(--info); background: var(--info-soft); }
.alert--info .icon { color: var(--info); }
.alert--warn { border-color: var(--warn); background: var(--warn-soft); }
.alert--warn .icon { color: var(--warn); }
.alert--error { border-color: var(--error); background: var(--error-soft); }
.alert--error .icon { color: var(--error); }

/* ---------- skeleton line (for generating states) ---------- */
.skel-line {
    height: var(--control-h-lg);
    border-radius: var(--radius-md);
    background: var(--surface-3);
    animation: skel-pulse 1.1s var(--ease-in-out) infinite alternate;
}
@keyframes skel-pulse { from { opacity: 0.55; } to { opacity: 1; } }

/* ---------- help dialog rows ---------- */
.help-link {
    flex-direction: row !important;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
}
.help-link-ico {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: var(--radius-md);
    background: var(--surface-3);
    color: var(--text-2);
}
.help-link-ico .icon { width: 15px; height: 15px; }
.help-link-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.help-link-go { color: var(--text-3); flex: 0 0 auto; display: inline-flex; }
.help-link-go .icon { width: 14px; height: 14px; }
.help-link:hover .help-link-go { color: var(--text-2); }

/* Quick tips: 2-column grid of chip + label rows. */
.help-tips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-1) var(--space-4);
}
.help-tip {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    font-size: var(--fs-sm);
    color: var(--text-2);
}
@media (max-width: 520px) { .help-tips { grid-template-columns: 1fr; } }

/* ---------- overrides for legacy rules still in components.css ----------
   Older blanket styles (.dialog-box button/label/input) predate this system;
   these win on specificity until Phase F deletes the old rules. */
.dialog-box .dlg-head button,
.dialog-box .dlg-body button,
.dialog-box .dlg-foot button,
.dialog-box .settings-nav button,
.dialog-box .settings-content button { margin-top: 0; }
.dialog-box .opt-card { margin: 0; justify-content: flex-start; align-items: stretch; }
.dialog-box .set-label { display: block; margin: 0; }
.dialog-box .field > input { width: 100%; }
/* console.css still gives .error-box padding/scroll — the anatomy owns that now. */
.dialog-box.error-box { padding: 0; overflow: hidden; max-height: 80vh; }
/* The command palette's selected row used a full accent background — neutral now. */
.palette-item:hover,
.palette-item.selected { background: var(--state-hover); color: var(--text-1); }
.palette-item:hover .palette-hint,
.palette-item.selected .palette-hint { color: var(--text-3); opacity: 1; }

/* ---------- mobile: bottom-sheet dialogs ---------- */
@media (max-width: 640px) {
    .dialog { align-items: flex-end; padding: 0; }
    .dialog-box {
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        border-bottom: 0;
        animation: sheet-in var(--dur-base) var(--ease-out);
    }
    /* Drag-handle look at the top of the sheet. */
    .dialog-box::before {
        content: '';
        flex: 0 0 auto;
        align-self: center;
        width: 36px;
        height: 4px;
        margin-top: var(--space-2);
        border-radius: var(--radius-pill);
        background: var(--border-strong);
    }
    .dlg-body { padding: var(--space-4); }
    .dlg-head { padding-left: var(--space-4); }
}
@keyframes sheet-in {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
