:root {
  --bg: #f6f6f4; --card: #ffffff; --text: #1d1d1b; --muted: #6b6a66; --border: #e3e2dd;
  --accent: #2463c7; --accent-bg: #e6effb; --ok: #2f7d32; --ok-bg: #e5f3e6;
  --warn: #8a5a00; --warn-bg: #fbf0d9; --bad: #b3261e; --bad-bg: #fbe7e5; --radius: 8px; --on-accent: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --card: #201f1e; --text: #ecebe7; --muted: #a09f9a; --border: #34332f;
    --accent: #7aa7ee; --accent-bg: #1c2b44; --ok: #8fd193; --ok-bg: #1b2e1c;
    --warn: #f0c46b; --warn-bg: #3a2d10; --bad: #f2a29b; --bad-bg: #3d1d1a; --on-accent: #0f1c30; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.error { color: var(--bad); font-size: 14px; margin: 6px 0 0; min-height: 0; }
.error:empty { display: none; }
[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--border); background: var(--card); border-radius: var(--radius); padding: 7px 14px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.ghost { background: transparent; }
button:disabled { opacity: .6; cursor: wait; }
input[type=text], input[type=password], input[type=datetime-local], select, textarea {
  border: 1px solid var(--border); background: var(--card); border-radius: var(--radius); padding: 6px 10px; width: 100%;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select { color: var(--text); font-size: 15px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; margin-bottom: 16px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: var(--radius); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--accent-bg); color: var(--accent); }
.pill.muted { background: var(--bg); color: var(--muted); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }

.top { display: flex; align-items: center; gap: 20px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.top nav { display: flex; gap: 4px; }
.tab { border: none; background: transparent; border-radius: var(--radius); color: var(--muted); }
.tab.active { background: var(--accent-bg); color: var(--accent); }
.top #logout { margin-left: auto; }
.count { background: var(--accent); color: var(--on-accent); border-radius: 10px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.tab-panel { padding: 20px 24px; max-width: 1280px; margin: 0 auto; }

.upload { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.video-captions { margin-top: 12px; }
.video-captions select { max-width: 520px; }
.progress { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
a.button { display: inline-block; border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 14px; color: inherit; text-decoration: none; font-size: 15px; }
a.button:hover { border-color: var(--muted); }
.video-block { margin-bottom: 24px; }
.video-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.video-head strong { font-weight: 600; }
.video-head select { width: auto; max-width: 420px; }
.video-head .muted { font-size: 13px; }
.visibility { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.visibility label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.rows .sub { display: block; color: var(--muted); font-size: 12px; }

.library { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 800px) { .library { grid-template-columns: 1fr; } }
.batches ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.batches li { padding: 8px 10px; border-radius: var(--radius); cursor: pointer; }
.batches li:hover { background: var(--bg); }
.batches li.active { background: var(--accent-bg); }
.batches li small { display: block; color: var(--muted); font-size: 12px; }

.clips-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions select { width: auto; }
.actions.end { justify-content: flex-end; margin-top: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.clip { position: relative; cursor: pointer; }
.clip .thumb { aspect-ratio: 9 / 16; width: 100%; object-fit: cover; border-radius: var(--radius); background: var(--border); display: block; outline: 3px solid transparent; outline-offset: 1px; }
.clip.selected .thumb { outline-color: var(--accent); }
.clip .check { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.45); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.clip.selected .check { background: var(--accent); }
.clip .play { position: absolute; top: 8px; right: 8px; border-radius: 50%; width: 28px; height: 28px; padding: 0; background: rgba(0,0,0,.45); color: #fff; border: none; font-size: 12px; }
.clip .badge { position: absolute; bottom: 30px; left: 8px; }
.clip .label { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; }

.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 12px; }
.strip img { width: 54px; aspect-ratio: 9/16; object-fit: cover; border-radius: 6px; }
.plan-controls { display: grid; grid-template-columns: minmax(0, 2fr) 220px 150px auto; gap: 12px; align-items: end; }
@media (max-width: 900px) { .plan-controls { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0; padding: 6px 10px 8px; min-width: 0; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.accounts { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.accounts label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.accounts .tools { width: 100%; display: flex; gap: 10px; font-size: 13px; }
.accounts .tools a { color: var(--accent); cursor: pointer; }

table.rows { width: 100%; border-collapse: collapse; font-size: 14px; }
.rows th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.rows td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.rows td.thumbcell img { width: 40px; aspect-ratio: 9/16; object-fit: cover; border-radius: 4px; cursor: pointer; display: block; }
.rows select, .rows input { min-width: 140px; }
.rows textarea { min-width: 280px; resize: vertical; min-height: 60px; }
.rows .row-problems { font-size: 12px; margin-top: 4px; }
.rows .row-problems .warning { color: var(--warn); }
.rows .row-problems .error { color: var(--bad); display: block; margin: 0; font-size: 12px; }
.rows tr.has-error td { background: var(--bad-bg); }
.status td.caption { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status .err { color: var(--bad); font-size: 12px; white-space: normal; max-width: 320px; }
.status a { color: var(--accent); }
.link { background: none; border: none; color: var(--accent); padding: 0 4px; font-size: 13px; }
#problems .warning { color: var(--warn); }
#problems p { margin: 8px 0 0; font-size: 14px; }

dialog#player { border: none; border-radius: 12px; padding: 12px; background: var(--card); color: var(--text); }
dialog#player::backdrop { background: rgba(0,0,0,.6); }
dialog#player video { display: block; max-height: 78vh; max-width: 90vw; border-radius: 8px; background: #000; }
dialog#player form { display: flex; justify-content: flex-end; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: var(--radius); z-index: 20; font-size: 14px; }
.video-head label.inline { flex-direction: row; align-items: center; gap: 6px; margin-left: auto; }
ul.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
ul.plain code { font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-left: 4px; vertical-align: middle; }
.inline-check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; margin-top: 10px; }
.caption-full { width: 100%; font-size: 13px; color: var(--muted); margin: -4px 0 10px; }

/* ---------- stats (chart tokens: validated slot-1 blue, hairline chrome) ---------- */
.viz-root {
  --viz-series: #2a78d6; --viz-wash: rgba(42, 120, 214, 0.10); --viz-surface: var(--card);
  --viz-grid: #e1e0d9; --viz-axis: #c3c2b7; --viz-muted: #898781;
}
@media (prefers-color-scheme: dark) {
  .viz-root { --viz-series: #3987e5; --viz-wash: rgba(57, 135, 229, 0.10); --viz-grid: #2c2c2a; --viz-axis: #383835; }
}
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filter-row select { width: auto; }
#stats-body { transition: opacity .15s; }
#stats-body.loading { opacity: .5; }
.hero { margin-bottom: 16px; }
.hero-value { font-size: 52px; font-weight: 600; line-height: 1.1; margin: 2px 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.tile { background: var(--bg); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--muted); margin: 0; }
.tile .value { font-size: 24px; font-weight: 600; margin: 2px 0 0; }
figure.chart { margin: 0; position: relative; }
figure.chart figcaption { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.viz-tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px; font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.12);
  z-index: 3; white-space: nowrap; }
.viz-tip strong { display: block; font-size: 15px; font-weight: 600; }
.viz-tip span { color: var(--muted); }
.line-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.line-chart .grid line { stroke: var(--viz-grid); stroke-width: 1; }
.line-chart .baseline { stroke: var(--viz-axis); stroke-width: 1; }
.line-chart text { fill: var(--viz-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.line-chart .end-label { fill: var(--text); font-weight: 600; }
.line-chart .crosshair { stroke: var(--viz-axis); stroke-width: 1; }
table.data td, table.data th { font-variant-numeric: tabular-nums; }
table.data td.num, table.data th.num { text-align: right; }
.empty-note { color: var(--muted); font-size: 14px; padding: 12px 0; }
.table-scroll { overflow-x: auto; }
.videos-table th button.sort { background: none; border: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.videos-table th button.sort:hover { color: var(--text); }
.videos-table th[aria-sort] button.sort { color: var(--text); font-weight: 600; }
.videos-table th[aria-sort="descending"] button.sort::after { content: " ↓"; }
.videos-table th[aria-sort="ascending"] button.sort::after { content: " ↑"; }
.views-cell { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 90px; }
.mini-bar { width: 100%; height: 4px; display: block; }
.mini-bar span { display: block; height: 4px; background: var(--viz-series); border-radius: 0 2px 2px 0; min-width: 2px; }
td.nowrap { white-space: nowrap; }
.videos-table td:nth-child(2) { min-width: 150px; }
.clip .dl { color: var(--muted); text-decoration: none; margin-left: 6px; padding: 0 2px; border-radius: 4px; }
.clip .dl:hover { color: var(--accent); background: var(--bg); }
.link-small { color: var(--accent); font-size: 13px; text-decoration: none; }
.link-small:hover { text-decoration: underline; }
