:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f9fafb; --text: #16202c; --muted: #5d6b7a; --line: #e2e6ea;
  --navy: #132a45; --navy-text: #eef3f8; --accent: #e09a1f; --accent-ink: #1b1405; --link: #1d5fa8;
  --danger: #b42318; --ok: #157347; --warn: #a15c07; --focus: #1d5fa8;
  --s-new: #64748b; --s-assigned: #2563eb; --s-editing: #7c3aed; --s-in_qc: #c2410c; --s-changes: #b42318;
  --s-approved: #15803d; --s-delivered: #0f766e; --s-hold: #6b7280;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b; --panel: #151d26; --panel-2: #111820; --text: #e6ebf0; --muted: #93a1b0; --line: #26313d;
    --navy: #0a1622; --navy-text: #e6ebf0; --accent: #f5b041; --accent-ink: #1b1405; --link: #7cb7ff;
    --danger: #ff7b72; --ok: #4ade80; --warn: #fbbf24; --focus: #7cb7ff;
    --s-new: #94a3b8; --s-assigned: #60a5fa; --s-editing: #a78bfa; --s-in_qc: #fb923c; --s-changes: #f87171;
    --s-approved: #4ade80; --s-delivered: #2dd4bf; --s-hold: #9ca3af;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141b; --panel: #151d26; --panel-2: #111820; --text: #e6ebf0; --muted: #93a1b0; --line: #26313d;
  --navy: #0a1622; --navy-text: #e6ebf0; --accent: #f5b041; --accent-ink: #1b1405; --link: #7cb7ff;
  --danger: #ff7b72; --ok: #4ade80; --warn: #fbbf24; --focus: #7cb7ff;
  --s-new: #94a3b8; --s-assigned: #60a5fa; --s-editing: #a78bfa; --s-in_qc: #fb923c; --s-changes: #f87171;
  --s-approved: #4ade80; --s-delivered: #2dd4bf; --s-hold: #9ca3af;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 15px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
button.bad { color: var(--danger); border-color: var(--danger); background: transparent; }
button.link { border: 0; background: none; padding: 0; color: var(--link); }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label > span { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: grid; gap: 12px; }
.hidden { display: none !important; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: var(--navy-text); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-weight: 800; font-size: 13px; flex: none; }
.brand b { display: block; font-size: 14px; }
.brand small { opacity: .7; font-size: 11px; }
.nav a { display: flex; justify-content: space-between; align-items: center; color: var(--navy-text); opacity: .8; padding: 8px 10px; border-radius: 8px; text-decoration: none; }
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .06); }
.nav a.on { opacity: 1; background: rgba(255, 255, 255, .12); font-weight: 600; }
.nav .count { background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.side-foot { margin-top: auto; font-size: 12px; opacity: .85; display: grid; gap: 6px; padding: 8px; }
.side-foot button { background: transparent; color: var(--navy-text); border-color: rgba(255, 255, 255, .2); }
main { padding: 20px 24px 60px; min-width: 0; }
.topbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.menu-btn { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card-b { padding: 12px 14px; }
.banner { padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel-2); margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { border-color: var(--warn); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { padding: 12px 14px; }
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }

/* Board */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 120px; }
.col-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-weight: 600; font-size: 13px; }
.col-b { display: grid; gap: 8px; padding: 0 8px 10px; align-content: start; }
.job, .version { white-space: normal; }
.job { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--sc, var(--line)); border-radius: 8px; padding: 9px 10px; cursor: pointer; display: grid; gap: 4px; text-align: left; width: 100%; }
.job:hover { border-color: var(--muted); border-left-color: var(--sc); }
.job b { font-size: 13px; line-height: 1.3; }
.job .meta { color: var(--muted); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--muted); font-size: 12px; padding: 6px 4px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.select { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.badge.stage { color: var(--sc); border-color: currentColor; background: transparent; }
.badge.stage::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; background: transparent; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; min-width: 150px; }

/* Job page */
.job-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 14px; }
.job-head h1 { font-size: 22px; }
.links { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 0; }
.links a, .links span.off { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; background: var(--panel); font-size: 13px; }
.links span.off { color: var(--muted); border-style: dashed; }
.job-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 14px; align-items: start; }
.player { background: #000; border-radius: var(--radius) var(--radius) 0 0; aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; }
.player video { width: 100%; height: 100%; background: #000; }
.player .ph { color: #9aa4ae; text-align: center; padding: 20px; font-size: 13px; }
.timeline { position: relative; height: 26px; margin: 10px 2px 2px; cursor: pointer; }
.timeline .track { position: absolute; left: 0; right: 0; top: 11px; height: 4px; border-radius: 4px; background: var(--line); }
.timeline .prog { position: absolute; left: 0; top: 11px; height: 4px; border-radius: 4px; background: var(--muted); }
.timeline .mark { position: absolute; top: 4px; width: 12px; height: 18px; margin-left: -6px; border-radius: 3px; background: var(--accent); border: 2px solid var(--panel); cursor: pointer; }
.timeline .mark.done { background: var(--ok); }
.composer { display: grid; gap: 8px; }
.tc { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--link); cursor: pointer; border: 0; background: none; padding: 0; }
.comment { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: start; }
.comment:last-child { border-bottom: 0; }
.comment.resolved .text { text-decoration: line-through; color: var(--muted); }
.comment .who { font-size: 12px; color: var(--muted); }
.versions { display: grid; gap: 6px; }
.version { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--panel); text-align: left; width: 100%; }
.version.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.notes { white-space: pre-wrap; font-size: 13px; }
.activity { display: grid; gap: 6px; font-size: 12px; }
.activity div { display: grid; grid-template-columns: 90px 1fr; gap: 8px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 10, 16, .55); }
dialog form { display: grid; gap: 12px; padding: 18px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
.secret { font: 600 18px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 10px; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px; text-align: center; user-select: all; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 500px at 50% -10%, rgba(224, 154, 31, .18), transparent), var(--bg); }
.login-box { width: min(380px, 100%); display: grid; gap: 14px; }
.login-box .brand { color: var(--text); padding: 0; }
.login-box form { display: grid; gap: 10px; padding: 18px; }
.err { color: var(--danger); font-size: 13px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy); color: var(--navy-text); padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px); }

@media (max-width: 1100px) { .job-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-block; }
  main { padding: 14px 16px 60px; }
  .board { grid-template-columns: repeat(5, minmax(78vw, 1fr)); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
}
