/* Mission Control admin — Digital Excellence Platform spec.
   Tokens locked to the design.md palette and type system. */

:root {
    --bg: #000000;
    --surface: #1A1A1A;
    --surface-2: #111111;
    --surface-hover: #202022;
    --border: #27272A;
    --border-strong: #3F3F46;
    --text: #FFFFFF;
    --text-dim: #A1A1AA;
    --text-mute: #71717A;
    --primary: #EF233C;
    --primary-hover: #D11F35;
    --primary-glow: rgba(239, 35, 60, 0.18);
    --accent: #3B82F6;
    --accent-hover: #2563EB;
    --accent-glow: rgba(59, 130, 246, 0.18);
    --ok: #22C55E;
    --warn: #F59E0B;
    --err: #EF233C;

    --radius-card: 16px;
    --radius-control: 8px;
    --radius-pill: 9999px;

    --space-1: 8px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;
    --space-5: 48px;

    --sidebar-w: 240px;
    --sidebar-collapsed-w: 72px;
    --topbar-h: 64px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button {
    font-family: inherit;
    cursor: pointer;
}

/* ============================================================
   AUTH PAGES (login / register)
   ============================================================ */

body.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 20% 0%, var(--primary-glow) 0%, transparent 40%),
        radial-gradient(circle at 80% 100%, var(--accent-glow) 0%, transparent 40%),
        var(--bg);
    padding: var(--space-3);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-4);
    width: 100%;
    max-width: 440px;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.04) inset,
        0 12px 40px rgba(0, 0, 0, 0.6);
}

.auth-card h1 {
    margin: 0 0 var(--space-1) 0;
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.auth-sub {
    color: var(--text-dim);
    font-size: 14px;
    margin: 0 0 var(--space-3) 0;
}

.auth-card label {
    display: block;
    margin-bottom: var(--space-2);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.auth-card input,
.modal-card input,
.panel input,
.panel select,
.panel textarea {
    width: 100%;
    margin-top: 6px;
    padding: 10px 14px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-card input:focus,
.modal-card input:focus,
.panel input:focus,
.panel select:focus,
.panel textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---- Buttons (shared base) ---- */

button.btn,
.auth-card button[type="submit"],
.modal-card button.btn-primary,
.modal-card button[data-close] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-control);
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* Primary fill (red). Width is left to context — header rows stay auto-width;
   form CTAs in auth/modal contexts get a 100% override below. */
button.btn-primary,
.modal-card button.btn-primary {
    background: var(--primary);
    color: var(--text);
    border: 1px solid transparent;
}
button.btn-primary:hover,
.modal-card button.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

/* Ghost / outline */
button.btn-ghost,
.modal-card button[data-close] {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}
button.btn-ghost:hover,
.modal-card button[data-close]:hover {
    color: var(--text);
    border-color: var(--border-strong);
}
button.btn-ghost:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Danger outline */
button.btn-danger,
.panel button.danger {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
button.btn-danger:hover,
.panel button.danger:hover {
    background: var(--primary);
    color: var(--text);
}

/* Form CTAs that should fill their container (auth pages + modal submits). */
.auth-card button[type="submit"],
.modal-card button.btn-primary {
    width: 100%;
    background: var(--primary);
    color: var(--text);
    border: none;
    margin-top: var(--space-2);
}
.auth-card button[type="submit"]:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.auth-foot {
    margin-top: var(--space-3);
    text-align: center;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
}

.error {
    color: var(--primary);
    font-size: 13px;
    min-height: 1.2em;
    margin: var(--space-2) 0 0;
}

.hint {
    color: var(--text-dim);
    font-size: 13px;
}

/* ============================================================
   ADMIN SHELL
   ============================================================ */

body.admin-body {
    min-height: 100vh;
}

.app-shell {
    display: grid;
    /* Grid reserves the collapsed width; the sidebar itself is fixed and
       expands on hover, overlaying the content rather than reflowing it. */
    grid-template-columns: var(--sidebar-collapsed-w) 1fr;
    min-height: 100vh;
}

/* ---- Sidebar (icon rail with hover-expand) ---- */

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-collapsed-w);
    overflow: hidden;
    z-index: 20;
    transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.22s ease;
}

.sidebar:hover,
.sidebar:focus-within {
    width: var(--sidebar-w);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
}

/* Labels and metadata fade in only when the rail is expanded. */
.sidebar .brand-text,
.sidebar .nav-item > span:not(.icon):not(.badge),
.sidebar .nav-item .badge,
.sidebar .sidebar-section-label,
.sidebar .user-meta,
.sidebar .signout-btn-label {
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.18s ease 0s, transform 0.22s ease 0s;
    white-space: nowrap;
    pointer-events: none;
}

.sidebar:hover .brand-text,
.sidebar:hover .nav-item > span:not(.icon):not(.badge),
.sidebar:hover .nav-item .badge,
.sidebar:hover .sidebar-section-label,
.sidebar:hover .user-meta,
.sidebar:hover .signout-btn-label,
.sidebar:focus-within .brand-text,
.sidebar:focus-within .nav-item > span:not(.icon):not(.badge),
.sidebar:focus-within .nav-item .badge,
.sidebar:focus-within .sidebar-section-label,
.sidebar:focus-within .user-meta,
.sidebar:focus-within .signout-btn-label {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 0.06s;
    pointer-events: auto;
}

.sidebar-brand {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    height: var(--topbar-h);
    box-sizing: border-box;
    flex-shrink: 0;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-control);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.brand-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-mute);
    letter-spacing: 0.1em;
}

.sidebar-section-label {
    padding: var(--space-2) var(--space-3) 6px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    height: 26px;        /* keep its slot when collapsed so layout doesn't jump */
    box-sizing: border-box;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-item {
    all: unset;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-dim);
    border-radius: var(--radius-control);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
    position: relative;
    height: 40px;
    box-sizing: border-box;
    overflow: hidden;
    /* Center the icon when the rail is collapsed. Once expanded the icon
       sits flush-left and the label fades in to its right. */
    justify-content: flex-start;
}

.nav-item .icon {
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.nav-item.active {
    background: linear-gradient(180deg, rgba(239, 35, 60, 0.12), rgba(239, 35, 60, 0.04));
    color: var(--text);
    border: 1px solid rgba(239, 35, 60, 0.25);
    padding: 9px 11px; /* compensate for border */
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -13px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    border-radius: 0 2px 2px 0;
    background: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow);
}

.nav-item .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--surface-hover);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    font-size: 12px;
    transition: background 0.18s ease, border-color 0.18s ease, padding 0.18s ease;
    overflow: hidden;
}

.sidebar:hover .user-chip,
.sidebar:focus-within .user-chip {
    background: var(--bg);
    border-color: var(--border);
    padding: 8px 10px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-pill);
    background: linear-gradient(135deg, var(--accent), var(--primary));
    display: grid;
    place-items: center;
    color: white;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
    overflow: hidden;
}

.user-email {
    color: var(--text);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.signout-btn {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 8px;
    border-radius: var(--radius-control);
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, justify-content 0.18s ease;
    height: 38px;
    box-sizing: border-box;
    overflow: hidden;
}

.signout-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar:hover .signout-btn,
.sidebar:focus-within .signout-btn {
    justify-content: flex-start;
    padding-left: 14px;
}

/* ---- Main / Topbar ---- */

.main {
    /* The sidebar is position:fixed, so it's removed from grid flow. Pin
       .main to the second column explicitly — otherwise auto-placement
       drops it into column 1 (the 72px reserved slot) and the sidebar
       paints on top of the content. */
    grid-column: 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-3);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent),
        var(--bg);
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: blur(8px);
}

.crumbs {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.crumbs strong {
    color: var(--text);
    font-weight: 500;
}

.crumbs .sep { color: var(--border-strong); }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

button.btn-restart {
    padding: 5px 12px;
    font-size: 11px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: var(--radius-pill);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-pill);
    background: var(--ok);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

.dot.warn { background: var(--warn); box-shadow: 0 0 8px rgba(245, 158, 11, 0.6); }
.dot.err  { background: var(--err); box-shadow: 0 0 8px rgba(239, 35, 60, 0.6); }

/* ---- Content area ---- */

.content {
    padding: var(--space-3);
    max-width: 1480px;
    width: 100%;
}

.panel { display: none; animation: fadeUp 0.35s ease both; }
.panel.active { display: block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.panel-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.panel-header h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.panel-header .lede {
    margin: 6px 0 0;
    color: var(--text-dim);
    font-size: 14px;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
    justify-content: flex-end;
}

/* Save bar at the bottom of the settings form — primary action stays visible
   even if the panel-header actions get squeezed off on a narrow viewport. */
.save-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding: 14px var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    position: sticky;
    bottom: 16px;
    z-index: 5;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.save-bar-status {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.18s ease;
}
.save-bar-status[data-kind="ok"]      { color: var(--ok); }
.save-bar-status[data-kind="err"]     { color: var(--err); }
.save-bar-status[data-kind="pending"] { color: var(--accent); }

button[data-saved="1"] {
    background: var(--ok) !important;
    border-color: var(--ok) !important;
}

/* ---- Bento metric strip ---- */

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3);
    transition: transform 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
}

.metric-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}

.metric-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
}

.metric-card .label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}

.metric-card .value {
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1;
}

.metric-card .meta {
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
}

.metric-card.accent .value { color: var(--accent); }
.metric-card.primary .value { color: var(--primary); }
.metric-card.ok .value { color: var(--ok); }

/* ---- Surface / data card ---- */

.surface-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow: hidden;
}

.surface-card-head {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.surface-card-head h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.surface-card-head .sub {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.surface-card-body {
    padding: var(--space-3);
}

.surface-card-body.flush { padding: 0; }

/* ---- Tables ---- */

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.data th, table.data td {
    text-align: left;
    padding: 12px var(--space-3);
    border-bottom: 1px solid var(--border);
}

table.data thead th {
    background: var(--surface-2);
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

table.data tbody tr {
    transition: background 0.12s ease;
}

table.data tbody tr:hover { background: var(--surface-hover); }
table.data tbody tr:last-child td { border-bottom: none; }

table.data td.mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }
table.data td.num  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

td.actions { text-align: right; }
td.actions button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: var(--radius-control);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}
td.actions button:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ---- Clickable table rows (customer detail entry) ---- */

table.data tr.clickable-row {
    cursor: pointer;
    transition: background 0.15s ease;
}
table.data tr.clickable-row:hover {
    background: var(--surface-hover);
}
table.data tr.clickable-row td:first-child {
    position: relative;
}
table.data tr.clickable-row:hover td:first-child::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 2px;
    background: var(--primary);
}

/* ---- Key-value grid (used by detail panels) ---- */

dl.kv-grid {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 10px var(--space-3);
    margin: 0;
    align-items: start;
}

dl.kv-grid dt {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-top: 2px;
}

dl.kv-grid dd {
    margin: 0;
    color: var(--text);
    overflow-wrap: anywhere;
}

dl.kv-grid dd.mono {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text);
}

@media (max-width: 700px) {
    dl.kv-grid { grid-template-columns: 1fr; gap: 4px var(--space-2); }
    dl.kv-grid dt { padding-top: 8px; }
}

/* ---- Pills / status ---- */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid transparent;
}

.pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.pill.ok   { color: var(--ok);   background: rgba(34, 197, 94, 0.1);  border-color: rgba(34, 197, 94, 0.25); }
.pill.warn { color: var(--warn); background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.25); }
.pill.err  { color: var(--err);  background: rgba(239, 35, 60, 0.1);  border-color: rgba(239, 35, 60, 0.25); }
.pill.idle { color: var(--text-dim); background: var(--surface); border-color: var(--border); }

/* Pill variant for the role badge in user table — no leading dot */
.pill.role { padding: 3px 10px; }
.pill.role::before { display: none; }

.legend { display: flex; gap: 8px; }

/* ---- Empty / hint ---- */

.empty-state {
    padding: var(--space-5) var(--space-3);
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
}

/* ---- Modal ---- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal[hidden] { display: none; }

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3);
    width: 100%;
    max-width: 460px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal-card h3 {
    margin: 0 0 var(--space-3) 0;
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.modal-card label {
    display: block;
    margin-bottom: var(--space-2);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: var(--space-3);
}

.modal-actions button {
    padding: 8px 16px;
    border-radius: var(--radius-control);
    font-size: 13px;
    font-weight: 500;
}

/* ---- Settings ---- */

#settingsForm {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
}

.setting-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3);
}

.setting-group.span-2 { grid-column: span 2; }

.setting-group h3 {
    margin: 0 0 var(--space-2) 0;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.setting-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    margin-bottom: var(--space-2);
}

.setting-row:last-child { margin-bottom: 0; }

.setting-row label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-row .preview {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
}

.setting-row--slider .scan-cadence-control {
    display: flex;
    align-items: center;
    gap: 10px;
}
.setting-row--slider .scan-cadence-control input[type="range"] {
    flex: 1;
    accent-color: var(--accent, #6366f1);
    cursor: pointer;
}
.setting-row--slider .scan-cadence-control input[type="number"] {
    width: 64px;
    font-family: var(--font-mono);
    text-align: right;
}
.setting-row--slider .scan-cadence-unit {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
}
.setting-row--slider .scan-cadence-hint {
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-mute);
    line-height: 1.4;
}
.setting-row--slider #scanCadencePreview {
    font-weight: 600;
    color: var(--accent, #6366f1);
}

.warn-banner {
    background:
        linear-gradient(90deg, rgba(245, 158, 11, 0.08), transparent),
        var(--surface);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-left: 3px solid var(--warn);
    color: var(--warn);
    padding: 14px 16px;
    border-radius: var(--radius-control);
    font-size: 13px;
    margin-bottom: var(--space-3);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.warn-banner .warn-text { color: var(--text-dim); }
.warn-banner strong { color: var(--text); }

/* Sandbox-mode top-of-page indicator. Sticky so it's visible regardless of
   scroll/tab state. Bright magenta to be impossible to miss but not red
   (red is reserved for system-down alerts). */
/* Banner height is consumed by --banner-h so the sidebar (position:fixed) and
   topbar (position:sticky top:0) shift down instead of being painted over.
   Set on body[data-sandbox="on"] further down so the offset only applies when
   the banner is actually visible. */
:root { --banner-h: 0px; }

.sandbox-banner {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: linear-gradient(90deg, #b91c5c, #ec4899);
    color: #fff;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.02em;
    box-sizing: border-box;
    height: var(--banner-h);
    overflow: hidden;
}
/* `display: flex` above outranks the user-agent `[hidden] { display: none }`
   rule, so without this the banner renders even when sandbox is off. */
.sandbox-banner[hidden] { display: none; }

/* When sandbox is on, reserve banner height and shift the fixed sidebar +
   sticky topbar down so they stop at banner-bottom, not viewport-top. */
body[data-sandbox="on"] { --banner-h: 36px; }
body[data-sandbox="on"] .sidebar { top: var(--banner-h); }
body[data-sandbox="on"] .topbar  { top: var(--banner-h); }
.sandbox-banner code {
    background: rgba(0, 0, 0, 0.25);
    padding: 1px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 12px;
}
.sandbox-banner svg { flex-shrink: 0; }
body[data-sandbox="on"] { /* hook for future global tweaks */ }

/* Sandbox toggle panel inside the Settings tab. Echoes warn-banner sizing
   but with the magenta accent to match the top banner. */
.sandbox-panel {
    background:
        linear-gradient(90deg, rgba(236, 72, 153, 0.08), transparent),
        var(--surface);
    border: 1px solid rgba(236, 72, 153, 0.3);
    border-left: 3px solid #ec4899;
    border-radius: var(--radius-control);
    padding: 16px 18px;
    margin-bottom: var(--space-3);
}
.sandbox-panel__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.sandbox-panel__title h2 {
    margin: 0 0 4px;
    font-size: 15px;
    color: var(--text);
}
.sandbox-panel__lede {
    margin: 0;
    font-size: 12.5px;
    color: var(--text-dim);
    max-width: 70ch;
}
.sandbox-panel__hint {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-mute);
    font-family: var(--font-mono);
}
.sandbox-panel[data-state="on"] {
    border-color: rgba(236, 72, 153, 0.6);
    background:
        linear-gradient(90deg, rgba(236, 72, 153, 0.15), transparent),
        var(--surface);
}
.sandbox-panel[data-state="on"] .sandbox-panel__hint strong { color: #ec4899; }

/* Confirm modal for the sandbox toggle. Reuses the .modal / .modal-card frame;
   .sandbox-modal-* extensions just tune the body + confirm-button accent. */
.sandbox-modal-card { max-width: 480px; }
.sandbox-modal-body {
    margin: 0 0 var(--space-3) 0;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.55;
}
.sandbox-modal-confirm {
    background: linear-gradient(90deg, #b91c5c, #ec4899);
    color: #fff;
    border-color: transparent;
}
.sandbox-modal-confirm:hover { filter: brightness(1.08); }
.sandbox-modal-confirm.live {
    /* Going back to live mode — use the standard primary look so it doesn't
       read as "more sandbox". */
    background: var(--accent, #2f7dff);
}

.apply-output {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: var(--space-2);
    margin-top: var(--space-3);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    overflow: auto;
    max-height: 320px;
    white-space: pre-wrap;
}

/* ---- Import page (dropzone) ---- */

.dropzone {
    background:
        radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.06), transparent 60%),
        var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius-card);
    padding: 56px var(--space-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
    outline: none;
}

.dropzone:hover,
.dropzone:focus-visible {
    border-color: var(--accent);
    background:
        radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.1), transparent 65%),
        var(--surface);
}

.dropzone.drag {
    border-color: var(--primary);
    background:
        radial-gradient(circle at 50% 0%, rgba(239, 35, 60, 0.12), transparent 60%),
        var(--surface);
    transform: scale(1.005);
}

.dropzone.has-file {
    border-color: var(--ok);
    border-style: solid;
}

.dz-icon {
    color: var(--text-mute);
    transition: color 0.18s ease;
    margin-bottom: 4px;
}

.dropzone:hover .dz-icon,
.dropzone:focus-visible .dz-icon { color: var(--accent); }
.dropzone.drag .dz-icon { color: var(--primary); }
.dropzone.has-file .dz-icon { color: var(--ok); }

.dz-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

.dz-hint {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.dz-filename {
    margin-top: 12px;
    padding: 6px 14px;
    background: rgba(34, 197, 94, 0.1);
    color: var(--ok);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-size: 12px;
}

.import-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: var(--space-2);
}

/* ---- Service status grid (Scans tab) ---- */

.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
}
.service-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    font-size: 13px;
}
.service-chip .svc-name {
    font-weight: 500;
    color: var(--text);
    flex: 1;
}
.service-chip .svc-state {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.service-chip .dot-ok,
.service-chip .dot-err,
.service-chip .dot-idle {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.service-chip .dot-ok   { background: var(--ok);  box-shadow: 0 0 8px rgba(34,197,94,.6); }
.service-chip .dot-err  { background: var(--err); box-shadow: 0 0 8px rgba(239,35,60,.6); }
.service-chip .dot-idle { background: var(--text-mute); }

/* ---- Live log tail ---- */

.log-tail {
    margin: 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 11.5px;
    line-height: 1.55;
}
.log-tail > div {
    padding: 1px var(--space-3);
    border-left: 3px solid transparent;
    white-space: pre-wrap;
    word-break: break-word;
}
.log-tail .log-info { color: var(--text-dim); }
.log-tail .log-ok   { color: var(--ok);  border-left-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.05); }
.log-tail .log-warn { color: var(--warn); border-left-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.05); }
.log-tail .log-err  { color: var(--err);  border-left-color: var(--primary); background: rgba(239, 35, 60, 0.08); }

/* ---- Heartbeat / status indicator ---- */

.hb {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---- Responsive ---- */

@media (max-width: 1000px) {
    #settingsForm { grid-template-columns: 1fr; }
    .setting-group.span-2 { grid-column: auto; }
}

/* ============================================================
   MOBILE / TABLET RESPONSIVE PASS
   App is used on phones 99% of the time, so this section is the
   primary design target — desktop is the affordance, mobile is
   the product.
   ============================================================ */

@media (max-width: 760px) {

    /* ---- App shell: single column, sidebar pinned to bottom ---- */
    .app-shell { grid-template-columns: 1fr; }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: stretch;
        z-index: 50;
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 0;
        background: var(--surface);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
        /* Honor iOS safe-area inset so the bar doesn't overlap the home gesture */
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .sidebar-brand, .sidebar-section-label, .sidebar-footer { display: none; }

    .sidebar-nav {
        flex: 1;
        flex-direction: row;
        padding: 4px 2px;
        gap: 0;
        justify-content: space-around;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar-nav::-webkit-scrollbar { display: none; }

    .nav-item {
        flex-direction: column;
        gap: 2px;
        padding: 8px 6px;
        min-width: 64px;
        flex: 1 1 0;
        font-size: 10px;
        border-radius: 0;
        opacity: 0.65;
        position: relative;
    }
    .nav-item .icon { width: 22px; height: 22px; }
    .nav-item > span:not(.icon):not(.badge) {
        font-size: 10px;
        line-height: 1;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }
    .nav-item .badge { display: none; }
    .nav-item.active {
        opacity: 1;
        color: var(--primary);
        background: rgba(239, 35, 60, 0.08);
    }
    .nav-item.active::before { display: none; }
    .nav-item.active::after {
        content: '';
        position: absolute;
        top: 0; left: 20%; right: 20%;
        height: 2px;
        background: var(--primary);
    }

    /* ---- Topbar tightening ---- */
    .topbar {
        padding: 0 var(--space-2);
        height: 52px;
    }
    .crumbs { font-size: 11px; gap: 6px; }
    .crumbs strong { display: none; }       /* hide brand on phone */
    .crumbs .sep { display: none; }
    .system-status {
        padding: 4px 10px;
        font-size: 10px;
        gap: 6px;
    }

    /* ---- Content padding (leave room for bottom nav) ---- */
    .content {
        padding: var(--space-2);
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0));
        max-width: 100%;
    }

    /* ---- Panel header stacks ---- */
    .panel-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: var(--space-2);
    }
    .panel-header h1 { font-size: 22px; }
    .panel-header .lede { font-size: 13px; margin-top: 4px; }
    .panel-actions { justify-content: flex-start; }

    /* ---- Surface cards: less inner padding, head wraps gracefully ---- */
    .surface-card { border-radius: 12px; }
    .surface-card-head {
        padding: 12px var(--space-2);
        flex-wrap: wrap;
        gap: 6px;
    }
    .surface-card-head h2 { font-size: 13px; }
    .surface-card-body { padding: var(--space-2); }

    /* ---- Metric grid: 2-up on small tablet, single col on phone ---- */
    .metric-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-1);
    }
    .metric-card {
        padding: 14px;
        border-radius: 12px;
    }
    .metric-card .label { margin-bottom: 4px; font-size: 10px; }
    .metric-card .value { font-size: 20px; }
    .metric-card .meta { margin-top: 6px; font-size: 10px; line-height: 1.3; }
    .metric-card:hover { transform: none; }   /* hover lift looks weird from a tap */

    /* ---- Tables → labeled cards ----
       The pattern: hide <thead>, make every cell display:flex with the
       data-label injected as ::before. Each <tr> becomes a card. */
    table.data,
    table.data thead,
    table.data tbody,
    table.data tr,
    table.data td {
        display: block;
        width: 100%;
    }
    table.data { border-collapse: separate; }
    table.data thead { display: none; }
    table.data tbody tr {
        padding: 12px var(--space-2);
        border-bottom: 1px solid var(--border);
    }
    table.data tbody tr:last-child { border-bottom: none; }
    table.data tbody tr:hover { background: transparent; }
    table.data td {
        padding: 5px 0;
        border-bottom: none;
        text-align: left;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--space-2);
        min-height: 22px;
    }
    table.data td::before {
        content: attr(data-label);
        font-family: var(--font-mono);
        font-size: 10px;
        color: var(--text-mute);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        flex-shrink: 0;
    }
    /* Don't render the empty pseudo for cells without a label */
    table.data td:not([data-label])::before,
    table.data td[data-label=""]::before { content: ''; }
    table.data td.actions { justify-content: flex-end; padding-top: 10px; }
    table.data td.mono { font-size: 12px; }

    /* Cells whose value can be long (truck title, detail) get full-width
       wrap below the label rather than squeezing onto one line. */
    table.data td[data-label="Truck"],
    table.data td[data-label="Detail"],
    table.data td[data-label="Org"],
    table.data td[data-label="Target"] {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    /* Empty-state cells (used colspan, no label) take full width as text. */
    table.data td[colspan] {
        text-align: center;
        padding: var(--space-3) 0;
    }
    table.data td[colspan]::before { display: none; }

    /* Expandable scans table — chevron pinned right; details stack ---- */
    table.data.expandable tbody tr.scan-row {
        position: relative;
        padding-right: 36px;
    }
    table.data.expandable tbody tr.scan-row td.expand-cell {
        position: absolute;
        top: 14px;
        right: var(--space-2);
        width: 18px;
        padding: 0;
        display: block;
        min-height: 0;
    }
    table.data.expandable tbody tr.scan-row td.expand-cell::before { display: none; }
    table.data.expandable tbody tr.scan-detail td {
        padding: 12px var(--space-2);
        display: block;
    }
    table.data.expandable tbody tr.scan-detail td::before { display: none; }
    .scan-detail__grid {
        grid-template-columns: 1fr;
        gap: 4px var(--space-2);
    }
    .scan-detail__grid dt { padding-top: 8px; }

    /* Customer-row clickable — kill hover red-bar; tap is the affordance */
    table.data tr.clickable-row td:first-child { padding-left: 0; }
    table.data tr.clickable-row:hover td:first-child::before { display: none; }

    /* ---- Buttons / pager: 44px tap targets ---- */
    .btn, button.btn-primary, button.btn-ghost {
        min-height: 40px;
        padding: 8px 14px;
    }
    .pager-btn { width: 40px; height: 40px; }
    td.actions button { min-height: 36px; padding: 6px 14px; }

    /* ---- Check rows: chevron + title; summary wraps to next row ---- */
    .check-row__head {
        grid-template-columns: 24px 1fr;
        grid-template-areas:
            "chev title"
            "chev summary";
        row-gap: 6px;
        padding: 12px var(--space-2);
    }
    .check-chevron { grid-area: chev; }
    .check-row__title {
        grid-area: title;
        white-space: normal;
        font-size: 13px;
    }
    .check-row__title .check-title-time { display: block; margin-bottom: 2px; }
    .check-row__summary {
        grid-area: summary;
        flex-wrap: wrap;
        gap: 4px;
    }
    .check-stat-pill { font-size: 10px; padding: 1px 6px; }
    .check-row__body { padding: 8px var(--space-2) 12px; }
    .check-line { font-size: 11px; line-height: 1.55; }
    .check-list { max-height: 60vh; }

    /* ---- Pagination: spread, taller ---- */
    .pagination {
        justify-content: space-between;
        padding: 10px var(--space-2);
    }
    .pager-info { font-size: 13px; flex: 1; text-align: center; }

    /* ---- Modals: full-width sheet ---- */
    .modal { padding: 0; align-items: flex-end; }
    .modal-card {
        max-width: 100vw;
        width: 100vw;
        margin: 0;
        border-radius: 16px 16px 0 0;
        padding: var(--space-3) var(--space-2) calc(var(--space-3) + env(safe-area-inset-bottom, 0));
    }

    /* ---- Save bar: stack stays sticky, action button goes full width ---- */
    .save-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px var(--space-2);
    }
    .save-bar .btn-primary { width: 100%; justify-content: center; }

    /* ---- Services grid (chip per container) wraps tighter ---- */
    .services-grid { gap: 4px !important; }

    /* ---- Warn / info banners: less padding ---- */
    .warn-banner { padding: 12px; gap: 10px; flex-wrap: wrap; }

    /* ---- Hide right-side legend on Purchases (looks crowded on mobile) ---- */
    .panel-header .legend { gap: 4px; }
}

/* ---- Phone tightening ---- */

@media (max-width: 480px) {
    .metric-grid { grid-template-columns: 1fr; }
    .metric-card .value { font-size: 22px; }
    .panel-header h1 { font-size: 20px; }
    .topbar { height: 48px; }
    .system-status { padding: 4px 8px; }
    .system-status #systemText {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ---- Small extras ---- */

.super-only { transition: opacity 0.15s ease; }
.super-only[data-hidden="true"] { display: none !important; }

/* ============================================================
   STAGE 1: Live check list (structured per-check rows + paging),
   in-flight scan pulse, next-check countdown, expandable rows
   ============================================================ */

.check-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    max-height: 480px;
    overflow-y: auto;
}

.check-empty {
    padding: var(--space-3);
    color: var(--text-mute);
    background: var(--surface);
    text-align: center;
}

.check-row {
    background: var(--surface);
    transition: background 0.12s ease;
}

.check-row__head {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: var(--space-2);
    padding: 12px var(--space-3);
    cursor: pointer;
    user-select: none;
}

.check-row__head:hover { background: var(--surface-hover); }

.check-chevron {
    color: var(--text-mute);
    transition: transform 0.18s ease;
    display: inline-flex;
}

.check-row.expanded .check-chevron { transform: rotate(90deg); }

.check-row__title {
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.check-row__title .check-title-time {
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 12px;
    margin-right: 10px;
}

.check-row__summary {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 12px;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

.check-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-dim);
}

.check-stat-pill.ok    { color: var(--ok);    border-color: rgba(34, 197, 94, 0.3); }
.check-stat-pill.warn  { color: var(--warn);  border-color: rgba(245, 158, 11, 0.3); }
.check-stat-pill.err   { color: var(--err);   border-color: rgba(239, 35, 60, 0.3); }
.check-stat-pill.info  { color: var(--accent); border-color: rgba(59, 130, 246, 0.3); }

.check-row__body {
    display: none;
    padding: 0 var(--space-3) var(--space-2);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.check-row.expanded .check-row__body { display: block; }

.check-line {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 2px 0;
}
.check-line.log-info  { color: var(--text-dim); }
.check-line.log-ok    { color: var(--ok); }
.check-line.log-warn  { color: var(--warn); }
.check-line.log-err   { color: var(--err); }

/* ---- In-flight scan pulse (next to "Last scan" label) ---- */

.scan-pulse {
    display: inline-block;
    position: relative;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    vertical-align: middle;
}
.scan-pulse__core {
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}
.scan-pulse__ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--accent);
    opacity: 0.7;
    animation: scan-pulse-ring 1.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes scan-pulse-ring {
    0%   { transform: scale(0.6); opacity: 0.9; }
    80%  { transform: scale(1.6); opacity: 0; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ---- Pagination ---- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.pager-btn {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.pager-btn:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-strong);
}
.pager-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pager-info {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-mute);
    min-width: 90px;
    text-align: center;
}

/* ---- Detected-trucks: expandable rows ---- */

table.data.expandable tbody tr.scan-row { cursor: pointer; }
table.data.expandable tbody tr.scan-row:hover td { background: var(--surface-hover); }
table.data.expandable tbody tr.scan-row td.expand-cell {
    color: var(--text-mute);
    width: 24px;
}
table.data.expandable tbody tr.scan-row.expanded td.expand-cell svg {
    transform: rotate(90deg);
}
table.data.expandable tbody tr.scan-row td.expand-cell svg {
    transition: transform 0.18s ease;
}
table.data.expandable tbody tr.scan-detail { display: none; background: var(--surface-2); }
table.data.expandable tbody tr.scan-detail.shown { display: table-row; }
table.data.expandable tbody tr.scan-detail td {
    padding: var(--space-2) var(--space-3);
    border-top: 1px dashed var(--border);
}
.scan-detail__grid {
    display: grid;
    grid-template-columns: 130px 1fr;
    column-gap: var(--space-3);
    row-gap: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
}
.scan-detail__grid dt {
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 11px;
}
.scan-detail__grid dd {
    color: var(--text-dim);
    margin: 0;
    word-break: break-word;
}
.scan-detail__grid dd a { color: var(--accent); }


/* ---- Notifications: filter pills row in the surface-card head ---- */

.filter-group {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
}

.filter-pill {
    background: var(--surface-2);
    color: var(--text-mute);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 4px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.filter-pill:hover { color: var(--text); border-color: var(--border-strong); }
.filter-pill.active {
    background: var(--surface);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.25);
}

@media (max-width: 760px) {
    .filter-group { width: 100%; justify-content: flex-start; }
    .filter-pill { padding: 6px 10px; min-height: 32px; }
}

/* ============================================================
   Autobuy toggle (iOS-style on/off switch in customer roster)
   Green = autobuy on, gray = autobuy off. No text label;
   color + thumb position is the affordance.
   ============================================================ */

.autobuy-toggle {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 0;
    padding: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.autobuy-toggle:disabled { opacity: 0.6; cursor: wait; }

.autobuy-toggle__track {
    width: 44px;
    height: 24px;
    border-radius: 14px;
    background: #3F3F46;          /* gray when off */
    position: relative;
    transition: background 0.18s ease;
    flex-shrink: 0;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
}

.autobuy-toggle__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: transform 0.18s ease;
}

.autobuy-toggle.on .autobuy-toggle__track { background: var(--ok); }   /* green when on */
.autobuy-toggle.on .autobuy-toggle__thumb { transform: translateX(20px); }

.autobuy-toggle:focus-visible .autobuy-toggle__track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 760px) {
    .autobuy-toggle { padding: 6px; }
    .autobuy-toggle__track { width: 50px; height: 28px; border-radius: 16px; }
    .autobuy-toggle__thumb { width: 24px; height: 24px; }
    .autobuy-toggle.on .autobuy-toggle__thumb { transform: translateX(22px); }
}

/* ============================================================
   Roster section (Scans → Next up / Last buy / Cool-off)
   Three labeled rows; mobile-friendly stacked layout.
   ============================================================ */

.roster-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: var(--space-3);
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.roster-row:last-child { border-bottom: none; padding-bottom: 0; }
.roster-row:first-child { padding-top: 0; }

.roster-row__label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.roster-row__value {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    color: var(--text);
}

.roster-empty {
    color: var(--text-mute);
    font-style: italic;
    font-size: 13px;
}

.roster-order-hint {
    margin-left: 8px;
    font-size: 11px;
    color: var(--text-mute);
    font-weight: normal;
    text-transform: none;
    letter-spacing: 0;
}

.queue-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    counter-reset: queue;
}
.queue-list__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 13px;
    cursor: grab;
    user-select: none;
    counter-increment: queue;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.queue-list__item::before {
    content: counter(queue);
    min-width: 1.4em;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
}
.queue-list__item:hover { border-color: var(--border-strong); }
.queue-list__item:active { cursor: grabbing; }
.queue-list__item.dragging { opacity: 0.4; }
.queue-list__item.drag-over { border-color: var(--accent, #6366f1); background: rgba(99, 102, 241, 0.08); }
.queue-list__item .queue-name { flex: 1; font-weight: 500; color: var(--text); }
.queue-list__item .queue-handle {
    color: var(--text-mute);
    font-size: 14px;
    line-height: 1;
    cursor: grab;
}
.queue-status {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-mute);
    min-height: 14px;
}
.queue-status.ok  { color: var(--ok); }
.queue-status.err { color: var(--err); }

.customer-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 13px;
}
.customer-chip__name { font-weight: 500; color: var(--text); }
.customer-chip__meta {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    border-left: 1px solid var(--border-strong);
    padding-left: 8px;
}

.customer-chip.ok    { border-color: rgba(34, 197, 94, 0.4);  background: rgba(34, 197, 94, 0.08); }
.customer-chip.ok .customer-chip__name { color: var(--ok); }
.customer-chip.warn  { border-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.08); }
.customer-chip.warn .customer-chip__name { color: var(--warn); }
.customer-chip.err   { border-color: rgba(239, 35, 60, 0.4);  background: rgba(239, 35, 60, 0.08); }
.customer-chip.err .customer-chip__name { color: var(--err); }
.customer-chip.idle  { color: var(--text-dim); }

.roster-upnext-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-left: 4px;
    width: 100%;
    padding-top: 6px;
}
.roster-upnext-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.roster-up-next {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-pill);
    padding: 3px 10px;
}

@media (max-width: 760px) {
    .roster-row {
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 10px 0;
    }
    .customer-chip { font-size: 12px; padding: 5px 10px; }
    .customer-chip__meta { font-size: 10px; }
}

/* ============================================================
   Customers toolbar (search + filter pills)
   ============================================================ */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding: 12px var(--space-3);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.toolbar-search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 220px;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 0 10px;
    transition: border-color 0.12s ease;
}
.toolbar-search:focus-within { border-color: var(--accent); }
.toolbar-search svg { color: var(--text-mute); flex-shrink: 0; }
.toolbar-search input {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    padding: 9px 8px;
    outline: none;
    min-width: 0;
}
.toolbar-search input::placeholder { color: var(--text-mute); }

.toolbar-date {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-mute);
}
.toolbar-date input[type="date"] {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 7px 9px;
    font: inherit;
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
    outline: none;
    color-scheme: dark;
    transition: border-color 0.12s ease;
}
.toolbar-date input[type="date"]:focus { border-color: var(--accent); }

/* Tiny destructive icon button used inline within table rows (delete a
   purchase, delete a notification, etc.). Stays out of the way until
   hovered, then gets a red wash so the action reads as destructive. */
.row-delete-btn {
    background: transparent;
    border: 0;
    color: var(--text-mute);
    padding: 6px;
    border-radius: var(--radius-control);
    cursor: pointer;
    line-height: 0;
    transition: background 0.12s ease, color 0.12s ease;
}
.row-delete-btn:hover {
    background: rgba(239, 68, 68, 0.12);
    color: var(--err);
}
.row-delete-btn:active:not(:disabled) { transform: translateY(1px); }

/* Eye toggle for per-row credential reveal on the customer detail
   page. Sits inline with the value so the value+button group reads as
   one unit; the button only fades to full opacity on hover/focus so it
   doesn't crowd the row. */
.cred-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.cred-row .cred-value {
    flex: 1;
    word-break: break-all;
}
.cred-row .cred-value[data-state="revealed"] {
    color: var(--text);
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
}
.cred-row .cred-value[data-state="masked"] {
    color: var(--text-mute);
    letter-spacing: 0.05em;
}
.cred-eye {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    color: var(--text-mute);
    width: 28px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    line-height: 0;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.cred-eye:hover  { opacity: 1; color: var(--text); border-color: var(--border-strong); }
.cred-eye:focus  { outline: none; opacity: 1; border-color: var(--accent); }
.cred-eye:active:not(:disabled) { transform: translateY(1px); }
.cred-eye:disabled { opacity: 0.4; cursor: progress; }

@media (max-width: 760px) {
    .toolbar { padding: 10px var(--space-2); gap: 8px; }
    .toolbar-search { flex: 1 1 100%; }
    .toolbar .filter-group { flex: 1 1 100%; }
    .toolbar-search input { padding: 11px 8px; }
    .toolbar-date { flex: 1 1 calc(50% - 4px); }
    .toolbar-date input[type="date"] { flex: 1; min-width: 0; }
}

/* ============================================================
   Customer detail: tab strip + autobuy bar
   ============================================================ */

.cd-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--border);
}

.cd-tab {
    background: transparent;
    border: 0;
    color: var(--text-mute);
    padding: 10px 16px;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.12s ease, border-color 0.12s ease;
}
.cd-tab:hover { color: var(--text); }
.cd-tab.active {
    color: var(--text);
    border-bottom-color: var(--primary);
}

.cd-tabpanel { display: none; animation: fadeUp 0.25s ease both; }
.cd-tabpanel.active { display: block; }

.autobuy-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 12px 16px;
    margin-bottom: var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
}
.autobuy-bar__label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.autobuy-bar__label > span {
    font-weight: 500;
    color: var(--text);
}
.autobuy-bar__label > small {
    color: var(--text-mute);
    font-size: 12px;
}

@media (max-width: 760px) {
    .cd-tabs { gap: 0; overflow-x: auto; }
    .cd-tab { padding: 12px 14px; flex-shrink: 0; }
    .autobuy-bar { padding: 12px; }
}

/* ============================================================
   Analytics page
   ============================================================ */

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.chart-card { display: flex; flex-direction: column; }
.chart-card--wide { grid-column: span 2; }
.chart-card--full { grid-column: 1 / -1; }   /* spans the full chart-grid row */
.chart-card .surface-card-body { flex: 1; min-height: 0; }
/* Horizontal bar charts (10 trucks) get more vertical room to breathe. */
.chart-card--full .chart-host { height: 360px; }

.chart-host {
    position: relative;
    width: 100%;
    height: 280px;
    /* Chart.js sizes the canvas based on the container. We give it a
       deterministic height so the layout doesn't jump around as data loads. */
}

.data-gaps {
    list-style: disc;
    margin: 0;
    padding-left: 20px;
    color: var(--text-dim);
    font-size: 13px;
}
.data-gaps li { margin: 6px 0; }

@media (max-width: 1100px) {
    .chart-card--wide,
    .chart-card--full { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .chart-grid {
        grid-template-columns: 1fr;
        gap: var(--space-1);
    }
    .chart-host { height: 220px; }
    .panel-actions #analyticsRange { flex-wrap: wrap; }
}

/* ============================================================
   Audit page — time column nowrap + native select styling
   ============================================================ */

/* Keep "Today · 3:14 PM" on one line so the AM/PM never wraps. */
.audit-col-time { white-space: nowrap; }

/* Native <select> styled to match the rest of the toolbar inputs. */
.select-input {
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 9px 32px 9px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-mute) 50%),
        linear-gradient(135deg, var(--text-mute) 50%, transparent 50%);
    background-position: calc(100% - 18px) 14px, calc(100% - 13px) 14px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    transition: border-color 0.12s ease;
    min-height: 38px;
}
.select-input:focus { outline: none; border-color: var(--accent); }

@media (max-width: 760px) {
    /* On phone the table goes to cards, so the time row is its own block —
       still keep the value on a single line within that block. */
    table.data td.audit-col-time { white-space: nowrap; }
    .select-input { flex: 1 1 100%; min-height: 44px; }
}

/* ============================================================
   Test buy form
   ============================================================ */

.testbuy-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2) var(--space-3);
    align-items: start;
}
.testbuy-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.testbuy-form label small {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    color: var(--text-mute);
    font-size: 11px;
    margin-left: 6px;
}
.testbuy-form label.span-2 { grid-column: 1 / -1; }
.testbuy-form input { margin-top: 0; }
.testbuy-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: var(--space-2);
    align-items: center;
    margin-top: 4px;
}

button.btn-row-delete {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-mute);
    padding: 4px 12px;
    border-radius: var(--radius-control);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease;
}
button.btn-row-delete:hover {
    color: var(--err);
    border-color: var(--err);
}

@media (max-width: 760px) {
    .testbuy-form { grid-template-columns: 1fr; gap: 12px; }
    .testbuy-actions .btn { flex: 1; }
    button.btn-row-delete { padding: 8px 14px; min-height: 36px; }
}

/* ============================================================
   Friendly Live log tail rendering
   ============================================================ */

.check-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.check-line .logfmt-icon {
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
}

.check-line .logfmt-label {
    font-weight: 500;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 12px;
    text-transform: none;
}

.check-line .logfmt-truck {
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
}

.check-line .logfmt-meta {
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 11px;
    margin-left: auto;          /* push trailing meta to the right */
}

/* Severity tints — same as before, but apply to icon when emoji is missing. */
.check-line.logfmt-tracked-avail .logfmt-icon { color: var(--ok); }
.check-line.logfmt-skipped       .logfmt-icon { color: var(--warn); }
.check-line.logfmt-excluded      .logfmt-icon { color: var(--text-mute); }
.check-line.logfmt-autobuy       .logfmt-label,
.check-line.logfmt-autobuy       .logfmt-icon  { color: var(--accent); }
.check-line.logfmt-autobuy-off   .logfmt-icon  { color: var(--warn); }
.check-line.logfmt-no-new        .logfmt-icon,
.check-line.logfmt-no-new        .logfmt-label { color: var(--text-mute); }
.check-line.logfmt-heartbeat     .logfmt-icon  { color: var(--primary); }

@media (max-width: 760px) {
    .check-line .logfmt-meta { margin-left: 0; flex-basis: 100%; }
    .check-line .logfmt-truck { flex-basis: 100%; }
}

/* ============================================================
   Login health section (Scans page)
   ============================================================ */

.login-row {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: var(--space-3);
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.login-row:first-child { padding-top: 0; }
.login-row:last-child  { border-bottom: none; padding-bottom: 0; }

.login-row__label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.login-row__value {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.login-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.login-pill.ok  { background: rgba(34, 197, 94, 0.1); color: var(--ok);  border: 1px solid rgba(34, 197, 94, 0.25); }
.login-pill.err { background: rgba(239, 35, 60, 0.1); color: var(--err); border: 1px solid rgba(239, 35, 60, 0.25); }

.login-email   { color: var(--text); font-size: 13px; }
.login-meta    { color: var(--text-mute); font-size: 11px; }
.login-error   { color: var(--err); font-size: 11px; flex-basis: 100%; word-break: break-all; }

.login-attempt-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-size: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.login-attempt-chip.ok  { color: var(--ok); }
.login-attempt-chip.err { color: var(--err); }
.login-attempt-dot {
    width: 5px; height: 5px; border-radius: 50%;
    background: currentColor;
}

@media (max-width: 760px) {
    .login-row { grid-template-columns: 1fr; gap: 6px; padding: 10px 0; }
}

/* ============================================================
   Test detail page (sub-panel of testbuy)
   ============================================================ */

.td-summary {
    margin: 0 0 12px 0;
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
}

.td-error {
    margin: 0;
    padding: var(--space-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 480px;
    overflow-y: auto;
}

#tdScreenshot {
    border-top: 1px solid var(--border);
    background: #000;
}

#tdScreenshotLink:hover #tdScreenshot {
    filter: brightness(1.05);
}

@media (max-width: 760px) {
    .td-summary { font-size: 14px; }
    .td-error { font-size: 11px; padding: 12px; max-height: 320px; }
}

/* Live-submit toggle on the test buy form */
.testbuy-livesubmit {
    flex-direction: row !important;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    text-transform: none !important;
    letter-spacing: 0 !important;
    font-weight: 400 !important;
    color: var(--text) !important;
}
.testbuy-livesubmit input[type="checkbox"] {
    width: 18px; height: 18px;
    flex-shrink: 0;
    accent-color: var(--primary);
    cursor: pointer;
    margin: 0 !important;
    padding: 0 !important;
}
.testbuy-livesubmit > span:not(.icon) { font-weight: 500; font-size: 14px; }
.testbuy-livesubmit small {
    flex-basis: 100%;
    color: var(--text-mute);
    font-size: 12px;
    margin-left: 28px;
    line-height: 1.4;
}

/* ============================================================
   Test history: keep cells on one line, truncate with ellipsis,
   show full value on hover (and on the detail page).
   ============================================================ */

#testbuyTable td.testbuy-trunc {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}
#testbuyTable td[data-label="Outcome"].testbuy-trunc { max-width: 320px; }
#testbuyTable td[data-label="Truck"].testbuy-trunc   { max-width: 200px; color: var(--text-dim); }
#testbuyTable tr.clickable-row { cursor: pointer; }

@media (max-width: 760px) {
    /* On mobile (card mode) cells are full-width; truncate the value
       portion only — the data-label pseudo stays at its own size. */
    #testbuyTable td.testbuy-trunc {
        max-width: none;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ---- Per-scan screenshots + lightbox ---- */

.scan-shots {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--border);
}
.scan-shots-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.scan-shot-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 2px 6px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    vertical-align: middle;
}
.scan-shot-badge svg { color: var(--text-mute); }

.scan-captures {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.scan-captures-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}
.scan-capture {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease;
}
.scan-capture:hover { border-color: var(--border-strong); }
.scan-capture-meta {
    flex: 1;
    font-size: 11px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.scan-capture-hint {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---- Observed products table ---- */

.product-row { cursor: default; }
.product-row.untracked td {
    color: var(--text-mute);
    opacity: 0.55;
}
.product-row.untracked td .autobuy-toggle { opacity: 1; }   /* toggles stay clickable */

.product-row .expand-cell {
    cursor: pointer;
    width: 24px;
    text-align: center;
    color: var(--text-mute);
    transition: transform 0.15s ease, color 0.15s ease;
}
.product-row.expanded .expand-cell svg { transform: rotate(90deg); }
.product-row .expand-cell:hover { color: var(--text); }

tr.product-detail { display: none; }
tr.product-detail.shown { display: table-row; }
.product-detail__body {
    padding: 12px 16px;
    background: var(--surface-2);
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.product-detail__field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.product-detail__label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.product-detail__textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    resize: vertical;
}
.product-detail__textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.product-detail__hint {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
}
.product-detail__price-input {
    width: 200px;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
}
.product-detail__price-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
a.product-link {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px dotted var(--border-strong);
}
a.product-link:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* per-product detail page */
.pd-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-2);
}
.pd-cell {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.pd-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.pd-value {
    font-size: 18px;
    color: var(--text);
}
.pd-hint {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
}

/* Expandable Purchase ledger rows */
.purchase-row { cursor: pointer; }
.purchase-row .expand-cell {
    width: 24px;
    text-align: center;
    color: var(--text-mute);
    transition: transform 0.15s ease;
}
.purchase-row.expanded .expand-cell svg { transform: rotate(90deg); }
tr.purchase-detail { display: none; }
tr.purchase-detail.shown { display: table-row; }
.purchase-detail__body {
    padding: 12px 16px;
    background: var(--surface-2);
    border-top: 1px dashed var(--border);
}

/* AI-diagnosis block at the top of an expanded purchase row. Visually
   prominent — accent border + slightly raised surface — so the operator's
   eye lands here first before the raw fields. */
.purchase-detail__diagnose {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 12px 14px;
    margin-bottom: 14px;
}
.diagnose-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.diagnose-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.diagnose-refresh {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-mute);
    border-radius: var(--radius-control);
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: color 0.12s ease, border-color 0.12s ease, transform 0.4s ease;
}
.diagnose-refresh:hover { color: var(--text); border-color: var(--border-strong); }
.diagnose-refresh:active { transform: rotate(180deg); }
.diagnose-text { margin: 0 0 8px; color: var(--text); line-height: 1.45; }
.diagnose-action {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 8px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-control);
    color: var(--text);
    font-size: 13px;
    line-height: 1.4;
}
.diagnose-action-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ok);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}
.diagnose-footer {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.diagnose-meta { flex: 1; }
.diagnose-model { opacity: 0.7; }
.diagnose-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
    font-style: italic;
}
.diagnose-loading::before {
    content: '';
    width: 10px;
    height: 10px;
    border: 1.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: diagnose-spin 0.8s linear infinite;
}
@keyframes diagnose-spin { to { transform: rotate(360deg); } }
.diagnose-error { color: var(--err); }
@media (prefers-reduced-motion: reduce) {
    .diagnose-loading::before { animation: none; }
    .diagnose-refresh:active { transform: none; }
}
.purchase-detail__error {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--border);
}
.purchase-detail__pre {
    margin: 0;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow-y: auto;
}

.purchase-detail__capture {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--border);
}

.capture-summary {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 10px 14px;
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.capture-summary-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 12px;
}
.capture-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 70px;
}

.capture-section {
    margin-top: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
}
.capture-section > summary {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    user-select: none;
}
.capture-section > summary:hover { color: var(--accent); }
.capture-section[open] > summary {
    border-bottom: 1px solid var(--border);
}
.capture-section .purchase-detail__pre {
    margin: 0;
    border: 0;
    border-radius: 0 0 var(--radius-control) var(--radius-control);
    max-height: 420px;
}

/* ---- Live availability alert drawer ---- */

.alert-drawer {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: min(380px, calc(100vw - 32px));
    z-index: 90;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-control);
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    overflow: hidden;
    display: none;
}
.alert-drawer.has-items { display: flex; flex-direction: column; }

.alert-drawer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.alert-drawer-title {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.alert-drawer-mute {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
}
.alert-drawer-clear {
    background: transparent;
    color: var(--text-mute);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 3px 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    cursor: pointer;
}
.alert-drawer-clear:hover { color: var(--text); border-color: var(--border-strong); }

.alert-drawer-list {
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
}

.alert-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--ok);
    border-radius: var(--radius-control);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: alertSlideIn 0.25s ease-out;
}
.alert-card.status-fail   { border-left-color: var(--err); }
.alert-card.status-manual { border-left-color: var(--warn); }
.alert-card.status-missed { border-left-color: var(--warn); }
@keyframes alertSlideIn {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.alert-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-card-name {
    flex: 1;
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
}
.alert-card-meta {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.alert-card-status {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
}
.alert-card-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}
.alert-card-buy {
    flex: 1;
    text-align: center;
    background: var(--ok);
    color: #0a0a0a;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: var(--radius-control);
    font-size: 12px;
    font-weight: 600;
}
.alert-card-buy:hover { filter: brightness(1.1); }
.alert-card-dismiss {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-mute);
    border-radius: var(--radius-control);
    padding: 5px 10px;
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    cursor: pointer;
}
.alert-card-dismiss:hover { color: var(--text); border-color: var(--border-strong); }

.shot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-2);
}

.shot-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease;
    display: flex;
    flex-direction: column;
}
.shot-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.shot-card img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: var(--bg);
    display: block;
}
.shot-card-meta {
    padding: 8px 10px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-top: 1px solid var(--border);
}
.shot-card-name {
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.shot-card-sub {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-3);
}
.lightbox[hidden] { display: none; }

.lightbox-figure {
    margin: 0;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    align-items: center;
}
.lightbox-figure img {
    max-width: 100%;
    max-height: calc(100vh - 120px);
    object-fit: contain;
    border-radius: var(--radius-control);
    background: var(--bg);
}
.lightbox-caption {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.lightbox-caption-meta {
    color: var(--text-mute);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lightbox-close,
.lightbox-nav {
    position: absolute;
    background: rgba(20, 20, 20, 0.7);
    border: 1px solid var(--border);
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.lightbox-close:hover,
.lightbox-nav:hover {
    background: rgba(40, 40, 40, 0.9);
    border-color: var(--border-strong);
}
.lightbox-close {
    top: 16px;
    right: 16px;
    font-size: 24px;
}
.lightbox-nav--prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-nav--next { right: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-nav[disabled] { opacity: 0.3; cursor: not-allowed; }

/* ---- Live View ---- */

.liveview-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: var(--space-3);
    align-items: stretch;
}

.liveview-left {
    max-height: calc(100vh - var(--topbar-h) - 8rem);
    display: flex;
    flex-direction: column;
}
.liveview-left .surface-card-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow: hidden;
}

.liveview-search {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    color: var(--text);
    font-size: 13px;
}
.liveview-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.liveview-customer-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 200px;
}

.liveview-customer {
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.liveview-customer:hover { border-color: var(--border-strong); }
.liveview-customer.selected {
    border-color: var(--accent);
    background: var(--surface-hover);
}
.liveview-customer-name {
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
}
.liveview-customer-meta {
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.liveview-right {
    display: flex;
    flex-direction: column;
}

.liveview-toolbar {
    display: flex !important;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.liveview-url-input {
    flex: 1;
    min-width: 280px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    color: var(--text);
    font-size: 12px;
    font-family: var(--font-mono);
}
.liveview-url-input:focus {
    outline: none;
    border-color: var(--accent);
}

.liveview-viewport {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.liveview-status {
    padding: 8px 12px;
    background: var(--surface-2);
    border-left: 3px solid var(--border-strong);
    border-radius: 0 var(--radius-control) var(--radius-control) 0;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    text-transform: none;
    letter-spacing: 0;
}
.liveview-status.ok    { border-left-color: var(--ok); color: var(--text); }
.liveview-status.warn  { border-left-color: var(--warn); }
.liveview-status.err   { border-left-color: var(--err); color: var(--text); }

.liveview-frame {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    overflow: hidden;
    min-height: 480px;
    display: flex;
    align-items: stretch;
    justify-content: center;
}
.liveview-frame iframe {
    width: 100%;
    height: 75vh;
    border: 0;
    display: block;
    background: white;
}
.liveview-frame img {
    width: 100%;
    height: auto;
    display: block;
}

.liveview-customer-detail {
    margin-top: var(--space-2);
    padding: var(--space-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.liveview-customer-detail h3 {
    margin: 0 0 4px 0;
    font-size: 12px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-mono);
    font-weight: 600;
}
.liveview-copy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    cursor: pointer;
    transition: border-color 0.15s ease;
}
.liveview-copy-row:hover { border-color: var(--border-strong); }
.liveview-copy-row.copied { border-color: var(--ok); }
.liveview-copy-row-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 70px;
}
.liveview-copy-row-value {
    flex: 1;
    color: var(--text);
    font-size: 12px;
    font-family: var(--font-mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.liveview-copy-row-hint {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-mute);
    text-transform: uppercase;
}
.liveview-copy-row.copied .liveview-copy-row-hint { color: var(--ok); }

.liveview-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}
.liveview-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@media (max-width: 1100px) {
    .liveview-grid {
        grid-template-columns: 1fr;
    }
    .liveview-left {
        max-height: 360px;
    }
}

/* ============================================================
   Motion polish
   ----------------------------------------------------------------
   Small, tasteful additions on top of the existing transitions:
     · Tactile press feedback on clickable surfaces
     · Cross-fade between tab panels via View Transitions API
       (progressive enhancement — old browsers fall through to
       the existing fadeUp keyframe)
     · Smooth content reveal inside expanded scan-detail rows
     · Honor prefers-reduced-motion across the whole sheet
   ============================================================ */

/* Tactile press feedback. Pairs with each control's existing
   transition declarations — only adds the active transform. */
.btn:active:not(:disabled),
.signout-btn:active:not(:disabled),
.nav-item:active:not(:disabled),
.filter-pill:active:not(:disabled),
.pager-btn:active:not(:disabled),
.alert-card-buy:active,
.alert-card-dismiss:active {
    transform: translateY(1px);
}

/* Content reveal when a scan row is expanded. The <tr> itself still
   appears/disappears via display: none ↔ table-row (CSS can't transition
   `display`), but its inner content slides in smoothly. */
table.data.expandable tbody tr.scan-detail.shown > td > * {
    animation: detailReveal 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes detailReveal {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* View Transitions: each of the three chrome regions gets its own
   transition-name so the browser captures them as separate snapshots.
   The sidebar and topbar look identical across tab switches, so their
   default cross-fade is a no-op — they appear visually stable. Only
   `.content` animates, and because it has its own snapshot layer it
   can't overpaint the fixed-position sidebar (z-index: 20). */
.sidebar { view-transition-name: app-sidebar; }
.topbar  { view-transition-name: app-topbar;  }
.content { view-transition-name: app-content; }

::view-transition-old(app-content),
::view-transition-new(app-content) {
    animation-duration: 0.34s;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}
::view-transition-old(app-content) { animation-name: vtPanelOut; }
::view-transition-new(app-content) { animation-name: vtPanelIn;  }

@keyframes vtPanelOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-8px); }
}
@keyframes vtPanelIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Sidebar + topbar: explicitly suppress motion on their snapshots —
   the only safe way to guarantee they don't drift during the transition
   even on browsers that infer motion from layout deltas. */
::view-transition-old(app-sidebar),
::view-transition-new(app-sidebar),
::view-transition-old(app-topbar),
::view-transition-new(app-topbar) {
    animation: none;
}

/* Fallback for browsers without View Transitions API: bump the existing
   .panel fade-up to be more visibly page-like. Doesn't conflict with VT
   — when VT runs, the live DOM animations are masked by the snapshot
   layer anyway. */
.panel { animation: fadeUp 0.32s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Section reveal — top-level panel sections (header, metric strip,
   surface cards) start hidden when the page is "motion-ready" (an
   inline <head> script sets that class before body parses, so there's
   no flash of visible content before the cascade plays). JS then adds
   `.is-revealed` either via a cascade on tab-enter or via an
   IntersectionObserver for sections that scroll into view. */
html.motion-ready .panel > .panel-header,
html.motion-ready .panel .metric-strip,
html.motion-ready .panel .surface-card {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: opacity, transform;
}
html.motion-ready .panel .is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Honor the OS-level accessibility setting. Anyone who has
   "Reduce motion" turned on gets a static UI — no fades, no slides,
   no pulses. Keeps shape changes (display, layout) intact so the
   page remains usable. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    ::view-transition-old(root),
    ::view-transition-new(root),
    ::view-transition-old(app-content),
    ::view-transition-new(app-content) {
        animation: none !important;
    }
    /* Reduced-motion: surface the sections immediately, no fade-up. */
    html.motion-ready .panel > .panel-header,
    html.motion-ready .panel .metric-strip,
    html.motion-ready .panel .surface-card {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
}
