/* Locus Internal - monochrome admin console.
   Color is reserved for destructive actions and errors. */

:root {
    --bg: #ffffff;
    --bg-raised: #f9fafb;
    --border: #e5e7eb;
    --text: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --red: #dc2626;
    --radius: 6px;
    --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

    --alert-error-bg: #fef2f2;
    --alert-error-text: #b91c1c;
    --alert-error-border: #fecaca;

    --overlay: rgba(17, 24, 39, 0.4);

    /* Chart series colors (validated categorical palette, light surface).
       Fixed per entity: s1 ranked, s2 physics, s3 daily, s4 assignment,
       s5 practice; s6 spare. o1-o4 = ordinal blue ramp (funnel/pipeline). */
    --s1: #2a78d6;
    --s2: #1baf7a;
    --s3: #eda100;
    --s4: #008300;
    --s5: #4a3aa7;
    --s6: #e87ba4;
    --o1: #86b6ef;
    --o2: #5598e7;
    --o3: #2a78d6;
    --o4: #184f95;
}

html.dark {
    --bg: #030712;
    --bg-raised: #0b1120;
    --border: #1f2937;
    --text: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-muted: #6b7280;
    --red: #ef4444;

    --alert-error-bg: #450a0a;
    --alert-error-text: #fca5a5;
    --alert-error-border: #7f1d1d;

    --overlay: rgba(0, 0, 0, 0.6);

    /* Same hues re-stepped for the dark surface (validated separately). */
    --s1: #3987e5;
    --s2: #199e70;
    --s3: #c98500;
    --s4: #008300;
    --s5: #9085e9;
    --s6: #d55181;
    --o1: #9ec5f4;
    --o2: #6da7ec;
    --o3: #3987e5;
    --o4: #256abf;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    font-size: 14px;
}

a { color: inherit; }

.dim { color: var(--text-muted); font-weight: 500; margin-left: 6px; }
.mono { font-family: var(--mono); font-size: 12px; }

/* --- Boot / auth gates ------------------------------------------------- */

.boot {
    padding: 80px 0;
    text-align: center;
    color: var(--text-muted);
}

.gate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.gate-box {
    width: 100%;
    max-width: 340px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.gate-box h1 { font-size: 16px; font-weight: 700; }
.gate-box p { font-size: 13px; }
.gate-box label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

input, textarea, select {
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 7px 9px;
}
input:focus, textarea:focus, select:focus, button:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: -1px;
}
select { font-size: 12px; padding: 3px 6px; cursor: pointer; }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; width: 100%; }

/* --- Buttons ------------------------------------------------------------ */

.btn {
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-raised); border-color: var(--text-muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { font-size: 12px; padding: 3px 9px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover:not(:disabled) { opacity: 0.85; background: var(--text); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover:not(:disabled) { opacity: 0.85; background: var(--red); }
.btn.danger-outline { color: var(--red); border-color: var(--red); }
.btn.danger-outline:hover:not(:disabled) { background: var(--alert-error-bg); }
.btn.load-more { margin-top: 12px; }

.link {
    font: inherit;
    background: none;
    border: none;
    padding: 0;
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--text-muted);
    cursor: pointer;
    text-align: left;
}
.link:hover { text-decoration-color: var(--text); }

/* --- Shell -------------------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
}
.wordmark { font-size: 14px; font-weight: 700; letter-spacing: 0.01em; }
.topnav { display: flex; gap: 4px; }
.topnav a {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 4px;
}
.topnav a:hover { color: var(--text); background: var(--bg-raised); }
.topnav a[aria-current="page"] { color: var(--text); background: var(--bg-raised); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }

.content { padding: 20px; max-width: 1200px; }

/* --- Page chrome ---------------------------------------------------------- */

.page-head {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
}
.page-head h1 { font-size: 15px; font-weight: 700; }

.filters { display: flex; gap: 4px; }
.filter {
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 10px;
    cursor: pointer;
    text-transform: capitalize;
}
.filter:hover { color: var(--text); }
.filter.active { color: var(--bg); background: var(--text); border-color: var(--text); }

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

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
table.data .num { text-align: right; }
table.data .actions { text-align: right; white-space: nowrap; }
table.data .actions .btn { margin-left: 6px; }
tr.row:hover td { background: var(--bg-raised); }
tr.row.resolved td { color: var(--text-muted); }

.cell-trunc {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-trunc.wide { max-width: 340px; }
.cell-trunc .link {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag {
    display: inline-block;
    font-family: var(--mono);
    font-size: 11px;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 6px;
    color: var(--text-secondary);
}
.tag.solid { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Expanded detail row */
tr.detail td { background: var(--bg-raised); padding: 12px 14px; }
.detail-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.detail-label:not(:first-child) { margin-top: 12px; }
.pre {
    font-family: var(--mono);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    background: var(--bg);
    max-height: 260px;
    overflow: auto;
}
.ext {
    display: inline-block;
    margin-top: 8px;
    font-family: var(--mono);
    font-size: 12px;
    word-break: break-all;
}
.reject-box { margin-top: 12px; max-width: 560px; }
.detail-actions { display: flex; gap: 8px; margin-top: 8px; }

/* --- Districts -------------------------------------------------------------- */

.create-form { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.create-form input { font-size: 13px; min-width: 200px; }

.domain-list { list-style: none; max-width: 420px; }
.domain-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}
.domain-add { display: flex; gap: 8px; margin-top: 8px; max-width: 420px; }
.domain-add input { flex: 1; font-family: var(--mono); font-size: 12px; padding: 4px 8px; }
.hint { margin-top: 6px; font-size: 12px; color: var(--text-muted); }

/* --- Stat grid ------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 16px;
}
.stat-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
    padding: 14px 16px;
}
.stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.stat-value {
    font-family: var(--mono);
    font-size: 24px;
    font-weight: 600;
    line-height: 1.2;
    margin-top: 6px;
}
.stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* --- Charts ---------------------------------------------------------------- */

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 28px 0 4px;
}
.section-head h2 { font-size: 13px; font-weight: 700; }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
/* Categorical charts (horizontal bars, donut) need room for label + track +
   value columns - wider minimum so the 1fr bar track doesn't collapse. */
.chart-grid.cats { grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); }
.chart-wide { margin-top: 12px; }

.chart {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
    padding: 12px 14px;
}
.chart-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.chart-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}
.chart-peak { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

.chart-svg {
    display: block;
    width: 100%;
    height: 96px;
    overflow: visible;
}
.chart-wide .chart-svg { height: 130px; }

.chart-svg .bar { fill: var(--text-secondary); }
.chart-svg .bar:hover { fill: var(--text); }
.chart-svg .axis { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }

.chart-x {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-muted);
}

/* Series color hooks - fills, strokes, and HTML backgrounds. */
.fill-s1 { fill: var(--s1); } .fill-s2 { fill: var(--s2); } .fill-s3 { fill: var(--s3); }
.fill-s4 { fill: var(--s4); } .fill-s5 { fill: var(--s5); } .fill-s6 { fill: var(--s6); }
.fill-ink { fill: var(--text-secondary); }
.stroke-s1 { stroke: var(--s1); } .stroke-s2 { stroke: var(--s2); } .stroke-s3 { stroke: var(--s3); }
.stroke-s4 { stroke: var(--s4); } .stroke-s5 { stroke: var(--s5); } .stroke-s6 { stroke: var(--s6); }
.stroke-ink { stroke: var(--text-secondary); }
.bg-s1 { background: var(--s1); } .bg-s2 { background: var(--s2); } .bg-s3 { background: var(--s3); }
.bg-s4 { background: var(--s4); } .bg-s5 { background: var(--s5); } .bg-s6 { background: var(--s6); }
.bg-ink { background: var(--text-secondary); }
.bg-o1 { background: var(--o1); } .bg-o2 { background: var(--o2); }
.bg-o3 { background: var(--o3); } .bg-o4 { background: var(--o4); }

.chart-svg .cbar { fill-opacity: 0.88; }
.chart-svg .cbar:hover { fill-opacity: 1; }

/* Area chart: 2px line (screen px via non-scaling-stroke) + a light wash. */
.chart-svg .area-line {
    fill: none;
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}
.chart-svg .area-fill { fill-opacity: 0.12; }
.chart-svg .hover-col { fill: transparent; }
.chart-svg .hover-col:hover { fill: var(--text); fill-opacity: 0.06; }

/* Legend (multi-series identity channel; carries exact window totals). */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 8px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    flex: none;
}
.legend-name { font-size: 11px; color: var(--text-secondary); }
.legend-value { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

/* Sparkline inside a stat tile. */
.spark { display: block; width: 100%; height: 28px; margin-top: 8px; overflow: visible; }
.spark-line {
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

/* Horizontal bars: label | track | value | detail. */
.hbars { display: flex; flex-direction: column; gap: 6px; }
/* Label/value/detail columns are FIXED-width: each row is its own grid, so a
   per-row auto column would give every row a different track length and make
   the bar widths incomparable. */
.hbar-row {
    display: grid;
    grid-template-columns: minmax(80px, 110px) 1fr 40px 92px;
    align-items: center;
    gap: 8px;
}
.hbar-row.no-detail { grid-template-columns: minmax(80px, 110px) 1fr 40px; }
.hbar-label {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.hbar-track {
    display: block;
    height: 12px;
    border-radius: 3px;
    overflow: hidden;
}
.hbar-fill {
    display: block;
    height: 100%;
    border-radius: 0 3px 3px 0;
    opacity: 0.88;
}
.hbar-row:hover .hbar-fill { opacity: 1; }
.hbar-value {
    font-family: var(--mono);
    font-size: 11px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.hbar-detail {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Donut. */
.donut-body { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-plot { position: relative; width: 132px; flex: none; }
.donut-svg { display: block; width: 100%; transform: rotate(0.001deg); }
.donut-arc {
    fill: none;
    stroke-width: 6;
}
.donut-arc:hover { stroke-width: 7; }
.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.donut-total { font-family: var(--mono); font-size: 18px; font-weight: 600; line-height: 1.1; }
.donut-total-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.donut-legend { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.donut-legend-row { display: flex; align-items: center; gap: 7px; font-size: 12px; }

/* Weekday x hour heatmap: 28px day column + 24 equal hour cells. */
.heatmap {
    display: grid;
    grid-template-columns: 28px repeat(24, 1fr);
    gap: 2px;
    align-items: stretch;
}
.hm-day {
    font-family: var(--mono);
    font-size: 9px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}
.hm-slot { aspect-ratio: 1 / 1; border-radius: 2px; background: var(--bg); overflow: hidden; }
.hm-cell { width: 100%; height: 100%; }
.hm-hours {
    display: flex;
    justify-content: space-between;
    margin: 4px 0 0 30px;
    font-family: var(--mono);
    font-size: 9px;
    color: var(--text-muted);
}

/* Small classroom-adoption tiles ride the standard stat grid. */
.subsection {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 20px 0 0;
}

/* --- States --------------------------------------------------------------- */

.alert {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 10px;
    background: var(--alert-error-bg);
    color: var(--alert-error-text);
    border: 1px solid var(--alert-error-border);
}
.flash {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    background: var(--bg-raised);
}
.loading { color: var(--text-muted); padding: 20px 0; font-size: 13px; }
.empty { color: var(--text-muted); padding: 20px 0; font-size: 13px; }

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

.overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
}
.modal {
    width: 100%;
    max-width: 440px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.modal h2 { font-size: 14px; font-weight: 700; }
.modal p { font-size: 13px; color: var(--text-secondary); }
.modal-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}
.modal-label input { font-family: var(--mono); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; gap: 10px; }
    .content { padding: 14px; }
    .cell-trunc, .cell-trunc.wide { max-width: 140px; }
}
