/* ── Tokens ────────────────────────────────────────────────────────────── */
/* Light is the base. The dark and glass themes below override only colour -
   never geometry - so a theme switch can never reflow the page. */
:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --line: #e4e1d9;
  --hair: #efece6;
  --ink: #1c221f;
  --ink-2: #4d534f;
  --muted: #8b908c;
  --accent: #1f5a3e;
  --accent-soft: #eaf2ed;
  --gold: #c8a64c;
  --danger: #a8342b;
  --field: #fbfaf8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  --radius: 16px;
  --radius-sm: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  --t: 140ms cubic-bezier(.2, .8, .2, 1);
}

/* ── Theme: dark ───────────────────────────────────────────────────────── */
/* A flat dark theme, no translucency. This is the one to pick if glass
   stutters on a phone - it costs the GPU nothing. */
[data-theme="dark"] {
  --bg: #14181a;
  --card: #1c2124;
  --line: #2c3338;
  --hair: #242a2e;
  --ink: #eef1f0;
  --ink-2: #b3bbb8;
  --muted: #7f8886;
  --accent: #4aa87a;
  --accent-soft: #1d3329;
  --gold: #d8b661;
  --danger: #e0695e;
  --field: #171c1f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

/* ── Theme: glass ──────────────────────────────────────────────────────── */
/* Surfaces are translucent, so --card and --line carry alpha rather than
   solid colour. The blurred backdrop comes from the gradient field painted on
   body below: backdrop-filter has nothing to refract over a flat fill, and
   the whole effect collapses into plain grey without it. */
[data-theme="glass"] {
  --bg: #0d1b16;
  --card: rgba(255, 255, 255, .10);
  --line: rgba(255, 255, 255, .17);
  --hair: rgba(255, 255, 255, .08);
  --ink: #f3f7f5;
  --ink-2: #c9d4cf;
  --muted: #98a6a1;
  --accent: #57c795;
  --accent-soft: rgba(87, 199, 149, .16);
  --gold: #e0c070;
  --danger: #ff8478;
  --field: rgba(255, 255, 255, .07);
  --shadow: 0 10px 30px rgba(0, 0, 0, .32);
  --glass: blur(20px) saturate(180%);
  /* The bright top edge that reads as a lit bevel, plus a faint bottom bounce. */
  --glass-edge:
    inset 0 1px 0 rgba(255, 255, 255, .30),
    inset 0 -1px 0 rgba(255, 255, 255, .05);
}

* { box-sizing: border-box; }

/* Any rule that sets `display` beats the browser's built-in
   `[hidden] { display: none }`, which silently un-hides flex/grid elements.
   This keeps the hidden attribute meaning what it says. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -0.01em; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow);
}

.mark {
  width: 46px; height: 46px;
  margin: 0 auto 16px;
  border-radius: 13px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
}

.login-card h1 { font-size: 21px; }
.login-card .sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 22px; }

.pin-input {
  width: 100%;
  padding: 13px;
  font-size: 24px;
  letter-spacing: .35em;
  text-align: center;
  font-family: var(--mono);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  transition: border-color var(--t), box-shadow var(--t);
}
.pin-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.msg { min-height: 20px; margin-top: 12px; font-size: 13.5px; }
.msg.err { color: var(--danger); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--t), border-color var(--t), transform var(--t);
}
.btn:hover { background: var(--hair); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.wide { width: 100%; padding: 13px; margin-top: 18px; font-size: 15px; }
.btn.tiny { padding: 6px 10px; font-size: 12.5px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-in {
  max-width: 1080px; margin: 0 auto;
  height: 62px;
  display: flex; align-items: center; gap: 14px;
}
.topbar .brand { font-weight: 640; font-size: 16px; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.who { font-size: 13.5px; color: var(--ink-2); text-align: right; line-height: 1.3; }
.who b { display: block; color: var(--ink); font-weight: 600; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 26px 24px 80px; }

/* ── Proxy banner ──────────────────────────────────────────────────────── */
/* Deliberately loud. An admin must never forget whose library they are in. */
.proxybar {
  background: var(--gold);
  color: #2a2208;
  font-size: 13.5px;
  padding: 9px 24px;
  display: flex; align-items: center; gap: 14px;
  position: sticky; top: 62px; z-index: 19;
}
.proxybar b { font-weight: 700; }
.proxybar .btn { margin-left: auto; background: rgba(255, 255, 255, .75); border-color: rgba(0, 0, 0, .15); }
.proxybar .btn:hover { background: #fff; }

/* ── Usage bar ─────────────────────────────────────────────────────────── */
.usage { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }
.usage .track {
  width: 96px; height: 6px;
  background: var(--hair);
  border-radius: 999px; overflow: hidden;
}
.usage .fill { height: 100%; background: var(--accent); transition: width var(--t); }
.usage .fill.warn { background: var(--gold); }
.usage .fill.full { background: var(--danger); }

/* ── Dropzone ──────────────────────────────────────────────────────────── */
.drop {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 34px 24px;
  text-align: center;
  transition: border-color var(--t), background var(--t);
  cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop h2 { font-size: 16px; margin-bottom: 4px; }
.drop p { margin: 0; color: var(--muted); font-size: 13.5px; }
.drop .hint { margin-top: 8px; font-size: 12.5px; color: var(--muted); }

/* ── Video grid ────────────────────────────────────────────────────────── */
.section-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 30px 0 14px;
}
.section-head h2 { font-size: 15px; }
.section-head .count { color: var(--muted); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
}

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #22282a center/cover no-repeat;
  display: grid; place-items: center;
}
.thumb .dur {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0, 0, 0, .78); color: #fff;
  font-size: 11.5px; font-variant-numeric: tabular-nums;
  padding: 2px 6px; border-radius: 5px;
}
.thumb .state {
  color: #cfd6d2; font-size: 13px; text-align: center; padding: 16px;
}
.thumb .bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 4px; background: rgba(255, 255, 255, .18);
}
.thumb .bar i { display: block; height: 100%; background: var(--gold); transition: width var(--t); }

.card-body { padding: 13px 14px; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.card-title { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.card-sub { color: var(--muted); font-size: 12.5px; }

.card-links { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 13px; }

.badge {
  display: inline-block;
  font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.warn { background: #fdf3dd; color: #8a6d1f; }
.badge.err { background: #fbeae8; color: var(--danger); }

.empty {
  text-align: center; color: var(--muted);
  padding: 48px 20px; font-size: 14px;
  border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ── Admin tables ──────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--hair); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(20, 24, 22, .45);
  display: none; place-items: center; padding: 24px; z-index: 50;
}
.modal-back.open { display: grid; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 440px;
  max-height: 80vh; overflow: auto;
}
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal label { display: block; font-size: 12.5px; color: var(--ink-2); margin: 12px 0 5px; }
.modal input[type=text] {
  width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px;
  background: var(--field); color: var(--ink);
}
.modal input[type=text]::placeholder { color: var(--muted); }
.modal input[type=text]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translateX(-50%) translateY(12px);
  /* Fixed dark pill in every theme - it floats over arbitrary content, so it
     cannot borrow --ink without inverting itself into illegibility on dark. */
  background: rgba(24, 29, 27, .94); color: #fff;
  border: 1px solid rgba(255, 255, 255, .14);
  padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t), transform var(--t);
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Theme picker ──────────────────────────────────────────────────────── */
.themepick {
  display: flex; gap: 2px; padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--hair);
}
.themepick button {
  width: 30px; height: 25px;
  display: grid; place-items: center;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.themepick button:hover { color: var(--ink); }
.themepick button[aria-pressed="true"] { background: var(--card); color: var(--ink); }
.themepick svg { width: 14px; height: 14px; display: block; }

/* ── Glass surfaces ────────────────────────────────────────────────────── */
/* Scoped entirely to the glass theme - light and dark never pay for any of
   this, and never load a blur layer. */

/* The backdrop lives on a fixed pseudo-element rather than
   `background-attachment: fixed`, which janks badly on mobile Safari and
   Chrome while scrolling a blurred page. */
[data-theme="glass"] body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1100px 700px at 10% -12%, rgba(31, 122, 84, .38), transparent 62%),
    radial-gradient(900px 620px at 92% 0%, rgba(38, 92, 128, .30), transparent 58%),
    radial-gradient(900px 700px at 50% 118%, rgba(140, 108, 44, .24), transparent 58%),
    var(--bg);
}

[data-theme="glass"] .login-card,
[data-theme="glass"] .topbar,
[data-theme="glass"] .panel,
[data-theme="glass"] .card,
[data-theme="glass"] .modal,
[data-theme="glass"] .drop,
[data-theme="glass"] .themepick {
  -webkit-backdrop-filter: var(--glass);
  backdrop-filter: var(--glass);
  box-shadow: var(--glass-edge), var(--shadow);
}

/* Buttons deliberately get the lit edge but NOT their own blur layer. There
   are three per video card, so blurring them would mean ~90 compositing
   layers on a library of 30 - which is exactly where a mid-range Android
   phone starts dropping frames. The translucent fill over the already-blurred
   card behind reads the same for free. */
[data-theme="glass"] .btn { box-shadow: var(--glass-edge); }
/* --hair is fainter than --card here, so the inherited hover would make a
   button recede instead of lift. */
[data-theme="glass"] .btn:hover { background: rgba(255, 255, 255, .18); }
[data-theme="glass"] .empty { border-color: var(--line); }
[data-theme="glass"] .thumb { background-color: rgba(0, 0, 0, .35); }

/* Old browsers with no backdrop-filter would render the glass theme as barely
   visible white films. Give them something solid instead. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  [data-theme="glass"] {
    --card: rgba(28, 42, 36, .90);
    --field: rgba(0, 0, 0, .28);
  }
}

/* Respect a stated preference for less transparency: same palette, no blur. */
@media (prefers-reduced-transparency: reduce) {
  [data-theme="glass"] .login-card,
  [data-theme="glass"] .topbar,
  [data-theme="glass"] .panel,
  [data-theme="glass"] .card,
  [data-theme="glass"] .modal,
  [data-theme="glass"] .drop,
  [data-theme="glass"] .themepick {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(28, 42, 36, .94);
  }
}

@media (max-width: 620px) {
  .topbar-in { height: auto; padding: 12px 0; flex-wrap: wrap; }
  .usage { order: 3; width: 100%; }
  .grid { grid-template-columns: 1fr; }
}
