/* ── CSS variables ─────────────────────────────────────────── */
:root {
  color-scheme: light dark;
  --bg:           #f2f0ea;
  --bg-alt:       #faf8f2;
  --surface:      rgba(255,255,255,0.85);
  --surface-hi:   #ffffff;
  --text:         #17212b;
  --muted:        #66717c;
  --border:       rgba(23,33,43,0.13);
  --accent:       #c8511a;
  --accent-hi:    #a8420f;
  --danger:       #b42318;
  --shadow:       0 18px 46px rgba(23,33,43,0.09);
  --radius-card:  18px;
  --radius-input: 11px;
  --radius-btn:   11px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #0d1117;
    --bg-alt:     #131820;
    --surface:    rgba(18,24,32,0.92);
    --surface-hi: #151c26;
    --text:       #edf1f5;
    --muted:      #8a97a5;
    --border:     rgba(237,241,245,0.11);
    --accent:     #f07840;
    --accent-hi:  #e05f28;
    --danger:     #ff7070;
    --shadow:     0 20px 50px rgba(0,0,0,0.4);
  }
}

[data-theme="light"] { color-scheme: light; }
[data-theme="dark"]  {
  color-scheme: dark;
  --bg:         #0d1117;  --bg-alt:     #131820;
  --surface:    rgba(18,24,32,0.92);  --surface-hi: #151c26;
  --text:       #edf1f5;  --muted:      #8a97a5;
  --border:     rgba(237,241,245,0.11);
  --accent:     #f07840;  --accent-hi:  #e05f28;
  --danger:     #ff7070;
  --shadow:     0 20px 50px rgba(0,0,0,0.4);
}

/* ── Reset / base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.9375rem; line-height: 1.55; color: var(--text);
  background: linear-gradient(160deg, var(--bg-alt) 0%, var(--bg) 60%);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
h1,h2,h3,p { margin-top: 0; }
h1 { margin-bottom: 0.2rem; font-size: clamp(1.6rem, 2.4vw, 2.5rem); }
h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.eyebrow { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.muted, .subtitle { color: var(--muted); }

/* ── Admin shell ───────────────────────────────────────────── */
.app-shell { max-width: 1280px; margin: 0 auto; padding: 1rem 1.2rem 3rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; margin-bottom: 1.25rem;
}
.topbar-actions, .inline-actions, .tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.content { display: grid; gap: 0; }
.grid { display: grid; gap: 1rem; }
.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.section-gap { margin-top: 1rem; }

/* ── Card ──────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  background: var(--surface); backdrop-filter: blur(14px);
  box-shadow: var(--shadow); border-radius: var(--radius-card);
  padding: 1.25rem 1.3rem;
}
.notice {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-card); padding: 0.8rem 1.1rem; margin-bottom: 0.75rem;
}
.notice-error { border-color: var(--danger); color: var(--danger); }
.narrow { max-width: 520px; }

/* ── Forms ─────────────────────────────────────────────────── */
.stack { display: grid; gap: 0.85rem; }
label { display: grid; gap: 0.35rem; font-size: 0.875rem; }
label > span { font-weight: 500; color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  width: 100%; padding: 0.65rem 0.85rem;
  border-radius: var(--radius-input); border: 1px solid var(--border);
  background: var(--surface-hi); color: var(--text); font: inherit; font-size: 0.9rem;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.875rem; }
.inline-input { flex: 1; width: auto; min-width: 0; }
.color-swatch { width: 40px; padding: 2px 4px; border-radius: 8px; cursor: pointer; flex-shrink: 0; }
.is-archived { opacity: 0.5; font-style: italic; }

/* ── Buttons ───────────────────────────────────────────────── */
.button {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.65rem 1rem;
  border-radius: var(--radius-btn); border: 1px solid var(--border);
  background: var(--surface-hi); color: var(--text);
  font: inherit; font-size: 0.875rem; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.button-primary { background: var(--accent); color: #fff; border-color: transparent; }
.button-primary:hover { background: var(--accent-hi); }
.button-ghost { background: transparent; }
.button-ghost:hover { background: rgba(128,128,128,0.08); }
.button-danger { color: var(--danger); border-color: transparent; background: transparent; }
.button-danger:hover { background: rgba(180,35,24,0.08); }
.button-sm { padding: 0.35rem 0.6rem; font-size: 0.8rem; border-radius: 8px; }

/* ── Lists / sortable ──────────────────────────────────────── */
.list, .sortable-list, .item-list { display: grid; gap: 0.5rem; }
.list-item, .sortable-item, .item-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.9rem; border: 1px solid var(--border);
  border-radius: 13px; background: rgba(128,128,128,0.04);
}
.sortable-item { cursor: grab; }
.sortable-item.is-dragging, .cue-row.is-dragging { opacity: 0.45; }
.drag-handle { color: var(--muted); cursor: grab; user-select: none; font-size: 1.1rem; flex-shrink: 0; }
.item-link {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 0.75rem 1rem; border: 1px solid var(--border);
  border-radius: 13px; background: rgba(128,128,128,0.04);
  transition: background 0.15s, border-color 0.15s;
}
.item-link:hover { background: rgba(128,128,128,0.09); border-color: var(--accent); }
.item-link > div { display: flex; flex-direction: column; gap: 0.1rem; }
.item-arrow { color: var(--accent); font-weight: 700; }
.item-row-info { flex: 1; display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; min-width: 0; }
.item-row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tab {
  display: inline-flex; align-items: center; padding: 0.45rem 0.9rem;
  border: 1px solid var(--border); border-radius: 999px; font-size: 0.85rem;
  background: transparent; transition: background 0.15s;
}
.tab.active { background: var(--accent); color: #fff; border-color: transparent; }
.tab:hover:not(.active) { background: rgba(128,128,128,0.08); }

/* ── Section head ──────────────────────────────────────────── */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.85rem; }
.section-head h2 { margin-bottom: 0; }

/* ── Misc forms ────────────────────────────────────────────── */
.inline-form { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 160px; }
.create-rundown-form { display: grid; grid-template-columns: 1fr 160px 140px auto; gap: 0.65rem; align-items: end; }
.rundown-settings-grid .field-row { grid-template-columns: 1fr 160px 140px; }

/* ── Login ─────────────────────────────────────────────────── */
.page-login .content { justify-items: center; padding-top: 4rem; }

/* ── TomSelect overrides ───────────────────────────────────── */
.ts-wrapper { font-size: 0.875rem; }
.ts-control { border-radius: var(--radius-input) !important; border-color: var(--border) !important; background: var(--surface-hi) !important; color: var(--text) !important; min-height: 36px; }
.ts-dropdown { background: var(--surface-hi) !important; border-color: var(--border) !important; color: var(--text) !important; border-radius: var(--radius-input) !important; }
.ts-dropdown .option.active { background: var(--accent) !important; color: #fff !important; }

/* ════════════════════════════════════════════════════════════
   CUE EDITOR (admin /rundowns/:id)
   ════════════════════════════════════════════════════════════ */

.cue-sheet-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 0.65rem;
}

/* Column label row */
.cue-editor-labels {
  display: grid;
  grid-template-columns: 28px 22px 52px 72px 1fr 48px 28px 28px;
  gap: 4px;
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

/* Container */
.cue-editor { display: grid; gap: 3px; }

/* Each cue row */
.cue-row {
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: rgba(128,128,128,0.03);
}

.cue-row.is-break {
  background: rgba(200,81,26,0.05);
  border-color: rgba(200,81,26,0.2);
}

/* Compact header */
.cue-row-head {
  display: grid;
  grid-template-columns: 28px 22px 52px 72px 1fr 48px 28px 28px;
  gap: 4px;
  align-items: center;
  padding: 5px 8px;
  border-left: 4px solid transparent;
  min-height: 38px;
}

/* Break rows: kind badge + title spanning type+title+dur+expand cols */
.cue-row.is-break .cue-row-head {
  grid-template-columns: 28px 22px 52px auto 1fr 28px;
}

.cue-num  { font-size: 0.72rem; color: var(--muted); text-align: right; }
.cue-time { font-variant-numeric: tabular-nums; font-size: 0.8rem; color: var(--muted); }
.col-kind { width: auto; padding: 0.28rem 0.4rem; font-size: 0.8rem; border-radius: 7px; }
.col-type { width: auto; padding: 0.28rem 0.4rem; font-size: 0.8rem; border-radius: 7px; }
.col-dur  { padding: 0.28rem 0.4rem; font-size: 0.85rem; border-radius: 7px; text-align: right; }
.cue-title-input { padding: 0.3rem 0.55rem; font-size: 0.9rem; font-weight: 500; border-radius: 8px; min-width: 0; }
.cue-break-badge {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); white-space: nowrap;
}
.cue-expand-btn { padding: 0.2rem 0.4rem; font-size: 0.85rem; border-radius: 6px; }
.cue-expand-btn[aria-expanded="true"] { background: rgba(128,128,128,0.1); }

/* Expandable details */
.cue-row-details {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.65rem;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--border);
  background: rgba(128,128,128,0.02);
}
.cue-details-full { grid-column: 1 / -1; }

/* ════════════════════════════════════════════════════════════
   PUBLIC PROGRAM TABLE
   ════════════════════════════════════════════════════════════ */

.page-public body { background: var(--bg); }

/* Program header */
.program-header {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0.75rem;
}
.program-header-top {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--border); padding-bottom: 0.75rem;
}
.program-title { font-size: clamp(1.6rem, 3vw, 2.4rem); margin: 0; }
.program-date  { color: var(--muted); margin: 0.2rem 0 0; font-size: 0.9rem; }

/* Table wrapper */
.program-table-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  overflow: auto;
}

/* The table */
.program-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.program-table th,
.program-table td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  vertical-align: top;
}

.program-table thead th {
  background: rgba(128,128,128,0.07);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Time column */
.prog-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  vertical-align: middle;
}

/* Description column */
.prog-desc strong { display: block; }
.prog-subtitle { display: block; font-style: italic; color: var(--muted); font-size: 0.875rem; }
.prog-body { margin-top: 0.3rem; }
.prog-body p  { margin: 0.1rem 0; }
.prog-body ul { margin: 0.2rem 0; padding-left: 1.2rem; }
.prog-body li { margin: 0.1rem 0; }

/* Duration column */
.prog-dur { white-space: nowrap; color: var(--muted); font-size: 0.875rem; vertical-align: middle; }

/* Screen column */
.prog-screen p  { margin: 0.1rem 0; font-size: 0.875rem; }
.prog-screen ul { margin: 0.2rem 0; padding-left: 1.1rem; }
.prog-screen li { font-size: 0.875rem; margin: 0.1rem 0; }

/* Lyd column */
.prog-lyd { font-size: 0.875rem; color: var(--muted); vertical-align: middle; }

/* Break rows */
.prog-break td {
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.85rem;
  background: rgba(128,128,128,0.08);
  color: var(--muted);
  padding: 0.7rem;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 860px) {
  .two-up { grid-template-columns: 1fr; }
  .topbar, .cue-sheet-header, .section-head, .program-header-top { flex-direction: column; align-items: stretch; }
  .create-rundown-form { grid-template-columns: 1fr 1fr; }
  .cue-row-details { grid-template-columns: 1fr; }
  .cue-editor-labels { display: none; }
  .cue-row-head { grid-template-columns: 28px 22px 52px 1fr 28px 28px; }
  .cue-row-head .col-kind, .cue-row-head .col-type { display: none; }
  .program-table th:nth-child(4), .program-table td:nth-child(4),
  .program-table th:nth-child(5), .program-table td:nth-child(5) { display: none; }
}

@media (max-width: 540px) {
  .create-rundown-form { grid-template-columns: 1fr; }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  body, .app-shell { background: white; color: black; }
  .topbar-actions, .tabs, .button, .notice, .cue-sheet-header .inline-actions { display: none !important; }
  .card { box-shadow: none; background: white; border: none; padding: 0; border-radius: 0; }

  /* Program print styles */
  .program-header { padding: 0 0 0.5rem; }
  .program-table-wrap { padding: 0; }
  .program-table { font-size: 0.85rem; }
  .program-table th, .program-table td { border-color: #999; }
  .prog-break td { background: #eee !important; }
}
