/* ---------- admin dashboard (js/26-admin.js) ----------
   Same paper-and-ticket language as the student pages: KPI tiles are ticket
   stubs with a dashed tear line, cards are raised paper. Series colors come
   from --chart-1/--chart-2 (validated as a pair in both themes); text never
   wears a series color. */

.adm-note {
    color: var(--text-muted);
    font-size: .85rem;
    margin: 0 0 22px;
    max-width: 70ch;
}

.adm-bar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

#admTabs {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}

/* The page uses the whole screen: the shared 1180px column suits reading, not a dashboard.
   Layout reflows on #admBody's own width (container query), because the sidebar takes
   248px and a viewport query cannot see what is left. Thresholds: 720 (two columns) and
   1100 (twelve-column grid), documented in RESPONSIVE.md. */
/* The id outranks the shell's `:root[data-view="app"] .wrap { max-width: 1240px }`. */
#page-admin > .adm-wrap {
    max-width: 2200px;
    padding-top: 16px;
    padding-bottom: 64px;
}

#admBody {
    container: adm / inline-size;
}

/* ---------- date range picker ---------- */
.adm-range {
    position: relative;
    margin-bottom: 8px;
}

.adm-range-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 7px 12px;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.adm-range-btn:hover,
.adm-range-btn[aria-expanded="true"] {
    border-color: var(--text);
}

.adm-range-text {
    display: flex;
    flex-direction: column;
    font-size: .82rem;
    line-height: 1.3;
}

.adm-range-text small {
    color: var(--text-muted);
    font-size: .72rem;
}

.adm-scrim {
    display: none;
}

.adm-pop {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 60;
    width: min(780px, calc(100vw - 32px));
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.adm-pop[hidden] {
    display: none;
}

.adm-presets {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px;
    border-right: 1px dashed var(--border-strong);
}

.adm-preset {
    background: none;
    border: none;
    border-radius: var(--radius);
    padding: 8px 10px;
    text-align: left;
    font: inherit;
    font-size: .85rem;
    color: var(--text);
    cursor: pointer;
}

.adm-preset:hover {
    background: var(--bg-sunken);
}

.adm-preset.is-on {
    background: var(--text);
    color: var(--bg);
}

.adm-pop-main {
    padding: 14px 16px;
    min-width: 0;
}

.adm-fields {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.adm-fields label,
.adm-cmp label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font: 600 .66rem 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}

.adm-months {
    display: flex;
    gap: 22px;
}

.adm-month {
    flex: 1;
    min-width: 0;
}

.adm-month-head {
    display: grid;
    grid-template-columns: 32px 1fr 32px;
    align-items: center;
    text-align: center;
    margin-bottom: 4px;
    font-size: .88rem;
}

.adm-nav {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.3rem;
    line-height: 1;
    height: 32px;
    border-radius: var(--radius);
    cursor: pointer;
}

.adm-nav:hover {
    background: var(--bg-sunken);
}

.adm-dow,
.adm-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.adm-dow span {
    text-align: center;
    font: 600 .66rem 'IBM Plex Mono', monospace;
    color: var(--text-muted);
    padding: 4px 0;
}

.adm-day {
    background: none;
    border: none;
    border-radius: 0;
    height: 34px;
    font: .8rem 'IBM Plex Mono', monospace;
    color: var(--text);
    cursor: pointer;
}

.adm-day:hover:not(:disabled) {
    background: var(--bg-sunken);
}

.adm-day:disabled {
    color: var(--text-muted);
    opacity: .35;
    cursor: not-allowed;
}

.adm-day.in-range {
    background: color-mix(in srgb, var(--chart-1) 16%, transparent);
}

.adm-day.is-today {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.adm-day.is-start,
.adm-day.is-end {
    background: var(--text);
    color: var(--bg);
    font-weight: 700;
}

.adm-day.is-start { border-radius: var(--radius) 0 0 var(--radius); }
.adm-day.is-end { border-radius: 0 var(--radius) var(--radius) 0; }
.adm-day.is-start.is-end { border-radius: var(--radius); }

.adm-cmp {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 6px 14px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border-strong);
}

.adm-cmp label {
    flex: 0 1 220px;
}

.adm-cmp-range {
    font: .78rem 'IBM Plex Mono', monospace;
    padding-bottom: 8px;
}

.adm-cmp-warn {
    flex-basis: 100%;
    font-size: .74rem;
    color: var(--text-muted);
}

.adm-pop-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

/* ---------- KPI tickets ---------- */
.adm-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.adm-delta {
    font-size: .74rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.adm-delta-pct {
    font: 700 .74rem 'IBM Plex Mono', monospace;
    margin-right: 2px;
}

.adm-delta-pct.is-good { color: var(--success); }
.adm-delta-pct.is-bad { color: var(--danger); }

.adm-kpi {
    position: relative;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-left: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.adm-kpi-label {
    font: 600 .66rem 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
}

.adm-kpi b {
    font-family: 'Big Shoulders Display', sans-serif;
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.adm-kpi b small {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 600;
}

.adm-kpi-sub {
    font-size: .76rem;
    color: var(--text-muted);
}

.adm-live {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--success);
    margin-right: 8px;
    vertical-align: middle;
    animation: adm-pulse 2s ease-in-out infinite;
}

@keyframes adm-pulse {
    50% { opacity: .35; }
}

@media (prefers-reduced-motion: reduce) {
    .adm-live { animation: none; }
}

/* ---------- cards ---------- */
/* Twelve columns. A card names its share of the row (adm-s4, s5, s6, s7, s8); how many
   of those shares apply depends on the width #admBody has been given. */
.adm-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
}

.adm-card {
    grid-column: span 12;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px 20px;
    min-width: 0;
}

@container adm (min-width: 720px) {
    .adm-card { grid-column: span 6; }
    /* wide shares and odd ones out take the full row until there is room for the real split */
    .adm-s5, .adm-s7, .adm-s8, .adm-odd { grid-column: span 12; }
}

@container adm (min-width: 1100px) {
    .adm-s4 { grid-column: span 4; }
    .adm-s5 { grid-column: span 5; }
    .adm-s6 { grid-column: span 6; }
    .adm-s7 { grid-column: span 7; }
    .adm-s8 { grid-column: span 8; }

    .adm-kpis { grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); }
    .adm-log { columns: 2; column-gap: 28px; }
    .adm-log li { break-inside: avoid; }
}

.adm-span {
    grid-column: 1 / -1;
}

.adm-card-head {
    border-bottom: 1px dashed var(--border-strong);
    padding-bottom: 10px;
    margin-bottom: 14px;
}

.adm-card-head h3 {
    margin: 0;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.adm-card-head p {
    margin: 4px 0 0;
    font-size: .82rem;
    color: var(--text-muted);
}

.adm-sample {
    color: var(--gold);
}

.adm-empty {
    color: var(--text-muted);
    font-size: .88rem;
}

.adm-sub {
    display: block;
    font-size: .76rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* ---------- horizontal bars ---------- */
.adm-bars {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.adm-bar {
    display: grid;
    grid-template-columns: minmax(90px, 38%) 1fr auto;
    align-items: center;
    gap: 10px;
    font-size: .84rem;
}

.adm-bars-wide .adm-bar {
    grid-template-columns: minmax(120px, 50%) 1fr auto;
}

.adm-bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.adm-bar-track {
    height: 12px;
    background: var(--bg-sunken);
    border-radius: 2px;
}

.adm-bar-fill {
    display: block;
    height: 100%;
    min-width: 2px;
    background: var(--chart-1);
    border-radius: 0 4px 4px 0;
}

.adm-bar-val {
    font: 600 .8rem 'IBM Plex Mono', monospace;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.adm-bar-val small {
    color: var(--text-muted);
    font-weight: 400;
}

.adm-defs {
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
    font-size: .78rem;
    color: var(--text-muted);
    display: grid;
    gap: 3px;
}

.adm-defs b {
    color: var(--text);
}

/* ---------- SVG charts ---------- */
.adm-chart {
    width: 100%;
    min-height: 200px;
}

.adm-chart svg {
    display: block;
    overflow: visible;
}

.adm-legend {
    display: flex;
    gap: 16px;
    font-size: .8rem;
    margin-bottom: 6px;
}

.adm-legend i {
    display: inline-block;
    width: 14px;
    height: 3px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
}

.adm-legend i.is-dash {
    height: 0;
    border-top: 2px dashed var(--text-muted);
    border-radius: 0;
}

.adm-gridline {
    stroke: var(--border);
    stroke-width: 1;
}

.adm-axis {
    fill: var(--text-muted);
    font: 11px 'IBM Plex Mono', monospace;
}

.adm-end {
    fill: var(--text);
    font: 600 11px 'Public Sans', sans-serif;
}

.adm-line {
    fill: none;
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.adm-line.is-prev {
    stroke-dasharray: 5 4;
    opacity: .55;
}

.adm-area {
    opacity: .14;
}

.adm-marker {
    stroke: var(--text-muted);
    stroke-dasharray: 3 3;
}

.adm-marker-label {
    fill: var(--text-muted);
    font: 600 10px 'IBM Plex Mono', monospace;
    text-transform: uppercase;
}

.adm-cross,
.adm-dot {
    opacity: 0;
}

.adm-cross {
    stroke: var(--text-muted);
}

.adm-dot {
    stroke: var(--bg-raised);
    stroke-width: 2;
}

.adm-hit:hover .adm-cross,
.adm-hit:hover .adm-dot {
    opacity: 1;
}

.adm-hit:hover .adm-col {
    opacity: .8;
}

.adm-tip {
    position: fixed;
    z-index: 400;
    pointer-events: none;
    background: var(--text);
    color: var(--bg);
    font-size: .78rem;
    line-height: 1.45;
    padding: 7px 10px;
    border-radius: var(--radius);
    white-space: pre-line;
    max-width: 280px;
    box-shadow: var(--shadow);
}

/* ---------- ranked key points ---------- */
.adm-rank {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: rank;
}

.adm-rank li {
    counter-increment: rank;
    display: grid;
    grid-template-columns: 22px 1fr auto;
    gap: 10px;
    align-items: start;
    padding: 8px 0;
    border-top: 1px dashed var(--border);
    font-size: .85rem;
}

.adm-rank li:first-child {
    border-top: none;
}

.adm-rank li::before {
    content: counter(rank);
    font: 600 .75rem 'IBM Plex Mono', monospace;
    color: var(--text-muted);
    padding-top: 2px;
}

.adm-rank-text b {
    font-weight: 600;
}

.adm-rank-val {
    font: 700 .85rem 'IBM Plex Mono', monospace;
}

/* ---------- activity log ---------- */
.adm-log {
    margin: 0;
    padding: 0;
    list-style: none;
}

.adm-log li {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 12px;
    padding: 7px 0;
    border-top: 1px dashed var(--border);
    font-size: .85rem;
}

.adm-log li:first-child {
    border-top: none;
}

.adm-log li.is-admin b {
    color: var(--accent);
}

.adm-log-when {
    font: .74rem 'IBM Plex Mono', monospace;
    color: var(--text-muted);
    padding-top: 2px;
}

/* ---------- system health ---------- */
.adm-mini {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
}

.adm-mini .adm-kpi {
    background: var(--bg);
    padding: 10px 12px;
}

.adm-mini .adm-kpi b {
    font-size: 1.4rem;
}

/* ---------- retention heatmap ---------- */
.adm-scroll {
    overflow-x: auto;
}

.adm-heat {
    border-collapse: separate;
    border-spacing: 2px;
    font: .74rem 'IBM Plex Mono', monospace;
    width: 100%;
}

.adm-heat th {
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    white-space: nowrap;
    padding: 4px 6px;
}

.adm-heat td {
    text-align: center;
    padding: 6px 4px;
    border-radius: 2px;
    color: var(--text);
}

.adm-heat td.is-hi {
    color: var(--accent-ink);
}

.adm-heat td.is-empty {
    background: none;
}

.adm-heat .adm-num {
    color: var(--text-muted);
}

/* ---------- account table ---------- */
.adm-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.adm-input {
    font: inherit;
    font-size: .88rem;
    padding: 8px 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
}

.adm-filters input {
    flex: 1 1 220px;
}

.adm-count {
    font: .74rem 'IBM Plex Mono', monospace;
    color: var(--text-muted);
    margin: 0 0 6px;
}

.adm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

.adm-table th {
    text-align: left;
    font: 600 .66rem 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-strong);
}

.adm-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.adm-row {
    cursor: pointer;
}

.adm-row:hover,
.adm-row.is-open {
    background: var(--bg);
}

.adm-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.adm-detail td {
    background: var(--bg);
}

.adm-dl {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px 18px;
    margin: 4px 0;
}

.adm-dl dt {
    font: 600 .64rem 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    color: var(--text-muted);
}

.adm-dl dd {
    margin: 0;
}

.adm-more {
    margin-top: 12px;
}

.adm-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font: 600 .7rem 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    white-space: nowrap;
}

.adm-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.adm-status.is-good { color: var(--success); }
.adm-status.is-info { color: var(--ink-blue); }
.adm-status.is-muted { color: var(--text-muted); }
.adm-status.is-warn { color: var(--gold); }
.adm-status.is-drop { color: var(--danger); }

/* ---------- responsive ---------- */
/* The picker's presets become a wrapping row above a single month. */
@media (max-width: 900px) {
    .adm-pop {
        width: min(440px, calc(100vw - 32px));
        grid-template-columns: minmax(0, 1fr);
    }

    .adm-presets {
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px dashed var(--border-strong);
    }
}

/* On a phone the picker is a bottom sheet, like the other dialogs. */
@media (max-width: 720px) {
    .adm-range {
        width: 100%;
    }

    .adm-range-btn {
        width: 100%;
    }

    .adm-range-btn .adm-range-text {
        flex: 1;
        min-width: 0;
    }

    .adm-scrim:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 90;
        background: rgba(0, 0, 0, .45);
    }

    .adm-pop {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        z-index: 95;
        width: auto;
        max-height: 92dvh;
        overflow-y: auto;
        border-radius: var(--radius) var(--radius) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .adm-day {
        height: 40px;
    }

    .adm-preset {
        padding: 10px 12px;
    }

    .adm-pop .adm-input {
        font-size: 16px;
    }

    .adm-pop-foot .btn {
        flex: 1;
        min-height: 44px;
    }
}

@media (max-width: 720px) {
    .adm-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .adm-kpi b {
        font-size: 1.55rem;
    }

    .adm-card {
        padding: 14px 14px 16px;
    }
}

/* The account table turns into cards: one block per account, labels from data-label. */
@media (max-width: 560px) {
    #admTabs .chip {
        padding: 8px 9px;
        white-space: nowrap;
    }

    .adm-table thead {
        display: none;
    }

    .adm-table,
    .adm-table tbody,
    .adm-table tr,
    .adm-table td {
        display: block;
    }

    .adm-row {
        border-bottom: 1px solid var(--border-strong);
        padding: 6px 0;
    }

    .adm-table td {
        border: none;
        padding: 3px 8px;
    }

    .adm-row td[data-label]:not(:first-child)::before {
        content: attr(data-label) ': ';
        font: 600 .64rem 'IBM Plex Mono', monospace;
        text-transform: uppercase;
        color: var(--text-muted);
    }

    .adm-bar,
    .adm-bars-wide .adm-bar {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .adm-bar-track {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .adm-log li {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }
}

@media (max-width: 400px) {
    .adm-kpi {
        padding: 12px;
    }

    .adm-kpi b {
        font-size: 1.3rem;
    }
}
