/* public/style.css — dark glass.
 *
 * Hand-written rather than Tailwind: the admin is served as three static files
 * with no build step, and the CSP on /admin is script-src 'self'. A CDN build
 * would mean either adding a toolchain or punching a hole in that, and neither
 * buys anything a stylesheet cannot do.
 *
 * The glass is three layers that have to agree: a translucent fill, a blurred
 * backdrop, and a one-pixel inner highlight along the top edge. Drop the
 * highlight and the panels look like flat grey boxes; drop the blur and the
 * background bleeds through as noise.
 */

:root {
    --bg: #080a12;
    --text: #e9ecf5;
    --muted: #8e97b0;
    --faint: #5a6480;

    --glass: rgba(255, 255, 255, .045);
    --glass-2: rgba(255, 255, 255, .075);
    --edge: rgba(255, 255, 255, .09);
    --edge-soft: rgba(255, 255, 255, .055);
    --highlight: rgba(255, 255, 255, .14);

    --accent: #6d8bff;
    --accent-2: #a46bff;
    --ok: #3ad29f;
    --warn: #f0b544;
    --danger: #ff6b6b;

    --r-lg: 20px;
    --r-md: 14px;
    --r-sm: 10px;

    --shadow: 0 18px 50px -18px rgba(0, 0, 0, .75);
    --blur: blur(22px) saturate(150%);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Colour behind the glass. Fixed, so scrolling moves the content across the
 * light rather than dragging the light along with it. */
body::before {
    content: '';
    position: fixed;
    inset: -20vmax;
    z-index: -1;
    /* Two blobs, both near the top. The green one sat at 72%/92% — bottom right,
     * under the content, where it read as a stain on the screen rather than
     * light behind the glass. */
    background:
        radial-gradient(42vmax 42vmax at 12% -8%, rgba(109, 139, 255, .28), transparent 60%),
        radial-gradient(38vmax 38vmax at 88% 2%, rgba(164, 107, 255, .22), transparent 62%);
    filter: blur(14px);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }

/* ── the glass surface ───────────────────────────────────────────────────── */

.glass {
    background: var(--glass);
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow), inset 0 1px 0 var(--highlight);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
}

/* Without backdrop-filter the translucent fill just looks washed out, so give
 * those browsers something solid instead of something broken. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass, header, .toast, .modal { background: #141828; }
}

/* ── header ──────────────────────────────────────────────────────────────── */

header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 12px 22px;
    background: rgba(10, 13, 24, .62);
    border-bottom: 1px solid var(--edge-soft);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    letter-spacing: .2px;
    font-size: 15px;
}

.brand-mark {
    width: 24px; height: 24px; flex: none;
    filter: drop-shadow(0 0 10px rgba(109, 139, 255, .55));
}

/* ── segmented controls ──────────────────────────────────────────────────
 * One pill that travels between options instead of each option lighting up.
 * The pill is a separate element so it can be animated; the options themselves
 * only change colour. */

nav, .subtabs {
    position: relative;
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--edge-soft);
    isolation: isolate;
}

.seg-slider {
    position: absolute;
    left: 0;
    top: 3px;
    bottom: 3px;
    width: 0;
    z-index: -1;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(109, 139, 255, .34), rgba(164, 107, 255, .28));
    border: 1px solid rgba(154, 174, 255, .42);
    box-shadow: inset 0 1px 0 var(--highlight), 0 6px 18px -8px rgba(109, 139, 255, .85);
    opacity: 0;
    /* Overshoot on the way in, so the pill settles rather than stops — the
     * stretch comes from the width travelling on a slightly slower curve. */
    transition: transform .34s cubic-bezier(.34, 1.26, .5, 1),
                width .42s cubic-bezier(.34, 1.1, .4, 1),
                opacity .2s;
}
.seg-ready .seg-slider { opacity: 1; }

.tab, .subtab, .seg-btn {
    position: relative;
    display: inline-block;
    padding: 7px 15px;
    border: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: color .22s;
}

.tab:hover, .subtab:hover, .seg-btn:hover { color: var(--text); background: transparent; filter: none; }
.tab.active, .subtab.active, .seg-btn.active { color: #fff; }

@media (prefers-reduced-motion: reduce) {
    .seg-slider { transition: opacity .2s; }
}

main {
    padding: 24px 26px 60px;
    /* Wide on purpose: the campaigns table has seven columns, one of them a list
     * of links, and squeezing that into 1400px was costing a line wrap per row. */
    max-width: 1860px;
    margin: 0 auto;
}

/* ── headings and panels ─────────────────────────────────────────────────── */

h1 { font-size: 20px; margin: 0 0 4px; font-weight: 700; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 0 0 14px; font-weight: 650; letter-spacing: -.1px; }
h3 { font-size: 14px; margin: 0 0 6px; font-weight: 650; }

.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.panel {
    background: var(--glass);
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow), inset 0 1px 0 var(--highlight);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    padding: 18px 20px;
    margin-bottom: 18px;
}

.panel.flush { padding: 0; overflow: hidden; }
.panel > h3 + p { margin-top: 0; }
.panel p { color: var(--muted); font-size: 13px; }

/* ── controls ────────────────────────────────────────────────────────────── */

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row + .row { margin-top: 12px; }
.toolbar { margin-bottom: 16px; }

label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--faint);
    font-weight: 600;
}

input, select, textarea {
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--edge);
    color: var(--text);
    padding: 9px 11px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    min-width: 0;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

input::placeholder { color: #4d5775; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(109, 139, 255, .65);
    background: rgba(255, 255, 255, .07);
    box-shadow: 0 0 0 3px rgba(109, 139, 255, .16);
}

select { appearance: none; padding-right: 30px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238e97b0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 11px center; }

input[type=date] { color-scheme: dark; }

button {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    border: 1px solid rgba(154, 174, 255, .35);
    padding: 9px 16px;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 650;
    font-family: inherit;
    box-shadow: 0 8px 22px -12px rgba(109, 139, 255, .95), inset 0 1px 0 var(--highlight);
    transition: transform .12s, filter .15s, opacity .15s;
}

button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .42; cursor: not-allowed; filter: none; }

button.ghost {
    background: rgba(255, 255, 255, .055);
    color: var(--text);
    border: 1px solid var(--edge);
    box-shadow: inset 0 1px 0 var(--edge-soft);
}
button.ghost:hover { background: rgba(255, 255, 255, .1); }

button.danger {
    background: rgba(255, 107, 107, .12);
    color: var(--danger);
    border-color: rgba(255, 107, 107, .3);
    box-shadow: none;
}
button.danger:hover { background: rgba(255, 107, 107, .2); }

button.small { padding: 5px 10px; font-size: 12px; border-radius: 8px; }

/* ── tables ──────────────────────────────────────────────────────────────── */

.table-wrap {
    background: var(--glass);
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow), inset 0 1px 0 var(--highlight);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    /* auto, not hidden: a wide table on a narrow screen has to be scrollable
     * sideways rather than simply cut off. Rounded corners still clip. */
    overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }

th, td {
    text-align: left;
    padding: 11px 14px;
    border-bottom: 1px solid var(--edge-soft);
    vertical-align: middle;
}

/* Deliberately NOT position:sticky.
 *
 * .table-wrap carries overflow:hidden to clip the rounded corners, and an
 * overflow container is also a scroll container: a sticky th then pins itself to
 * the bottom edge of that short box, which lands it exactly on top of the first
 * data row. Keeping the corners is worth more than a floating header. */
th {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--faint);
    font-weight: 700;
    background: rgba(255, 255, 255, .03);
    white-space: nowrap;
}

th.sortable { cursor: pointer; user-select: none; transition: color .15s; }
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--text); }
th .arrow { opacity: .85; margin-left: 4px; font-size: 9px; }

tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255, 255, 255, .035); }
tbody tr:last-child td { border-bottom: 0; }

td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 6px; }

.empty { padding: 34px 16px; text-align: center; color: var(--faint); }

/* ── small pieces ────────────────────────────────────────────────────────── */

.pill {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .3px;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.pill.active { background: rgba(58, 210, 159, .14); color: var(--ok); border-color: rgba(58, 210, 159, .28); }
.pill.burned, .pill.archived, .pill.paused { background: rgba(255, 107, 107, .13); color: var(--danger); border-color: rgba(255, 107, 107, .26); }
.pill.primary { background: rgba(109, 139, 255, .18); color: #a8b9ff; border-color: rgba(109, 139, 255, .36); }

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: #b3c0e8;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.chip {
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--edge-soft);
    border-radius: 7px;
    padding: 1px 8px;
    font-size: 11px;
    color: var(--muted);
}

a.link {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: #a8b9ff;
    text-decoration: none;
    border-bottom: 1px dashed rgba(168, 185, 255, .35);
}
a.link:hover { color: #cfd9ff; border-bottom-style: solid; }

.link-row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.link-row + .link-row { margin-top: 6px; }

/* ── stats ───────────────────────────────────────────────────────────────── */

/* Compact on purpose: five numbers do not need a third of the screen. */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; margin-bottom: 14px; }

.stat {
    background: var(--glass);
    border: 1px solid var(--edge);
    border-radius: var(--r-sm);
    box-shadow: inset 0 1px 0 var(--highlight);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    padding: 9px 12px 10px;
    position: relative;
    overflow: hidden;
}
.stat::after {
    content: '';
    position: absolute; inset: 0 auto 0 0; width: 3px;
    background: linear-gradient(180deg, var(--accent), var(--accent-2));
    opacity: .75;
}
.stat b {
    display: block;
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.3px;
    line-height: 1.2;
}
.stat span {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--faint);
    font-weight: 600;
}
.stat i { font-size: 10px; margin-top: 1px; }
.stat::after { width: 2px; }

.stat i {
    display: block;
    margin-top: 3px;
    font-style: normal;
    font-size: 11px;
    color: var(--faint);
}

.chart { padding: 14px 16px 12px; }
.chart-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.chart-head h3 { margin: 0; }
.chart-head span { margin-left: auto; font-size: 12px; }
.empty-chart { min-height: 150px; display: flex; align-items: center; justify-content: center; }

/* Scrolls sideways on a narrow screen instead of squashing: a chart compressed
 * to 340px is not a smaller chart, it is an unreadable one. */
.chart-box { overflow-x: auto; position: relative; }

.chart-tip {
    position: absolute;
    pointer-events: none;
    z-index: 3;
    min-width: 150px;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    background: rgba(14, 18, 32, .94);
    border: 1px solid var(--edge);
    box-shadow: var(--shadow);
    font-size: 12px;
    transform: translate(-50%, -100%);
}
.chart-tip.hidden { display: none; }
.chart-tip h4 { margin: 0 0 6px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.chart-tip .tip-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.chart-tip .tip-total { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--edge-soft); }

.device-share { padding: 14px 16px 16px; }
.stackbar {
    display: flex;
    height: 14px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, .05);
    box-shadow: inset 0 1px 0 var(--edge-soft);
}
.stackbar i { display: block; height: 100%; transition: width .2s; }
.stackbar i + i { box-shadow: inset 1px 0 0 rgba(8, 10, 18, .5); }

.device-rows { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 12px; }
.device-row { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; }
.device-row b { font-weight: 600; }
.device-pct { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

.pie-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.pie-wrap svg { width: 300px; height: 300px; flex: none; }
.pie-legend { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 7px; }
.pie-legend .legend-item { justify-content: flex-start; width: 100%; }
.pie-legend .legend-item b { flex: 1; }

.bulkbar {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 12px; padding: 10px 14px;
    border-radius: var(--r-sm);
    background: rgba(109, 139, 255, .12);
    border: 1px solid rgba(154, 174, 255, .35);
    font-size: 13px;
}
td.pick, th.pick { width: 34px; text-align: center; padding-right: 0; }
tbody tr.picked { background: rgba(109, 139, 255, .10); }
tbody tr.picked:hover { background: rgba(109, 139, 255, .16); }
input[type=checkbox] { width: 15px; height: 15px; accent-color: #6d8bff; cursor: pointer; }
/* height:auto with a wide viewBox: the drawing keeps its proportions and fills
 * the panel instead of sitting letterboxed in the middle of it. */
.chart-svg { display: block; width: 100%; min-width: 680px; height: auto; max-height: 420px; }

.subtabs { margin-bottom: 14px; }
.subtabs.tight { margin-bottom: 10px; }
.subtabs .seg-btn { padding: 6px 16px; font-size: 12.5px; }

.modal-backdrop {
    position: fixed; inset: 0; z-index: 60;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: rgba(4, 6, 14, .62);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fade .15s ease-out;
}
.modal {
    width: min(760px, 100%);
    max-height: 86vh;
    overflow-y: auto;
    padding: 22px 24px 20px;
    background: rgba(18, 22, 38, .92);
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow), inset 0 1px 0 var(--highlight);
    animation: pop .16s ease-out;
}
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.modal-head button { margin-left: auto; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

td.ref { max-width: 220px; }

.guide summary { font-weight: 600; color: var(--text); font-size: 13px; }
.guide-steps { margin: 14px 0 6px; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.guide-steps li { font-size: 13px; }
.guide-steps li b { font-weight: 650; }
.guide-steps li div { margin-top: 2px; font-size: 12.5px; line-height: 1.5; }
.guide > p { margin: 10px 0 0; font-size: 12.5px; }

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px 14px;
    margin-top: 12px;
}
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 14px; margin-top: 12px; }
.check { flex-direction: row; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0;
    font-size: 13px; color: var(--text); font-weight: 500; cursor: pointer; }

.chip-on { display: inline-flex; align-items: center; gap: 6px; background: rgba(109, 139, 255, .16);
    border-color: rgba(154, 174, 255, .4); color: var(--text); padding: 3px 6px 3px 10px; }
.chip-x { background: none; border: 0; box-shadow: none; color: var(--muted); padding: 0 2px;
    font-size: 11px; cursor: pointer; }
.chip-x:hover { color: var(--text); filter: none; }

.gone { color: var(--muted); }
.gone-tag { margin-left: 6px; font-size: 10.5px; color: var(--faint); }

.kv-list { display: grid; grid-template-columns: max-content 1fr; gap: 5px 16px; font-size: 13px; }
.kv { display: contents; }
.kv span { color: var(--faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; padding-top: 2px; }
.kv b { font-weight: 500; word-break: break-word; }
.raw-ua { display: block; margin-top: 8px; word-break: break-all; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; }
.legend-item b { font-weight: 600; }

.swatch {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 3px;
    margin-right: 7px;
    vertical-align: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.legend-item .swatch { margin-right: 0; }

.flag { margin-right: 8px; font-size: 15px; line-height: 1; }
.dim-name { white-space: nowrap; }
.bar-cell { width: 42%; min-width: 90px; }

.edit-panel h3 code { font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }

.bar-wrap { background: rgba(255, 255, 255, .06); border-radius: 999px; width: 100%; height: 7px; overflow: hidden; }
.bar { height: 7px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ── login ───────────────────────────────────────────────────────────────── */

.login {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px; position: relative; overflow: hidden;
}

/* Three slow blobs behind the glass. The card is translucent, so the colour has
 * to move for it to read as glass rather than as a grey panel. */
.login-aurora { position: absolute; inset: -30vmax; z-index: 0; filter: blur(70px); }
.login-aurora i {
    position: absolute; display: block; border-radius: 50%; opacity: .55;
    animation: drift 26s ease-in-out infinite;
}
.login-aurora i:nth-child(1) {
    width: 46vmax; height: 46vmax; left: 8%; top: 6%;
    background: radial-gradient(circle, rgba(109, 139, 255, .95), transparent 62%);
}
.login-aurora i:nth-child(2) {
    width: 40vmax; height: 40vmax; right: 6%; top: 18%;
    background: radial-gradient(circle, rgba(164, 107, 255, .85), transparent 62%);
    animation-duration: 34s; animation-direction: reverse;
}
.login-aurora i:nth-child(3) {
    width: 34vmax; height: 34vmax; left: 34%; bottom: 2%;
    background: radial-gradient(circle, rgba(58, 210, 159, .55), transparent 62%);
    animation-duration: 42s; animation-delay: -8s;
}
@keyframes drift {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(6vmax, -4vmax) scale(1.12); }
    66% { transform: translate(-5vmax, 5vmax) scale(.93); }
}
@media (prefers-reduced-motion: reduce) { .login-aurora i { animation: none; } }

.login-card {
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, .055);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 26px;
    box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .9), inset 0 1px 0 rgba(255, 255, 255, .22);
    backdrop-filter: blur(26px) saturate(160%);
    -webkit-backdrop-filter: blur(26px) saturate(160%);
    padding: 36px 34px 28px;
    width: 370px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}
/* The sheen that makes glass look like glass: a highlight slowly crossing it. */
.login-card::before {
    content: '';
    position: absolute;
    inset: -60% -120%;
    background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, .13) 48%, transparent 58%);
    animation: sheen 7s linear infinite;
    pointer-events: none;
}
@keyframes sheen { from { transform: translateX(-30%); } to { transform: translateX(30%); } }
@media (prefers-reduced-motion: reduce) { .login-card::before { animation: none; } }

.login-mark { display: block; width: 46px; height: 46px; margin-bottom: 4px; }
.login-mark svg { width: 100%; height: 100%; filter: drop-shadow(0 0 16px rgba(109, 139, 255, .6)); }

.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.login-card > p { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.login-card input {
    padding: 13px 15px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    letter-spacing: .5px;
    background: rgba(255, 255, 255, .07);
}
.login-card button { margin-top: 2px; padding: 12px; font-size: 14px; }
.login-note { margin: 2px 0 0 !important; font-size: 11.5px; color: var(--faint) !important; }
.error { color: var(--danger); font-size: 12px; min-height: 16px; margin: 0; }

input.bad, select.bad, textarea.bad {
    border-color: rgba(255, 107, 107, .65);
    background: rgba(255, 107, 107, .07);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, .14);
}
/* Above the field and out of the flow: in the flow it made the row taller and
 * knocked every neighbouring field out of line. */
label.has-err { position: relative; }
.field-err {
    position: absolute;
    bottom: calc(100% + 2px);
    left: 0;
    z-index: 5;
    white-space: nowrap;
    padding: 4px 9px;
    border-radius: 7px;
    background: rgba(255, 107, 107, .16);
    border: 1px solid rgba(255, 107, 107, .45);
    box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .2px;
    text-transform: none;
    color: #ffb3b3;
    animation: rise .16s ease-out;
}
.field-err::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 12px;
    border: 4px solid transparent;
    border-top-color: rgba(255, 107, 107, .45);
}
label.has-err > span:first-child { color: var(--danger); }

/* ── toast ───────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(18, 22, 38, .82);
    border: 1px solid var(--edge);
    box-shadow: var(--shadow), inset 0 1px 0 var(--highlight);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    padding: 11px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    z-index: 40;
    max-width: 80vw;
    animation: rise .22s ease-out;
}
.toast.bad { border-color: rgba(255, 107, 107, .45); color: #ffb3b3; }

@keyframes rise {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ── misc ────────────────────────────────────────────────────────────────── */

details > summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.spin { display: inline-block; width: 13px; height: 13px; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .2); border-top-color: var(--accent);
    animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 1100px) {
    main { padding: 18px 16px 50px; }
}

@media (max-width: 860px) {
    header { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
    .brand { font-size: 14px; }
    nav {
        order: 3; width: 100%; border-radius: var(--r-md);
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    nav::-webkit-scrollbar { display: none; }
    .tab { padding: 8px 13px; }

    main { padding: 14px 12px 60px; }
    h1 { font-size: 18px; }
    .page-head { flex-direction: column; align-items: flex-start; gap: 4px; }

    /* Controls stack and go full width: a 90px-wide date field on a phone is a
     * field you cannot read what you typed into. */
    .row { gap: 8px; }
    .row > label { flex: 1 1 150px; }
    .row > label input, .row > label select { width: 100%; }
    .toolbar .spacer { display: none; }

    .cards { grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
    .stat { padding: 13px 14px; }
    .stat b { font-size: 22px; }

    .panel { padding: 14px 14px; border-radius: var(--r-md); }
    .grid2 { gap: 12px; }

    /* Tables keep their shape and scroll, rather than wrapping every cell into
     * an unreadable column of fragments. */
    .table-wrap { border-radius: var(--r-md); }
    th, td { padding: 9px 10px; }
    td.actions { white-space: nowrap; }
    td.actions button + button { margin-left: 4px; }
}

@media (max-width: 520px) {
    .legend { gap: 6px 12px; }
    .modal { padding: 16px 14px; border-radius: var(--r-md); max-height: 92vh; }
    .modal-backdrop { padding: 8px; }
}
th.num { text-align: right; }
