/* ---------------------------------------------------------------------------
   PBX Scoreboard
   Hand-written and served straight from public/, so deploying the app to the
   Alma server needs PHP only - no Node, no build step, no asset pipeline.
   --------------------------------------------------------------------------- */

:root {
    color-scheme: light;

    --surface-0: #f2f3f5;
    --surface-1: #fcfcfb;
    --surface-2: #f7f7f5;
    --surface-3: #eeeeeb;

    --border: #e2e2de;
    --border-strong: #cfcfc9;

    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #86857f;
    --text-invert: #ffffff;

    --accent: #1c5cab;
    --accent-soft: #eaf1fb;

    /* Categorical slots 1 and 2 from the validated palette.
       Outbound = blue, inbound = orange. Fixed by series, never by rank. */
    --series-outbound: #2a78d6;
    --series-inbound: #eb6834;

    --good: #1a7f4b;
    --good-soft: #e6f4ec;
    --warn: #8a6100;
    --warn-soft: #fdf3e3;
    --bad: #b4443a;
    --bad-soft: #fbeceb;

    --grid: #ececE8;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --surface-0: #121211;
        --surface-1: #1a1a19;
        --surface-2: #212120;
        --surface-3: #2a2a28;

        --border: #33332f;
        --border-strong: #45443f;

        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #8d8c83;
        --text-invert: #101010;

        --accent: #6da7ec;
        --accent-soft: #1d2a3d;

        /* The same two hues, re-stepped for the dark surface. */
        --series-outbound: #3987e5;
        --series-inbound: #d95926;

        --good: #4bb47c;
        --good-soft: #16281e;
        --warn: #d9a441;
        --warn-soft: #2b2314;
        --bad: #e66767;
        --bad-soft: #2e1a1a;

        --grid: #2c2c29;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    }
}

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

body {
    margin: 0;
    background: var(--surface-0);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }

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

.topbar {
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar__inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 22px;
    min-height: 56px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 650;
    font-size: 15px;
    color: var(--text-primary);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand__dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--series-outbound);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.nav a {
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}
.nav a:hover { background: var(--surface-3); color: var(--text-primary); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px 20px 56px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.page-head p { margin: 3px 0 0; color: var(--text-secondary); font-size: 13px; }

/* --- Cards ---------------------------------------------------------------- */

.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}
.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }
.card__hint { color: var(--text-muted); font-size: 12px; font-weight: 400; }

/* --- Stat tiles ----------------------------------------------------------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.tile {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.tile__label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    font-weight: 600;
}
.tile__value {
    font-size: 25px;
    font-weight: 650;
    letter-spacing: -0.02em;
    margin: 5px 0 3px;
    font-variant-numeric: tabular-nums;
}
.tile__foot { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

/* The tile's accent stripe names the series; the number itself stays ink. */
.tile--outbound { border-top: 3px solid var(--series-outbound); }
.tile--inbound { border-top: 3px solid var(--series-inbound); }

.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta--up { color: var(--good); }
.delta--down { color: var(--bad); }
.delta--flat { color: var(--text-muted); }

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

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data th, table.data td {
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data th {
    background: var(--surface-2);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    font-weight: 600;
    position: sticky;
    top: 0;
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td {
    font-weight: 650;
    background: var(--surface-2);
    border-top: 2px solid var(--border-strong);
    border-bottom: none;
}
table.data .muted { color: var(--text-muted); font-weight: 400; }

/* Sortable column headings. The whole cell is the target, so the click area
   matches what looks clickable. */
table.data th a.sort {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    white-space: nowrap;
}
table.data th a.sort:hover { color: var(--text-primary); text-decoration: none; }
table.data th a.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
table.data th a.sort--active { color: var(--accent); }
.sort__mark { font-size: 9px; line-height: 1; }
/* Reserve the arrow's width on every heading so columns do not jump when the
   sort moves between them. */
table.data th a.sort .sort__mark { min-width: 7px; display: inline-block; }

.ext-link { font-weight: 600; }
.ext-name { color: var(--text-secondary); font-weight: 400; }

/* Inline magnitude bar behind a table figure. Sequential, single hue. */
.meter {
    display: block;
    height: 3px;
    margin-top: 4px;
    border-radius: 2px;
    background: var(--series-outbound);
    opacity: .85;
    min-width: 2px;
}
.meter--inbound { background: var(--series-inbound); }

/* --- Hourly volume chart -------------------------------------------------- */

.chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;                 /* 2px surface gap between hour bands */
    height: 168px;
    padding: 8px 2px 0;
    position: relative;
    border-bottom: 1px solid var(--border-strong);
}

/* Recessive baseline grid, drawn behind the marks. */
.chart::before {
    content: "";
    position: absolute;
    inset: 8px 0 0;
    background-image: repeating-linear-gradient(
        to top,
        var(--grid) 0 1px,
        transparent 1px 25%
    );
    pointer-events: none;
}

.chart__band {
    flex: 1 1 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 2px;                 /* 2px gap between the two adjacent bars */
    height: 100%;
    position: relative;
    min-width: 0;
}
.chart__band:hover { background: var(--surface-2); }

.chart__bar {
    width: 100%;
    max-width: 11px;          /* thin marks; never fills the band */
    /* 4px rounded data-end, square at the baseline. */
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    position: relative;
    z-index: 1;
}
.chart__bar--outbound { background: var(--series-outbound); }
.chart__bar--inbound { background: var(--series-inbound); }
.chart__bar--empty { background: var(--grid); min-height: 2px; border-radius: 2px; }

.chart__tip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(16, 24, 40, .16);
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.45;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity .1s ease;
    z-index: 5;
    pointer-events: none;
}
.chart__band:hover .chart__tip,
.chart__band:focus-within .chart__tip { opacity: 1; visibility: visible; }
.chart__tip strong { display: block; margin-bottom: 3px; color: var(--text-primary); }
.chart__tip span { color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }

.chart-axis {
    display: flex;
    gap: 2px;
    padding: 5px 2px 0;
}
.chart-axis span {
    flex: 1 1 0;
    text-align: center;
    font-size: 10px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 0;
    overflow: hidden;
}

.legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-secondary);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.swatch {
    width: 10px; height: 10px;
    border-radius: 3px;
    flex: none;
}
.swatch--outbound { background: var(--series-outbound); }
.swatch--inbound { background: var(--series-inbound); }

/* --- Live panel ----------------------------------------------------------- */

.live-list { display: flex; flex-direction: column; }
.live-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}
.live-row:last-child { border-bottom: none; }
.live-row__who { font-weight: 600; min-width: 74px; }
.live-row__peer {
    color: var(--text-secondary);
    font-family: var(--mono);
    font-size: 12px;
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 7px;
    min-width: 0;
    flex-wrap: wrap;
}

/* "dialled" / "from" — says which number is being shown, where an arrow
   alone would leave the reader guessing. */
.live-row__dir {
    font-family: var(--font);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    flex: none;
}
.live-row__name {
    font-family: var(--font);
    color: var(--text-primary);
    font-size: 12px;
}
.live-row__country {
    font-family: var(--font);
    font-size: 11px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 7px;
    flex: none;
}
.live-row__time { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 12px; }

.pulse {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--good);
    flex: none;
    animation: pulse 2s ease-in-out infinite;
}
.pulse--ringing { background: var(--warn); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.empty {
    padding: 26px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* --- Badges, banners, buttons --------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
}
.badge--good { background: var(--good-soft); color: var(--good); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--bad { background: var(--bad-soft); color: var(--bad); }
.badge--neutral { background: var(--surface-3); color: var(--text-secondary); }

.banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.banner--warn { background: var(--warn-soft); color: var(--warn); border-color: currentColor; }
.banner--bad { background: var(--bad-soft); color: var(--bad); border-color: currentColor; }
.banner--good { background: var(--good-soft); color: var(--good); border-color: currentColor; }
.banner strong { font-weight: 650; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}
.btn--primary:hover { filter: brightness(1.08); }
.btn--danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn--sm { padding: 4px 9px; font-size: 12px; }

/* --- Forms ---------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], select, textarea {
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    width: 100%;
}
textarea { resize: vertical; min-height: 54px; line-height: 1.5; }

input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.filters {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}
.filters .field { min-width: 150px; }

.error { color: var(--bad); font-size: 12px; margin-top: 4px; }

/* --- Auth ----------------------------------------------------------------- */

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.auth__card {
    width: 100%;
    max-width: 380px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}
.auth__card h1 { margin-bottom: 4px; }
.auth__card p { margin: 0 0 20px; color: var(--text-secondary); font-size: 13px; }
.auth__card .field { margin-bottom: 14px; }

/* --- Utilities ------------------------------------------------------------ */

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.pagination { display: flex; gap: 4px; padding: 12px 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 4px 9px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}
.pagination .active { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 720px) {
    .page { padding: 14px 12px 40px; }
    .tile__value { font-size: 21px; }
    .chart { height: 132px; }
}
