/* ČSFD Hub - one stylesheet, role tokens on :root, light + dark from the OS. */

:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
  --brand: #ba0305;
  --brand-2: #8f0204;
  --series-1: #2a78d6;
  --div-pos: #2a78d6;
  --div-neg: #e34948;
  --div-mid: #c3c2b7;
  --good: #0ca30c;
  --good-text: #006300;
  --good-wash: rgba(12, 163, 12, .10);
  --warning: #fab219;
  --warning-wash: rgba(250, 178, 25, .16);
  --critical: #d03b3b;
  --critical-wash: rgba(208, 59, 59, .10);
  --info-wash: rgba(42, 120, 214, .10);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: none;
    --series-1: #3987e5;
    --div-pos: #3987e5;
    --div-neg: #e66767;
    --div-mid: #383835;
    --good-text: #0ca30c;
    --good-wash: rgba(12, 163, 12, .16);
    --warning-wash: rgba(250, 178, 25, .14);
    --critical-wash: rgba(208, 59, 59, .18);
    --info-wash: rgba(57, 135, 229, .16);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.hidden { display: none !important; }
.mob { display: none; }
body.viewer .admin-only { display: none !important; }

/* ── top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  padding: 0 20px; height: 56px;
  background: #1e1e1e; color: #fff;
  border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 650; font-size: 16px; letter-spacing: .2px; }
.brand svg { width: 30px; height: 30px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a {
  text-decoration: none; padding: 7px 12px; border-radius: 7px;
  color: #c9c9c9; white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, .12); color: #fff; }
.nav .ico { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: rgba(255, 255, 255, .10); color: #fff; white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--good); }
.pill.run .dot { background: #3987e5; animation: pulse 1.2s ease-in-out infinite; }
.pill.warn .dot { background: var(--warning); }
.pill.err .dot { background: var(--critical); }
@keyframes pulse { 50% { opacity: .35; } }

/* ── layout ──────────────────────────────────────────────────────────── */
main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 650; }
.page-head .sub { color: var(--ink-2); margin-top: 3px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; min-width: 0;
}
.card h2 { margin: 0 0 2px; font-size: 15px; font-weight: 650; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.section-title { font-size: 15px; font-weight: 650; margin: 26px 0 10px; }

/* ── stat tiles ──────────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.tile .label { color: var(--ink-2); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.tile .note { color: var(--muted); font-size: 12px; margin-top: 1px; }
a.tile { text-decoration: none; transition: border-color .15s; }
a.tile:hover { border-color: var(--axis); }

/* ── controls ────────────────────────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.input, select.input {
  height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); min-width: 0;
}
.input:focus, .btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
input.input[type="search"] { width: 260px; max-width: 100%; }
input.input.year { width: 84px; }
.btn {
  height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-weight: 550;
  border: 1px solid var(--border); background: var(--surface); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.danger { color: var(--critical); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 0 12px; height: 32px; cursor: pointer; color: var(--ink-2); font-weight: 550; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); }
.spacer { flex: 1; }

/* ── badges & chips ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px; white-space: nowrap; line-height: 1.5;
}
.badge.good { background: var(--good-wash); color: var(--good-text); }
.badge.warn { background: var(--warning-wash); color: var(--ink); }
.badge.err { background: var(--critical-wash); color: var(--critical); }
.badge.info { background: var(--info-wash); color: var(--ink); }
.badge.neutral { background: var(--surface-2); color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); text-decoration: none; white-space: nowrap; }
a.chip:hover { color: var(--ink); }
.stars { letter-spacing: 1px; color: var(--ink); white-space: nowrap; }
.stars .off { color: var(--axis); }
.score { white-space: nowrap; display: inline-block; min-width: 34px; text-align: center; font-weight: 650; font-size: 12.5px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); }

/* ── banners ─────────────────────────────────────────────────────────── */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); }
.banner .icon { font-weight: 700; }
.banner.warn { background: var(--warning-wash); }
.banner.err { background: var(--critical-wash); }
.banner.info { background: var(--info-wash); }
.banner b { font-weight: 650; }

/* ── tables ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; user-select: none;
}
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--ink); }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.r, table.data th.r { text-align: right; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
.t-title { font-weight: 600; }
.t-sub { color: var(--muted); font-size: 12px; }
.thumb { width: 34px; height: 50px; border-radius: 4px; object-fit: cover; background: var(--surface-2); }
.st-failed td { background: var(--critical-wash); }
.st-blocked td { background: var(--warning-wash); }
.st-abandoned td, .st-cancelled td { color: var(--muted); }

/* ── poster cards (watchlist) ────────────────────────────────────────── */
.posters { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.pcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s;
}
.pcard:hover { transform: translateY(-2px); border-color: var(--axis); }
.pcard .poster { aspect-ratio: 2 / 3; width: 100%; object-fit: cover; background: var(--surface-2); }
.pcard .noposter { aspect-ratio: 2 / 3; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.pcard .body { padding: 9px 10px 11px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.pcard .name { font-weight: 600; line-height: 1.25; }
.pcard .meta { color: var(--muted); font-size: 12px; }
.pcard .foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.strip .pcard .body { padding: 7px 8px 9px; }

/* ── charts ──────────────────────────────────────────────────────────── */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font: 11.5px var(--font); }
.chart .val { fill: var(--ink-2); font-weight: 600; }
.chart .lbl { fill: var(--ink-2); }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .bar { fill: var(--series-1); }
.chart .bar.pos { fill: var(--div-pos); }
.chart .bar.neg { fill: var(--div-neg); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { opacity: .78; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
details.tbl { margin-top: 8px; }
details.tbl summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.tbl table { margin-top: 6px; }
#tooltip {
  position: fixed; z-index: 60; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: 7px 10px; font-size: 12.5px; line-height: 1.4;
}
#tooltip b { font-weight: 650; }
#tooltip .muted { font-size: 12px; }

/* ── detail drawer ───────────────────────────────────────────────────── */
#scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(560px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto;
  box-shadow: -8px 0 32px rgba(0, 0, 0, .16); animation: slidein .16s ease-out;
}
@keyframes slidein { from { transform: translateX(24px); opacity: .6; } }
.dw-head { display: flex; gap: 16px; padding: 18px 18px 14px; border-bottom: 1px solid var(--grid); }
.dw-head img, .dw-head .noposter { width: 120px; aspect-ratio: 2 / 3; border-radius: 6px; object-fit: cover; flex: none; background: var(--surface-2); }
.dw-head h2 { margin: 0; font-size: 19px; line-height: 1.25; }
.dw-close { position: sticky; top: 0; float: right; margin: 10px 10px 0 0; z-index: 1; }
.dw-body { padding: 14px 18px 30px; display: flex; flex-direction: column; gap: 16px; }
.dw-body h3 { margin: 0 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; }
.kv .k { color: var(--muted); }
.desc { color: var(--ink-2); }
.emby-box { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.results { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.results button { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 9px; cursor: pointer; }
.results button:hover { background: var(--surface-2); }
.imdb-row { border-top: 1px solid var(--grid); padding-top: 8px; }
.imdb-row .input { width: 190px; }

/* ── Emby page: titles that need a decision ──────────────────────────── */
.issue { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--grid); }
.issue:first-child { border-top: 0; padding-top: 0; }
.issue-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.issue-body .t-sub { margin-left: 6px; }
.issue .imdb-in { width: 230px; }
td.actions { white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }

.empty { color: var(--muted); padding: 26px 0; text-align: center; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.err-box { color: var(--critical); padding: 18px 0; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 40%; background: #3987e5; border-radius: 3px; animation: indet 1.3s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* Things that only matter on a phone. */
html.locked, html.locked body { overflow: hidden; }
@media (hover: none) {
  .pcard:hover { transform: none; }
  table.data tr.click:hover td { background: none; }
  .btn:hover { background: var(--surface); }
  .btn.primary:hover { background: var(--brand); }
}

/* ── phone (iPhone Safari, also "Add to Home Screen") ────────────────── */
@media (max-width: 720px) {
  body { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

  /* Top bar: brand + status, under the notch / status bar. */
  .topbar {
    gap: 10px; height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
    justify-content: space-between;
  }
  .topbar .pill { margin-left: auto; }
  .topbar .logout { padding: 6px 4px; }

  /* Sections move to a tab bar at the bottom, clear of the home indicator. */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; overflow: visible;
    background: rgba(30, 30, 30, .94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255, 255, 255, .08);
    padding: 4px max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
  }
  .nav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 50px; padding: 4px 2px; border-radius: 10px;
    font-size: 10.5px; font-weight: 550; color: #9a9a9a; text-align: center;
  }
  .nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .nav a:hover { background: none; color: #9a9a9a; }
  .nav a[aria-current="page"] { background: none; color: #fff; }
  .nav a[aria-current="page"] .ico { stroke: #fff; }
  .nav .ico {
    display: block; width: 24px; height: 24px; fill: none; stroke: currentColor;
    stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round;
  }

  main {
    padding: 14px max(12px, env(safe-area-inset-right)) calc(84px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 21px; }
  .page-head > .toolbar { width: 100%; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .card { padding: 14px 14px; }
  .section-title { margin-top: 22px; }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tiles > :last-child:nth-child(odd) { grid-column: span 2; }
  .tile { padding: 10px 12px; }
  .tile .value { font-size: 21px; }

  /* 16px+ text in fields stops Safari zooming in on focus; 40px+ targets. */
  .input, select.input { height: 40px; font-size: 16px; }
  input.input[type="search"] { width: 100%; }
  .toolbar { gap: 8px; }
  .toolbar select.input { flex: 1 1 140px; }
  .toolbar input.input.year { flex: 1 1 70px; }
  .btn { height: 40px; }
  .btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
  .seg { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg button { height: 38px; flex: 1 0 auto; padding: 0 10px; }
  .spacer { display: none; }
  .imdb-row .input, .issue .imdb-in { width: 100%; }

  /* Tables: drop the "nice to have" columns, keep the rest scrollable. */
  .opt { display: none; }
  .mob { display: inline; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; -webkit-overflow-scrolling: touch; }
  table.data td, table.data th { padding: 8px 4px; }
  .stars { letter-spacing: 0; }
  table.data td:first-child, table.data th:first-child { padding-left: 0; }
  table.data td:last-child, table.data th:last-child { padding-right: 0; }
  .t-title { min-width: 110px; }

  .posters { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .strip { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .strip .pcard .meta, .strip .pcard .foot .chip { display: none; }

  .issue { gap: 10px; }
  .issue .thumb { width: 42px; height: 62px; }

  /* The detail drawer becomes a full-screen sheet. */
  #drawer {
    width: 100vw; border-left: 0; overscroll-behavior: contain; animation: slideup .18s ease-out;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .dw-close { height: 40px; width: 40px; justify-content: center; padding: 0; font-size: 16px; margin: 8px 8px 0 0;
    background: var(--surface-2); border-radius: 50%; }
  .dw-head { padding: 14px 14px 12px; gap: 12px; }
  .dw-head img, .dw-head .noposter { width: 96px; }
  .dw-head h2 { font-size: 18px; padding-right: 40px; }
  .dw-body { padding: 12px 14px 30px; }
  .kv { grid-template-columns: 92px 1fr; }

  #tooltip { max-width: min(280px, calc(100vw - 16px)); }
}
@keyframes slideup { from { transform: translateY(18px); opacity: .6; } }
@media (max-width: 380px) {
  .strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .strip .pcard:nth-child(n+7) { display: none; }
}

/* Marks never take the pointer - the larger transparent .hit areas do, so
   hovering anywhere in a bar's column (or near a point) shows its tooltip. */
.chart .bar, .chart .line, .chart .dot, .chart text, .chart .base, .chart .grid { pointer-events: none; }

/* ── login page ──────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; max-width: none;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 24px 22px; }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.login-brand h1 { margin: 0; font-size: 20px; font-weight: 650; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; color: var(--ink-2); }
.field .input { height: 42px; font-size: 16px; width: 100%; }
.login-btn { height: 42px; justify-content: center; font-size: 15px; }
.login-msg { color: var(--critical); min-height: 1.2em; font-size: 13px; }
.login-msg:empty { display: none; }
.login-note { font-size: 12px; text-align: center; }
.topbar .logout { color: #c9c9c9; background: none; border: 0; cursor: pointer; padding: 6px 8px; border-radius: 7px; font-size: 13px; white-space: nowrap; }
.topbar .logout:hover { background: rgba(255, 255, 255, .08); color: #fff; }
