/* ============================================================
   FEAT-334 — Roster Integrity Console  (.ri-*)
   ============================================================ */

/* --- FEAT-341/342 INFO tier colour tokens (CVD-safe; applied inline in Python) --- */
:root {
    --ri-tier-standby-idle:     #1098ad;  /* teal */
    --ri-tier-unrostered-drive: #7048e8;  /* indigo */
}

/* --- page shell --- */
.ri-page {
    padding: 16px 20px;
    min-height: 100vh;
}

.ri-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}

.ri-page-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.ri-sensitivity-badge {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    background: #dc354522;
    color: #dc3545;
    border: 1px solid #dc354544;
}

/* --- filter bar --- */
.ri-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: var(--card-bg, #1e2130);
    border: 1px solid var(--border-color, #2e3348);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 12px;
}

.ri-filter-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ri-filter-item--tiers {
    flex: 1;
    min-width: 280px;
}

.ri-filter-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.6;
    margin-bottom: 2px;
}

/* --- tier pills --- */
.ri-tier-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ri-tier-pill {
    font-size: 0.78rem;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color, #2e3348);
    background: transparent;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s, border-color 0.15s;
    color: inherit;
}

.ri-tier-pill--active {
    opacity: 1;
    border-color: rgba(255,255,255,0.35);
}

body[data-theme="light"] .ri-tier-pill {
    border-color: #dee2e6;
    color: #495057;
}

body[data-theme="light"] .ri-tier-pill--active {
    border-color: #adb5bd;
}

/* --- stats strip --- */
.ri-stats-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 10px;
    padding: 0 2px;
}

.ri-stat {
    font-size: 0.85rem;
    opacity: 0.8;
}

.ri-stat--phantom strong { color: #fd7e14; }
.ri-stat--sg      strong { color: #dc3545; }

/* --- export bar --- */
.ri-export-bar {
    margin-bottom: 10px;
}

/* --- table wrapper --- */
.ri-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ri-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
}

/* --- summary row --- */
.ri-th {
    padding: 8px 10px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    border-bottom: 2px solid var(--border-color, #2e3348);
    white-space: nowrap;
    background: var(--card-bg, #1e2130);
    position: sticky;
    top: 0;
    z-index: 1;
}

.ri-th-toggle { width: 32px; }
.ri-th-num    { text-align: right; }

.ri-td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color, #2e3348);
    vertical-align: middle;
}

.ri-td-toggle { width: 32px; }
.ri-td-id     { font-family: monospace; font-size: 0.8rem; opacity: 0.8; }
.ri-td-num    { text-align: right; font-variant-numeric: tabular-nums; }
.ri-td-phantom, .ri-td-sg { font-weight: 600; }

.ri-summary-row:hover td { background: rgba(255,255,255,0.03); }
.ri-summary-row--expanded td { background: rgba(255,255,255,0.04); }

body[data-theme="light"] .ri-summary-row:hover td {
    background: rgba(0,0,0,0.03);
}
body[data-theme="light"] .ri-summary-row--expanded td {
    background: rgba(0,0,0,0.04);
}

/* --- expand button --- */
.ri-expand-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.15s;
    color: inherit;
}

.ri-expand-btn:hover,
.ri-expand-btn--open { opacity: 1; }

/* --- evidence rows --- */
.ri-evidence-header-row th {
    padding: 5px 8px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: var(--sidebar-bg, #161927);
    border-bottom: 1px solid var(--border-color, #2e3348);
    white-space: nowrap;
    opacity: 0.7;
}

.ri-ev-th-num { text-align: right; }
.ri-ev-indent { width: 40px; }

.ri-evidence-row td { padding: 5px 8px; }
.ri-ev-indent  { background: var(--sidebar-bg, #161927); }
.ri-ev-cell    { font-size: 0.78rem; background: var(--sidebar-bg, #161927); }
.ri-ev-num     { text-align: right; font-variant-numeric: tabular-nums; }
.ri-ev-clock   { font-family: monospace; font-size: 0.75rem; white-space: nowrap; }
.ri-ev-ro      { font-family: monospace; font-size: 0.75rem; white-space: nowrap; }
.ri-ev-loading { font-style: italic; opacity: 0.5; }

body[data-theme="light"] .ri-evidence-header-row th,
body[data-theme="light"] .ri-ev-cell,
body[data-theme="light"] .ri-ev-indent {
    background: #f4f5f7;
}

/* --- tier badge --- */
.ri-tier-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    color: #fff;
    padding: 2px 7px;
    border-radius: 10px;
    margin-right: 4px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* --- empty / access / loading states --- */
.ri-empty-state {
    padding: 40px 20px;
    text-align: center;
    opacity: 0.5;
    font-style: italic;
}

.ri-access-denied {
    padding: 40px 20px;
    text-align: center;
    color: #dc3545;
}

.ri-loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.ri-loading-text {
    background: var(--card-bg, #1e2130);
    padding: 16px 28px;
    border-radius: 8px;
    font-size: 1rem;
    border: 1px solid var(--border-color, #2e3348);
}

/* --- 390px responsive --- */
@media (max-width: 480px) {
    .ri-page { padding: 10px 10px; }
    .ri-filter-bar { padding: 10px; gap: 8px; }
    .ri-filter-item--tiers { min-width: 100%; }
    .ri-table { font-size: 0.75rem; }
    .ri-th, .ri-td { padding: 6px 6px; }
    .ri-evidence-row td { padding: 4px 6px; }
}

/* --- FEAT-334: severity legend panel --- */
.ri-legend { margin: 8px 0 14px; border: 1px solid var(--ri-border, #d0d5dd); border-radius: 8px; background: var(--ri-panel, #f8f9fb); }
.ri-legend-summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 0.9rem; list-style: none; user-select: none; color: var(--ri-fg, #344054); }
.ri-legend-summary::-webkit-details-marker { display: none; }
.ri-legend[open] .ri-legend-summary { border-bottom: 1px solid var(--ri-border, #d0d5dd); }
.ri-legend-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.ri-legend-row { display: flex; align-items: flex-start; gap: 12px; }
.ri-legend-row .ri-tier-badge { flex: 0 0 108px; text-align: center; color: #fff; padding: 3px 8px; border-radius: 4px; font-size: 0.78rem; font-weight: 600; }
.ri-legend-text { flex: 1; font-size: 0.85rem; line-height: 1.4; color: var(--ri-fg, #475467); }
.ri-legend-formula { border-top: 1px dashed var(--ri-border, #d0d5dd); padding-top: 10px; }
body[data-theme="dark"] .ri-legend { --ri-border: #3a3f4b; --ri-panel: #1e2230; --ri-fg: #c4cad6; }
.ri-driver-search { padding: 5px 9px; border: 1px solid var(--ri-border, #d0d5dd); border-radius: 5px; font-size: 0.85rem; }
body[data-theme="dark"] .ri-driver-search { background: #1e2230; border-color: #3a3f4b; color: #e4e7ec; }

/* ============================================================
   FEAT-335 — Roster Integrity Console v2 additions
   ============================================================ */

/* --- management overview panel --- */
.ri-overview { margin: 8px 0 14px; border: 1px solid var(--ri-border, #d0d5dd); border-radius: 8px; background: var(--ri-panel, #f8f9fb); }
.ri-overview-summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 0.9rem; list-style: none; user-select: none; color: var(--ri-fg, #344054); }
.ri-overview-summary::-webkit-details-marker { display: none; }
.ri-overview[open] .ri-overview-summary { border-bottom: 1px solid var(--ri-border, #d0d5dd); }
.ri-overview-body { padding: 14px; }
body[data-theme="dark"] .ri-overview { --ri-border: #3a3f4b; --ri-panel: #1e2230; --ri-fg: #c4cad6; }

.ri-overview-top { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; }
.ri-overview-section { flex: 1; min-width: 220px; }
.ri-overview-section--full { flex: 100%; }
.ri-overview-section-title { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.55; margin: 0 0 8px; }

/* KPI tiles */
.ri-kpi-tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.ri-kpi-tile { flex: 1; min-width: 110px; background: var(--card-bg, #1e2130); border: 1px solid var(--border-color, #2e3348); border-radius: 8px; padding: 10px 12px; }
body[data-theme="light"] .ri-kpi-tile { background: #fff; border-color: #e5e7eb; }
.ri-kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.ri-kpi-label { font-size: 0.72rem; opacity: 0.6; margin-top: 4px; }

/* Depot bars */
.ri-depot-bars { display: flex; flex-direction: column; gap: 6px; }
.ri-depot-bar-row { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.ri-depot-bar-name { flex: 0 0 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-depot-bar-track { flex: 1; height: 12px; background: var(--border-color, #2e3348); border-radius: 3px; overflow: hidden; }
body[data-theme="light"] .ri-depot-bar-track { background: #e5e7eb; }
.ri-depot-bar-val { flex: 0 0 32px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: #dc3545; }

/* Top-10 table */
.ri-top10-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.ri-top10-th { padding: 5px 8px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 2px solid var(--border-color, #2e3348); opacity: 0.6; }
.ri-top10-td { padding: 5px 8px; border-bottom: 1px solid var(--border-color, #2e3348); }
.ri-top10-num { text-align: right; font-variant-numeric: tabular-nums; }
.ri-jump-btn { font-size: 0.72rem; padding: 2px 8px; background: transparent; border: 1px solid var(--border-color, #2e3348); border-radius: 4px; cursor: pointer; opacity: 0.7; color: inherit; transition: opacity 0.15s; }
.ri-jump-btn:hover { opacity: 1; }
.ri-case-file-btn { font-size: 0.72rem; padding: 2px 8px; background: transparent; border: 1px solid #0d6efd; border-radius: 4px; cursor: pointer; color: #0d6efd; transition: opacity 0.15s; }
.ri-case-file-btn:hover { opacity: 0.75; }
body[data-theme="dark"] .ri-case-file-btn { border-color: #6ea8fe; color: #6ea8fe; }

/* --- depot→driver→date tree --- */
.ri-tree { display: flex; flex-direction: column; }

/* Layer 1 — depot row */
.ri-depot-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border-color, #2e3348); cursor: default; }
.ri-depot-row--open { background: rgba(255,255,255,0.03); }
body[data-theme="light"] .ri-depot-row--open { background: rgba(0,0,0,0.02); }
.ri-depot-name { font-weight: 600; font-size: 0.9rem; flex: 0 0 auto; }
.ri-depot-meta { display: flex; align-items: center; gap: 4px; font-size: 0.8rem; opacity: 0.7; flex-wrap: wrap; }
.ri-depot-stat { white-space: nowrap; }
.ri-depot-stat--ph { color: #fd7e14; font-weight: 600; opacity: 1; }
.ri-depot-stat--sg { color: #dc3545; font-weight: 600; opacity: 1; }
.ri-depot-sep { opacity: 0.4; }

/* Layer 2 — driver block / row */
.ri-driver-block { display: flex; flex-direction: column; }
.ri-driver-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border-color, #2e3348); font-size: 0.83rem; }
.ri-driver-row--open { background: rgba(255,255,255,0.04); }
body[data-theme="light"] .ri-driver-row--open { background: rgba(0,0,0,0.03); }
.ri-indent-1 { display: inline-block; width: 24px; flex-shrink: 0; }
.ri-driver-name { font-weight: 500; }
.ri-driver-id { font-family: monospace; font-size: 0.78rem; opacity: 0.6; }
.ri-driver-meta { display: flex; align-items: center; gap: 2px; font-size: 0.78rem; opacity: 0.75; flex-wrap: wrap; }
.ri-driver-stat--ph { color: #fd7e14; }
.ri-driver-stat--sg { color: #dc3545; font-weight: 600; }
.ri-driver-flags { display: flex; gap: 3px; flex-wrap: wrap; }

/* Layer 3 — date row */
.ri-date-row { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--border-color, #2e3348); font-size: 0.8rem; background: var(--sidebar-bg, #161927); }
.ri-date-row--open { background: rgba(255,255,255,0.06); }
body[data-theme="light"] .ri-date-row { background: #f4f5f7; }
body[data-theme="light"] .ri-date-row--open { background: rgba(0,0,0,0.04); }
.ri-indent-2 { display: inline-block; width: 48px; flex-shrink: 0; }
.ri-date-label { font-family: monospace; font-weight: 600; }
.ri-date-badge { }
.ri-date-vehicle { font-family: monospace; font-size: 0.78rem; }
.ri-date-extra-buses { font-size: 0.70rem; opacity: 0.55; margin-left: 2px; }
.ri-date-trips { font-variant-numeric: tabular-nums; opacity: 0.8; font-size: 0.78rem; }
.ri-date-ro { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; opacity: 0.4; }
.ri-date-ro--active { opacity: 1; color: #6f42c1; }
/* FEAT-340: RO open while in service badge — amber, info tier only */
.ri-ro-open-badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.66rem; font-weight: 700; background: #b45309; color: #fff; }
body[data-theme="dark"] .ri-ro-open-badge { background: #d97706; }

/* Loading placeholder */
.ri-date-loading { padding: 6px 10px 6px 82px; font-style: italic; font-size: 0.8rem; opacity: 0.5; border-bottom: 1px solid var(--border-color, #2e3348); }

/* Layer 4 — evidence card */
.ri-evidence-card { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--sidebar-bg, #161927); }
body[data-theme="light"] .ri-evidence-card { background: #f4f5f7; }
.ri-evidence-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }

/* --- RISK-001 guardrail notice --- */
.ri-guardrail-notice {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.83rem;
    line-height: 1.5;
    padding: 8px 14px;
    margin-bottom: 10px;
    background: var(--ri-panel, #f8f9fb);
    border: 1px solid var(--ri-border, #d0d5dd);
    border-radius: 6px;
}
body[data-theme="dark"] .ri-guardrail-notice { --ri-border: #3a3f4b; --ri-panel: #1e2230; }

/* Headline split tiles */
.ri-overview-headline { margin-bottom: 4px; }
.ri-kpi-tiles--headline { gap: 12px; }
.ri-kpi-tile--actionable { border-color: #dc354566; }
.ri-kpi-tile--investigate { opacity: 0.6; }
.ri-kpi-value--muted { color: #fd7e14; }

/* Info-only driver rows (no fraud tier) are visually subordinate */
.ri-driver-row--phantom-only,
.ri-driver-row--info-only { opacity: 0.6; }
.ri-driver-row--phantom-only .ri-driver-name,
.ri-driver-row--info-only .ri-driver-name { font-weight: 400; }

/* Remark cell — SP evidence line, wrap long text */
.ri-ev-remark { max-width: 320px; white-space: normal; color: #495057; }

/* 390px responsive adjustments for v2 additions */
@media (max-width: 480px) {
    .ri-kpi-tiles { gap: 8px; }
    .ri-kpi-tile { min-width: 80px; padding: 8px 10px; }
    .ri-kpi-value { font-size: 1.2rem; }
    .ri-depot-bar-name { flex-basis: 80px; }
    .ri-driver-meta, .ri-depot-meta { display: none; }
    .ri-driver-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* FEAT-336/RISK: driver ID always visible alongside (possibly blank) name — Jack UAT */
.ri-driver-id { font-family: monospace; font-weight: 700; margin-right: 6px; }
.ri-driver-name--missing { font-style: italic; opacity: 0.6; }

/* FEAT-339-P1c collusion pairs */
.ri-pairs-note { color: var(--ri-muted, #9aa4b2); font-size: 0.85rem; margin: 0 0 0.5rem; }
.ri-pairs-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.ri-pairs-th { text-align: left; padding: 0.35rem 0.6rem; color: var(--ri-muted, #9aa4b2);
               border-bottom: 1px solid rgba(255,255,255,0.08); font-weight: 600; }
.ri-pairs-td { padding: 0.3rem 0.6rem; border-bottom: 1px solid rgba(255,255,255,0.05); vertical-align: top; }
.ri-pairs-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.ri-pairs-arrow { text-align: center; color: #f0a020; }
.ri-pairs-dates { color: var(--ri-muted, #9aa4b2); font-size: 0.78rem; }
.ri-pairs-scroll { overflow-x: auto; }

/* BUG-426 + FEAT-346: plate links in evidence table */
.ri-plate-link {
    color: #4a9eff;
    text-decoration: none;
    font-weight: 600;
    font-family: monospace;
}
.ri-plate-link:hover { text-decoration: underline; color: #7ab8ff; }
body[data-theme="light"] .ri-plate-link { color: #1a6fc4; }
body[data-theme="light"] .ri-plate-link:hover { color: #1457a0; }
