:root {
  --bg: #f1f3f6; --panel: #ffffff; --ink: #141a26; --text: #3c4352; --muted: #7a8190; --line: #e6e9ee; --line-strong: #cfd4dc;
  --brand: #1f5eff; --brand-hover: #1a4fd6; --brand-ink: #ffffff; --brand-soft: #e8efff;
  --navy: #141a33; --ok: #17894b; --ok-soft: #e2f5ea; --bad: #d4321c; --bad-soft: #fde8e5; --warn: #b26a00; --warn-soft: #fff2d9;
  --pill: #e9ecf1; --radius: 10px; --btn-radius: 6px; --side-w: 228px;
  --shadow: 0 1px 3px rgba(20, 26, 38, .07), 0 1px 2px rgba(20, 26, 38, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181e; --panel: #1e2229; --ink: #f1f3f6; --text: #c9ced6; --muted: #8b919c; --line: #2b3039; --line-strong: #3a404b;
    --brand: #4d82ff; --brand-hover: #6694ff; --brand-soft: #1f2a44;
    --ok: #4cc685; --ok-soft: #1b3326; --bad: #ff7a66; --bad-soft: #3d2420; --warn: #f0b04a; --warn-soft: #3a2f1a;
    --pill: #2a2f38; --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.015em; color: var(--ink); margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin: 0 0 .75rem; }
.muted, small { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------------------ shell */
#side { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: var(--ink); font-weight: 700; font-size: 1.12rem; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
#nav a:hover { background: var(--pill); }
#nav a.on { background: var(--brand-soft); color: var(--brand); }
#side .foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); }
#side .foot b { display: block; color: var(--ink); font-weight: 600; font-size: .92rem; }
#side .foot span { display: block; font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#side .foot button { margin-top: 10px; width: 100%; }
main { margin-left: var(--side-w); padding: 28px 36px 60px; max-width: 1500px; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; min-height: 40px; }
.head .grow { flex: 1; }
.head .count { color: var(--muted); font-weight: 500; font-size: 1rem; }
#menu { display: none; }

@media (max-width: 860px) {
  #side { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open #side { transform: none; }
  main { margin-left: 0; padding: 18px 16px 60px; }
  #menu { display: inline-flex; }
}

/* ------------------------------------------------------------ controls */
button, .btn { font: inherit; font-weight: 550; font-size: .9rem; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: var(--btn-radius); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--pill); }
button.icon { padding: 6px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--btn-radius);
  padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--btn-radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 7px 11px; border-right: 1px solid var(--line-strong); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }

/* ------------------------------------------------------------ cards and grids */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 20px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.tile { cursor: pointer; overflow: hidden; display: flex; flex-direction: column; transition: border-color .12s; }
.tile:hover { border-color: var(--line-strong); }
.tile .art { aspect-ratio: 16 / 9; background: var(--pill); display: grid; place-items: center; color: var(--muted); position: relative; overflow: hidden; }
.tile .art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .art svg.i { width: 30px; height: 30px; }
.tile .art .mosaic { display: grid; grid-template-columns: 1fr 1fr; width: 100%; height: 100%; gap: 1px; }
.tile .art .mosaic img:only-child { grid-column: span 2; }
.tile .body { padding: 12px 14px; }
.tile .name { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meta { color: var(--muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .badge { position: absolute; top: 8px; left: 8px; }
.tile.picked { outline: 3px solid var(--brand); outline-offset: -3px; }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty svg.i { width: 36px; height: 36px; margin-bottom: 8px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--panel); color: var(--muted); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.on { color: var(--ok); }
.status.off { color: var(--bad); }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--pill); color: var(--text); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px;
  border-bottom: 1px solid var(--line); }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
td.actions { text-align: right; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
td.off { opacity: .55; }
table.nowrap td { white-space: nowrap; }

.folders { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.chip { font-size: .86rem; padding: 6px 12px; border-radius: 999px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.meter { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.meter .bar { width: 120px; height: 6px; border-radius: 3px; background: var(--pill); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--brand); }
.meter .bar i.full { background: var(--bad); }

/* ------------------------------------------------------------ playlist editor */
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.items li:last-child { border-bottom: 0; }
.items li.drag { opacity: .4; }
.items li.over { box-shadow: inset 0 2px 0 var(--brand); }
.items .grip { cursor: grab; color: var(--muted); }
.items .num { width: 22px; color: var(--muted); font-size: .85rem; text-align: right; }
.items .thumb { width: 72px; height: 40px; border-radius: 4px; background: var(--pill); flex: none; overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.items .thumb img { width: 100%; height: 100%; object-fit: cover; }
.items .what { flex: 1; min-width: 0; }
.items .what b { display: block; color: var(--ink); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .what small { font-size: .82rem; }
.items .secs { width: 92px; display: flex; align-items: center; gap: 6px; }
.items .secs input { text-align: right; padding: 6px 8px; }
.listfoot { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.listfoot .grow { flex: 1; }
.editbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.editbar input.title { width: auto; flex: 1 1 240px; font-size: 1.35rem; font-weight: 650; border-color: transparent; background: transparent; padding: 4px 8px; margin-left: -8px; max-width: 520px; color: var(--ink); }
.editbar input.title:hover { border-color: var(--line-strong); }
.editbar .grow { flex: 0 0 0; }

/* ------------------------------------------------------------ dialogs, toasts, uploads */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--panel); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25); max-height: calc(100vh - 48px); }
dialog.wide { width: min(880px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 22, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
dialog .dh { display: flex; align-items: center; padding: 18px 22px 6px; }
dialog .dh h2 { margin: 0; flex: 1; }
dialog .db { padding: 12px 22px; overflow-y: auto; }
dialog .df { display: flex; gap: 10px; padding: 14px 22px 18px; align-items: center; }
dialog .df .grow { flex: 1; }
.preview { background: #000; border-radius: 8px; overflow: hidden; margin-bottom: 16px; display: grid; place-items: center; max-height: 300px; }
.preview img, .preview video { max-width: 100%; max-height: 300px; display: block; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: .88rem; margin: 4px 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.codebox { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.8rem; letter-spacing: .3em; text-transform: uppercase; text-align: center; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.days { display: flex; gap: 6px; }
.days button { width: 40px; justify-content: center; padding: 7px 0; }
.days button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.screenlist { max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--btn-radius); padding: 6px 10px; margin-top: 8px; }
.err { color: var(--bad); font-size: .88rem; min-height: 1.3em; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast div { background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 8px; font-size: .9rem; box-shadow: var(--shadow); }
#toast div.bad { background: var(--bad); color: #fff; }

#uploads { position: fixed; right: 22px; bottom: 22px; width: 320px; z-index: 50; }
#uploads .card { padding: 12px 14px; }
#uploads .up { font-size: .85rem; margin-bottom: 8px; }
#uploads .up:last-child { margin-bottom: 0; }
#uploads .up b { display: block; font-weight: 550; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#uploads .up .bar { height: 4px; background: var(--pill); border-radius: 2px; overflow: hidden; margin-top: 4px; }
#uploads .up .bar i { display: block; height: 100%; background: var(--brand); transition: width .15s; }
#uploads .up.fail { color: var(--bad); }
#drop { position: fixed; inset: 0; z-index: 60; background: rgba(31, 94, 255, .12); border: 3px dashed var(--brand); display: grid; place-items: center;
  font-size: 1.3rem; font-weight: 600; color: var(--brand); pointer-events: none; }

/* ------------------------------------------------------------ sign in */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate .card { width: min(400px, 100%); padding: 32px 30px 26px; }
.gate .brand { justify-content: center; padding: 0 0 22px; font-size: 1.3rem; }
.gate .brand img { width: 36px; height: 36px; }
.gate h1 { font-size: 1.25rem; text-align: center; margin-bottom: 18px; }
.gate-link { display: block; margin-top: 16px; text-align: center; font-size: .88rem; color: var(--muted); text-decoration: none; }
.gate-link:hover { color: var(--brand); }
.gate-text { text-align: center; color: var(--muted); margin: -6px 0 6px; line-height: 1.5; }
.gate button.primary { width: 100%; justify-content: center; padding: 10px; margin-top: 4px; }
