:root {
    --bg: #0f1419;
    --panel: #1a1f2b;
    --border: #2a313f;
    --text: #e6edf3;
    --muted: #8b95a5;
    --accent: #4c8bf5;
    --high: #2ea043;
    --medium: #d29922;
    --low: #8b95a5;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.topbar .meta {
    display: flex;
    gap: 1.5rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr)) 2fr;
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}

.kpi {
    background: var(--panel);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.kpi-wide {
    grid-column: span 1;
}

.kpi-label {
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-value {
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-wide .kpi-value {
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1.4;
    white-space: normal;
}

.filters {
    display: flex;
    gap: 1rem;
    align-items: end;
    padding: 1rem 1.5rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.filters label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filters select,
.filters input,
.filters button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.filters button {
    cursor: pointer;
    align-self: end;
}

.filters button:hover {
    background: var(--border);
}

.btn-ghost {
    background: transparent !important;
    color: var(--muted) !important;
    border-color: var(--border) !important;
}

.btn-ghost:hover {
    color: var(--text) !important;
    background: var(--border) !important;
}

.btn-row-hide {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    font-family: inherit;
}

.btn-row-hide:hover {
    color: var(--text);
    background: var(--border);
}

/* Pin the Hide column to the left edge so it stays visible when
   wide rows (e.g. 14-signal leads) force horizontal scroll. */
.col-hide {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
    width: 64px;
    min-width: 64px;
    border-right: 1px solid var(--border);
}

thead .col-hide {
    background: #151a24;
}

tbody tr:hover .col-hide {
    background: #1f2632;
}

/* Wrap the signal-types cell rather than letting it stretch the row
   indefinitely. Cap width so 5+ signals wrap onto multiple lines. */
.signal-types {
    max-width: 320px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.4;
}

main {
    padding: 1rem 1.5rem;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: 6px;
    overflow: hidden;
}

th, td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: #151a24;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

th:hover {
    color: var(--text);
}

tbody tr:hover {
    background: rgba(76, 139, 245, 0.05);
}

.score {
    font-weight: 600;
    color: var(--accent);
}

.confidence-HIGH   { color: var(--high); }
.confidence-MEDIUM { color: var(--medium); }
.confidence-LOW    { color: var(--low); }

.source-link {
    color: var(--accent);
    text-decoration: none;
    margin-right: 0.4rem;
}

.source-link:hover {
    text-decoration: underline;
}

/* TX Cases feed: dim unmatched rows so the operator's eye lands on
   the CAD-resolved ones first, but unmatched stay visible since
   the defendant + case link are still actionable. */
tr.case-unmatched {
    opacity: 0.78;
}

.nav {
    display: flex;
    gap: 1.25rem;
    margin-left: 2rem;
    flex: 1;
}

.nav a {
    color: #ffffff;
    text-decoration: none;
    font-size: 1.05rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-bottom: 3px;
    border-bottom: 2px solid transparent;
}

.nav a:hover { color: var(--accent); }

.nav a.active {
    color: #ffffff;
    border-bottom-color: var(--accent);
    font-weight: 600;
}

main.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
}

.stats-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem 1.25rem;
}

.stats-section.full { grid-column: 1 / -1; }

.stats-section h2 {
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.stats-section .stats-help {
    margin: 0 0 0.75rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.stats-section table {
    border-radius: 4px;
}

.stats-section td.num,
.stats-section th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.stats-section td.empty {
    color: var(--muted);
    font-style: italic;
    text-align: center;
}

.status-success { color: var(--high); }
.status-failed  { color: #f85149; }
.status-running { color: var(--medium); }

.breaker-closed   { color: var(--high); font-weight: 600; }
.breaker-open     { color: #f85149; font-weight: 600; }
.breaker-half_open { color: var(--medium); font-weight: 600; }

.log-tail {
    background: #0c1018;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin: 0;
    color: var(--text);
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    max-height: 540px;
    overflow: auto;
    white-space: pre;
}

@media (max-width: 900px) {
    main.stats { grid-template-columns: 1fr; }
}

/* ---- Auth: logged-in user box + logout ------------------------------ */
.user-box {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto;
}
.user-box .user-name {
    color: var(--muted);
    font-size: 0.85rem;
}

/* ---- Login page ----------------------------------------------------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    /* Subtle depth behind the card: an accent-tinted glow over the flat
       dashboard background. */
    background:
        radial-gradient(1100px 520px at 50% -10%,
            rgba(76, 139, 245, 0.14), transparent 60%),
        var(--bg);
}
.login-card {
    background: linear-gradient(180deg,
        rgba(255, 255, 255, 0.03), transparent 120px), var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.25rem 2.25rem 1.75rem;
    width: 360px;
    max-width: 100%;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.04) inset,
        0 18px 50px rgba(0, 0, 0, 0.45);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.login-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex: none;
    border-radius: 10px;
    color: #fff;
    background: linear-gradient(160deg, var(--accent), #2f63c4);
    box-shadow: 0 6px 16px rgba(76, 139, 245, 0.35);
}
.login-titles h1 { font-size: 1.05rem; margin: 0; letter-spacing: 0.2px; }
.login-sub { color: var(--muted); margin: 0.15rem 0 0; font-size: 0.82rem; }
.login-card label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 1rem;
}
.login-card input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 0.6rem 0.7rem;
    font-size: 0.95rem;
    text-transform: none;
    letter-spacing: normal;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input::placeholder { color: #5a6473; }
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.18);
}
.login-card button {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.65rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.35rem;
    transition: background 0.15s, transform 0.05s;
}
.login-card button:hover { background: #3f7ae8; }
.login-card button:active { transform: translateY(1px); }
.login-card button:disabled { opacity: 0.6; cursor: default; }
.login-error {
    color: var(--medium);
    font-size: 0.82rem;
    min-height: 1.1rem;
    margin: 0.7rem 0 0;
    text-align: center;
}
.login-foot {
    color: #586173;
    font-size: 0.72rem;
    text-align: center;
    margin: 1.4rem 0 0;
    letter-spacing: 0.3px;
}

/* ---- Multi-select + saved views (filter bar widgets) ---------------- */
.filter-ms, .saved-views {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
}
.saved-views {
    flex-direction: row;
    align-items: flex-end;
    gap: 0.4rem;
}
.ms { position: relative; }
.ms-label { font-size: 0.8rem; color: var(--muted); }
.ms-button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    min-width: 130px;
    text-align: left;
    cursor: pointer;
}
.ms-panel {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    margin-top: 2px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem;
    min-width: 160px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.ms-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.35rem;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.ms-option:hover { background: var(--border); border-radius: 3px; }
.sv-select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    padding: 0.4rem 0.5rem;
    min-width: 130px;
}

/* ---- CSV export (filter bar widget) --------------------------------- */
.csv-export {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
}
.csv-wrap { position: relative; }
.csv-button { cursor: pointer; }
.csv-panel {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 20;
    margin-top: 2px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem;
    min-width: 160px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.csv-panel[hidden] { display: none; }
.csv-item {
    background: transparent;
    border: none;
    color: var(--text);
    text-align: left;
    padding: 0.4rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}
.csv-item:hover { background: var(--border); }
