:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #16191f;
  --muted: #5d6573;
  --accent: #d6243a;        /* on-air red */
  --accent-ink: #ffffff;
  --accent-soft: #fde8eb;
  --ok: #17803d;
  --ok-soft: #e3f4e8;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --info: #2457c5;
  --info-soft: #e5edfc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --border: #2d323c;
    --text: #e9ecf1;
    --muted: #9aa3b2;
    --accent: #ff4d63;
    --accent-ink: #ffffff;
    --accent-soft: #3a1820;
    --ok: #4cc777;
    --ok-soft: #143221;
    --warn: #f0b546;
    --warn-soft: #362a12;
    --info: #7aa2ff;
    --info-soft: #1a2747;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  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(--info); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-logo { height: 46px; width: auto; display: block; }
.brand-sub { color: var(--muted); font-weight: 600; padding-left: 10px; border-left: 1px solid var(--border); }
.auth-card .brand { flex-direction: column; align-items: flex-start; gap: 10px; }
.auth-card .brand-logo { height: 80px; }
.auth-card .brand-sub { border-left: none; padding-left: 0; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs a {
  text-decoration: none; color: var(--muted); font-weight: 500;
  padding: 7px 12px; border-radius: 8px; white-space: nowrap;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

/* ---------- controls ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 12px 20px; font-size: 1rem; font-weight: 600; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.link { border: none; background: none; color: var(--info); padding: 4px 6px; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.danger { color: var(--accent); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--info); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 140px; resize: vertical; }
label { display: block; font-weight: 500; font-size: .9rem; }
label > input, label > select, label > textarea { margin-top: 4px; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 14px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; max-height: 220px; overflow: auto; }
.form-error { color: var(--accent); font-size: .9rem; margin: 6px 0 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input[type=datetime-local] { width: auto; min-width: 220px; }
.inline-form input[name=note] { flex: 1; min-width: 160px; width: auto; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card p { margin: 0 0 18px; }

.read-list { display: grid; gap: 16px; }
.read-card { position: relative; border-left: 5px solid var(--accent); }
.read-card.done { border-left-color: var(--ok); }
.rc-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.client { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.progress { text-align: right; white-space: nowrap; }
.progress .count { font-size: 1.5rem; font-weight: 700; font-family: var(--mono); }
.progress .count.done { color: var(--ok); }
.script {
  white-space: pre-wrap; font-size: 1.15rem; line-height: 1.6;
  background: var(--surface-2); border-radius: 8px; padding: 14px 16px; margin-bottom: 10px;
}
.notes { font-size: .9rem; color: var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; white-space: pre-wrap; }
.rc-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 12px 0 4px; }
.custom-log { margin-top: 10px; padding: 12px; background: var(--surface-2); border-radius: 8px; }

.loglist { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px solid var(--border); }
.loglist li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.loglist li:last-child { border-bottom: none; }
.loglist .t { font-family: var(--mono); font-weight: 500; font-size: 1rem; }
.loglist .who { font-weight: 500; }
.loglist .acts { margin-left: auto; display: flex; gap: 2px; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.live { background: var(--ok-soft); color: var(--ok); }
.badge.upcoming { background: var(--info-soft); color: var(--info); }
.badge.ended { background: var(--surface-2); color: var(--muted); }
.badge.edited { background: var(--warn-soft); color: var(--warn); }
.badge.short { background: var(--accent-soft); color: var(--accent); }

.date-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.date-nav input { width: auto; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.nowrap, th.nowrap { white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.detail-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 20px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.section-title { margin: 24px 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- dialog ---------- */
dialog.dlg {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(620px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog.dlg::backdrop { background: rgba(10, 12, 16, .5); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.secret { font-family: var(--mono); font-size: 1.1rem; background: var(--surface-2); padding: 10px 14px; border-radius: 8px; user-select: all; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 1000; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; animation: pop .18s ease-out; }
.toast.error { background: var(--accent); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .userbox { margin-left: auto; }
  main { padding: 16px 16px 80px; }
  .detail-grid { grid-template-columns: 1fr; }
  .script { font-size: 1.05rem; }
  .inline-form input[type=datetime-local] { min-width: 0; width: 100%; }
  .loglist .acts { margin-left: 0; }
}
