:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #161a21; --ink-2: #414955; --muted: #6b7380; --line: #e2e5ea; --line-2: #eef0f3;
  --side: #12161d; --side-ink: #c9ced6; --side-hi: #ffffff;
  --accent: #e4572e; --accent-ink: #ffffff; --accent-soft: #fde9e2;
  --ok: #1f9d55; --ok-soft: #e3f5ea; --warn: #b7791f; --warn-soft: #fdf3dc; --bad: #c53030; --bad-soft: #fde8e8; --info: #2b6cb0; --info-soft: #e6f0fa;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.mono, .time { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 750; font-size: 17px; letter-spacing: .01em; }
.tally { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(228,87,46,.25); flex: none; }
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 1px; overflow-y: auto; flex: 1; }
.nav a { color: var(--side-ink); padding: 8px 10px; border-radius: 6px; display: flex; align-items: center; gap: 10px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.1); color: #fff; }
.nav a.on::before { content: ""; width: 3px; height: 16px; background: var(--accent); border-radius: 2px; margin-left: -6px; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6c7584; padding: 14px 10px 4px; }
.side-foot { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side-foot b { color: #fff; display: block; font-weight: 600; font-size: 13px; }
.side-foot .row { display: flex; gap: 8px; margin-top: 8px; }
.side-foot button { background: rgba(255,255,255,.08); color: var(--side-ink); border: 0; padding: 5px 9px; border-radius: 5px; cursor: pointer; font: inherit; }
.side-foot button:hover { color: #fff; background: rgba(255,255,255,.14); }
.main { min-width: 0; padding: 22px 28px 60px; }
.topbar { display: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-b { padding: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stack > * + * { margin-top: 12px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.sticky { position: sticky; top: 16px; }

/* ---------- forms */
label.f { display: block; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
label.f > small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; }
input, select, textarea { font: inherit; color: inherit; background: #fff; border: 1px solid #cfd4db; border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(43,108,176,.35); outline-offset: 0; border-color: #6a9bd1; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 34px; width: 46px; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.fields .wide { grid-column: 1 / -1; }

button, .btn { font: inherit; font-weight: 600; border-radius: 6px; padding: 7px 13px; border: 1px solid #cfd4db; background: #fff; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none; }
button:hover, .btn:hover { background: #f6f7f9; text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.primary:hover { background: #cf4721; }
.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.dark:hover { background: #2a313c; }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: rgba(0,0,0,.05); }
.danger { color: var(--bad); }
.danger:hover { background: var(--bad-soft); }
.sm { padding: 4px 9px; font-size: 12.5px; }
.icon { padding: 4px 7px; line-height: 1; }

/* ---------- tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: #fafbfc; }
.tbl.edit td { padding: 4px 4px; }
.tbl.edit input, .tbl.edit select { padding: 5px 6px; border-color: transparent; background: transparent; }
.tbl.edit input:hover, .tbl.edit select:hover { border-color: #dfe3e8; background: #fff; }
.tbl.edit input:focus, .tbl.edit select:focus { border-color: #6a9bd1; background: #fff; }
.tbl.edit textarea { min-height: 34px; padding: 5px 6px; border-color: transparent; background: transparent; }
.tbl.edit textarea:focus, .tbl.edit textarea:hover { border-color: #dfe3e8; background: #fff; }
.tbl .sec-row td { background: #f6f7f9; font-weight: 650; }
.scroll-x { overflow-x: auto; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }

/* ---------- badges, chips */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: #eef0f3; color: var(--ink-2); white-space: nowrap; }
.b-planned, .b-draft { background: #eef0f3; color: #4a5361; }
.b-confirmed, .b-accepted, .b-done { background: var(--ok-soft); color: var(--ok); }
.b-sent { background: var(--info-soft); color: var(--info); }
.b-live { background: var(--accent-soft); color: var(--accent); }
.b-cancelled, .b-rejected { background: var(--bad-soft); color: var(--bad); }
.b-recur { background: #efe9fb; color: #6b46c1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-weight: 600; font-size: 12.5px; cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- KPI / summary */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .k { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.sum { width: 100%; border-collapse: collapse; }
.sum td { padding: 5px 0; font-variant-numeric: tabular-nums; }
.sum td:last-child { text-align: right; font-weight: 600; }
.sum tr.big td { font-size: 17px; font-weight: 750; padding-top: 10px; border-top: 1px solid var(--line); }
.sum tr.sep td { border-top: 1px dashed var(--line); padding-top: 9px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.meter { height: 6px; background: #eef0f3; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--ok); }

/* ---------- day list */
.day { display: grid; grid-template-columns: 74px 1fr; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.day:last-child { border-bottom: 0; }
.day .d { text-align: center; border-radius: 8px; background: #f3f4f6; padding: 6px 0; }
.day .d b { display: block; font-size: 20px; line-height: 1.1; }
.day .d span { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.day.today .d { background: var(--accent); color: #fff; }
.day.today .d span { color: rgba(255,255,255,.85); }
.ev { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.ev + .ev { margin-top: 6px; }

/* ---------- rundown */
.rd td.t { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.rd tr[data-kind=break] td { background: #fbfbfc; color: var(--muted); }
.rd tr[data-kind=ad] td:first-child, .rd tr[data-kind=video] td:first-child { box-shadow: inset 3px 0 #2b6cb0; }
.rd tr[data-kind=live] td:first-child { box-shadow: inset 3px 0 var(--accent); }
.rd tr[data-kind=break] td:first-child { box-shadow: inset 3px 0 #a0a7b2; }
.rd tr[data-kind=segment] td:first-child { box-shadow: inset 3px 0 #1f9d55; }
.rd tr.drag-over td { border-top: 2px solid var(--accent); }
.rd .handle { cursor: grab; color: #a0a7b2; padding: 0 4px; user-select: none; }
.rd input.dur { width: 72px; font-family: var(--mono); }
.rd input.fx { width: 92px; font-family: var(--mono); }

/* ---------- modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,18,24,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 14px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 820px; }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 500; max-width: 90vw; }
.toast.err { background: var(--bad); }
.saving { font-size: 12px; color: var(--muted); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--side); }
.login .card { background: #fff; border-radius: 12px; padding: 28px; width: 100%; max-width: 380px; }
.login .brand { color: var(--ink); padding: 0 0 18px; }

/* ---------- template editor */
.tpl-grid { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
.tpl-grid iframe { width: 100%; height: 82vh; border: 1px solid var(--line); border-radius: var(--radius); background: #e9ebef; }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.colors label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.asset { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.asset .name { font-size: 12.5px; color: var(--ink-2); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.box { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
details.box > summary { padding: 10px 12px; font-weight: 650; cursor: pointer; list-style: none; }
details.box > summary::after { content: "▾"; float: right; color: var(--muted); }
details.box[open] > summary { border-bottom: 1px solid var(--line); }
details.box > div { padding: 12px; }
details.box + details.box { margin-top: 10px; }

.wa-list { display: flex; flex-direction: column; gap: 8px; }
.wa-list .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.wa { background: #25d366; border-color: #25d366; color: #fff; }
.wa:hover { background: #1fb457; }
.ph { font-size: 12px; background: #f3f4f6; border-radius: 5px; padding: 2px 6px; font-family: var(--mono); cursor: pointer; }

/* ---------- responsive */
@media (max-width: 980px) {
  .cols, .tpl-grid { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 30; font-weight: 700; }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 20px; padding: 2px 6px; }
  .main { padding: 16px 12px 60px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  .hide-m { display: none; }
}
@media print {
  .side, .topbar, .actions, .tabs, button { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .panel { box-shadow: none; border: 0; }
}

/* rundown column sizing: scroll sideways rather than squeeze */
.rd { min-width: 1480px; }
.rd select[name=kind] { min-width: 118px; }
.rd input[name=title] { min-width: 230px; }
.rd input[name=presenter], .rd input[name=video] { min-width: 140px; }
.rd input[name=audio], .rd input[name=graphics] { min-width: 120px; }
.rd textarea[name=notes] { min-width: 200px; }
.rd td.t { width: 96px; }
#lines { min-width: 1080px; }
.sumbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 4px 0 2px; margin: -4px 0 4px; }
.sumbar .kpis { margin-bottom: 12px; }
.sumbar .kpi .v { font-size: 20px; }
@media (max-width: 760px) { .sumbar { position: static; } }
#lines input[name=section] { min-width: 110px; } #lines input[name=description] { min-width: 300px; }
