/* WARP Drive — blue / white / grey theme with per-user dark mode (html[data-theme="dark"]). */

:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #e8f0fe;
    --primary-text: #1e40af;
    --sidebar: #0f1f3d;
    --sidebar-2: #162a50;
    --sidebar-text: #c7d2e6;
    --sidebar-muted: #7f8fb0;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --success: #15803d;
    --success-soft: #e7f6ec;
    --warn: #b45309;
    --warn-soft: #fdf3e2;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .16);
    --radius: 10px;
    --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
    color-scheme: light;
}

html[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #121b2d;
    --surface-2: #0f1828;
    --surface-3: #1a253a;
    --border: #243049;
    --border-strong: #334262;
    --text: #e5eaf3;
    --text-2: #c3cbd9;
    --muted: #8b97ad;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: #172a4d;
    --primary-text: #93c5fd;
    --sidebar: #08101f;
    --sidebar-2: #111d35;
    --sidebar-text: #c3cbd9;
    --sidebar-muted: #6f7d99;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --success: #4ade80;
    --success-soft: #12301d;
    --warn: #fbbf24;
    --warn-soft: #33270f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
}

/* Sign-in pages follow the OS preference (no user yet). */
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --bg: #0b1220; --surface: #121b2d; --surface-2: #0f1828; --surface-3: #1a253a;
        --border: #243049; --border-strong: #334262; --text: #e5eaf3; --text-2: #c3cbd9; --muted: #8b97ad;
        --primary: #3b82f6; --primary-hover: #60a5fa; --primary-soft: #172a4d; --primary-text: #93c5fd;
        --danger: #f87171; --danger-soft: #3a1717;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 248px; flex: 0 0 248px;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    padding: 18px 12px;
    z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 32px; height: 32px; }
.brand-text { font-size: 18px; font-weight: 700; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); padding: 16px 12px 6px; }
.nav-item, .side-btn {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; border-radius: 8px;
    color: var(--sidebar-text); font-size: 14px;
    border: 0; background: none; width: 100%; text-align: left; cursor: pointer; font-family: inherit;
}
.nav-item svg, .side-btn svg, .menu-btn svg {
    width: 19px; height: 19px; flex: 0 0 19px;
    fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.nav-item:hover, .side-btn:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, .35); }
.nav-badge {
    margin-left: auto; background: #fff; color: var(--primary-hover);
    font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; min-width: 22px; text-align: center;
}
.nav-item:not(.active) .nav-badge { background: var(--primary); color: #fff; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 12px 10px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700;
}
.me-name { color: #fff; font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.me-role { font-size: 12px; color: var(--sidebar-muted); }
.switch { margin-left: auto; width: 32px; height: 18px; border-radius: 999px; background: rgba(255, 255, 255, .2); position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
#theme-toggle[aria-pressed="true"] .switch { background: var(--primary); }
#theme-toggle[aria-pressed="true"] .switch::after { transform: translateX(14px); }

.main { flex: 1; min-width: 0; padding: 26px 32px 48px; }
.menu-btn { display: none; }

@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: none; }
    .main { padding: 16px; }
    .menu-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 38px; height: 38px; margin-bottom: 10px;
        border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
    }
}

/* ---------- Page chrome ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; }
.head-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.narrow { max-width: 460px; }
.section-title { margin-top: 24px; display: flex; align-items: center; gap: 8px; }
.count { background: var(--surface-3); color: var(--muted); border-radius: 999px; font-size: 12px; padding: 0 9px; font-weight: 600; }
.flash { background: var(--success-soft); color: var(--success); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }

.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.live[data-state="live"] .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.live[data-state="down"] .dot { background: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; }

/* ---------- Forms & buttons ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field em { color: var(--danger); font-style: normal; }
.inline-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
input, select, textarea {
    font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px;
    padding: 7px 10px; min-width: 0; width: 100%;
}
.inline-field select { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; cursor: pointer; }
.check input { width: auto; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-weight: 600; font-size: 13px;
    padding: 7px 14px; border-radius: 7px; cursor: pointer;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
    white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid, .btn-danger-solid:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 4px; }
.btn-block { width: 100%; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 7px; padding: 8px 12px; font-size: 13px; }
.form-error:empty, .form-error ul:empty { display: none; }
.form-error ul { margin: 0; padding-left: 16px; }
.validation-summary-valid { display: none; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; align-items: end; margin-bottom: 14px; }
.filters .grow2 { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; }
@media (max-width: 600px) { .filters .grow2 { grid-column: auto; } }

.result-bar { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; gap: 12px; flex-wrap: wrap; }
.pager { display: flex; gap: 6px; align-items: center; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.pill.status-New { background: var(--primary-soft); color: var(--primary-text); }
.pill.status-In-Progress { background: var(--warn-soft); color: var(--warn); }
.pill.status-Closed { background: var(--success-soft); color: var(--success); }
.pill.status-Excluded { background: var(--surface-3); color: var(--muted); }
.pill.count-pill { background: var(--primary); color: #fff; }
.pill.outline { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Alert cards ---------- */
.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); border-left: 4px solid var(--primary); overflow: hidden; }
.alert-card.st-In-Progress { border-left-color: var(--warn); }
.alert-card.st-Closed { border-left-color: var(--success); }
.alert-card.st-Excluded { border-left-color: var(--border-strong); }
.alert-card.flash-new { animation: flashnew 2.4s ease-out; }
@keyframes flashnew { 0% { box-shadow: 0 0 0 3px var(--primary); } 100% { box-shadow: var(--shadow); } }
.alert-head { display: flex; gap: 14px; padding: 12px 16px; cursor: pointer; align-items: flex-start; }
.alert-head:hover { background: var(--surface-2); }
.chev { width: 18px; height: 18px; margin-top: 2px; flex: 0 0 18px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform .15s; }
.alert-card.open .chev { transform: rotate(90deg); }
.alert-main { flex: 1; min-width: 0; }
.alert-title { font-weight: 650; font-size: 15px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.alert-id { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.alert-desc { color: var(--text-2); margin-top: 3px; overflow-wrap: anywhere; }
.alert-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.alert-side { text-align: right; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.ts-local { font-weight: 600; font-size: 13px; white-space: nowrap; }
.ts-utc { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.ts-rel { font-size: 11.5px; color: var(--muted); }
@media (max-width: 700px) { .alert-head { flex-wrap: wrap; } .alert-side { text-align: left; align-items: flex-start; flex-basis: 100%; } }

.alert-body { border-top: 1px solid var(--border); padding: 16px; background: var(--surface-2); display: flex; flex-direction: column; gap: 16px; }
.triage { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.triage .field { width: 170px; }
.triage .spacer, .editor-actions .spacer { flex: 1; }
.sec h3 { margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: minmax(0, 1fr); } }

.kv { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; table-layout: fixed; }
.kv th, .kv td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }
.kv th { width: 38%; color: var(--muted); font-weight: 600; font-size: 12.5px; background: var(--surface-2); }
.kv td { font-family: var(--mono); font-size: 12.5px; }
.kv .kv { border: 0; border-radius: 0; background: transparent; }
.kv .kv th { background: transparent; }
.null { color: var(--muted); font-style: italic; font-family: inherit; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.grid-table th, .grid-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.grid-table th { background: var(--surface-3); color: var(--text-2); font-weight: 600; }
.profile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.profile h4 { margin: 0 0 8px; font-size: 13px; color: var(--primary-text); text-transform: capitalize; }

details.raw > summary, details.history > summary { cursor: pointer; font-weight: 600; color: var(--text-2); padding: 4px 0; }
pre.code { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; max-height: 420px; white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; color: var(--text); }

.notes { display: flex; flex-direction: column; gap: 8px; }
.note { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.note.system { background: transparent; border-style: dashed; color: var(--muted); font-size: 12.5px; }
.note-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.note-author { font-weight: 650; color: var(--text); }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 3px; }
.note-form { display: flex; gap: 8px; align-items: flex-end; }
.note-form textarea { flex: 1; }
.occ { font-size: 12.5px; columns: 2; color: var(--text-2); margin: 0; padding-left: 18px; }

/* ---------- Exclusions ---------- */
.editor { margin-bottom: 20px; border-top: 3px solid var(--primary); }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.conditions-head { margin: 16px 0 8px; }
.cond-row { display: grid; grid-template-columns: minmax(0, 2fr) 140px minmax(0, 2fr) auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.cond-row .and { grid-column: 1 / -1; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .08em; }
@media (max-width: 700px) { .cond-row { grid-template-columns: 1fr; } }
.editor-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; flex-wrap: wrap; }
.preview { background: var(--primary-soft); color: var(--primary-text); border-radius: 8px; padding: 10px 14px; margin-top: 12px; font-size: 13px; }
.preview ul { margin: 6px 0 0; padding-left: 18px; }
.ex-list { display: flex; flex-direction: column; gap: 8px; }
.ex { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.ex > summary { list-style: none; display: flex; gap: 12px; align-items: center; padding: 12px 16px; cursor: pointer; flex-wrap: wrap; }
.ex > summary::-webkit-details-marker { display: none; }
.ex[open] .chev { transform: rotate(90deg); }
.ex-name { font-weight: 650; flex: 1; min-width: 200px; }
.ex-body { border-top: 1px solid var(--border); padding: 14px 16px; background: var(--surface-2); display: flex; flex-direction: column; gap: 12px; }
.cond-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.cond-list li { font-family: var(--mono); font-size: 12.5px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; overflow-wrap: anywhere; }
.cond-list .op { color: var(--primary-text); font-weight: 700; padding: 0 6px; }
.history { margin-top: 24px; }
.history .ex-list { margin-top: 10px; }

/* ---------- Tables ---------- */
.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 650; background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.details { max-width: 480px; overflow-wrap: anywhere; }
.table .right { text-align: right; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.table select { width: auto; padding: 4px 8px; }
.role-help { margin-top: 16px; color: var(--text-2); }
.role-help ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Toasts & modal ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 10px 14px; font-size: 13px; animation: toastin .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }
.modal { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(480px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15, 23, 42, .5); }
.modal-body { padding: 20px 20px 8px; }
.modal-body h2 { margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.secret { display: flex; gap: 8px; margin-top: 10px; }
.secret input { font-family: var(--mono); font-size: 15px; }

/* ---------- Auth pages ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, rgba(37, 99, 235, .18), transparent), var(--bg); }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-logo { width: 44px; height: 44px; }
.auth-title { font-size: 20px; font-weight: 700; }
.auth-sub { color: var(--muted); font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-note { color: var(--text-2); margin: 0 0 14px; }
.auth-alt { text-align: center; margin-top: 10px; }

/* ---------- Bulk close (Alerts page) ---------- */
.bulk-bar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    position: sticky; top: 0; z-index: 5; margin-bottom: 12px; padding: 8px 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.bulk-bar .spacer { flex: 1; }
.bulk-count { font-size: 13px; color: var(--muted); font-weight: 600; }
.check-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check-inline input, .pick input { width: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--primary); cursor: pointer; }
.pick { display: flex; align-items: center; padding: 2px 2px 0; margin: -2px 0; cursor: pointer; }
.alert-card.selected { outline: 2px solid var(--primary); outline-offset: -1px; }
.alert-card.selected > .alert-head { background: var(--primary-soft, var(--surface-2)); }
.bulk-form { display: flex; flex-direction: column; gap: 12px; }
.bulk-list { margin: 0; padding-left: 18px; max-height: 160px; overflow: auto; font-size: 13px; color: var(--text-2); }
.bulk-list li { overflow-wrap: anywhere; }
