/* Layout: fixed sidebar with a single content column; stacks to a top bar on phones. */
:root {
  --bg: #f6f5fa;
  --surface: #ffffff;
  --surface-2: #f1eff7;
  --fg: #1d1b26;
  --muted: #625e72;
  --line: #e2dfec;
  --line-strong: #cfcadf;
  --accent: #5b3f9e;
  --accent-hover: #4b3285;
  --accent-soft: #eee8fa;
  --on-accent: #ffffff;
  --good: #1f7a4d;
  --good-soft: #e3f4ea;
  --warn: #8f5a00;
  --warn-soft: #fbf0d9;
  --bad: #b03a3a;
  --bad-soft: #fbe7e7;
  --live: #c2262e;
  --live-soft: #fde6e7;
  --shadow: 0 1px 2px rgb(29 27 38 / 0.05), 0 4px 16px rgb(29 27 38 / 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131219;
    --surface: #1c1a24;
    --surface-2: #25222f;
    --fg: #ece9f4;
    --muted: #a39fb4;
    --line: #2f2c3b;
    --line-strong: #403c4f;
    --accent: #b39cf0;
    --accent-hover: #c7b5f6;
    --accent-soft: #2c2541;
    --on-accent: #1a1426;
    --good: #5cc795;
    --good-soft: #17301f;
    --warn: #e5b04f;
    --warn-soft: #33270f;
    --bad: #ef8383;
    --bad-soft: #3a1b1d;
    --live: #ff7b80;
    --live-soft: #3d181b;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--font-body);
}

h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: var(--font-mono); font-size: 0.86em; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; overflow-wrap: anywhere; }
code.block { display: block; padding: 10px 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; }
.eyebrow { color: var(--accent); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Shell */
body.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; font-weight: 600; font-size: 1rem; padding: 0 8px; }
.brand.big { font-size: 1.25rem; padding: 0; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: var(--accent);
  /* A simple broadcast mark: dot with two arcs. */
  -webkit-mask: radial-gradient(circle at 50% 50%, #000 3px, transparent 3.5px), radial-gradient(circle at 50% 50%, transparent 6px, #000 6.5px, #000 8px, transparent 8.5px), radial-gradient(circle at 50% 50%, transparent 10.5px, #000 11px, #000 12.5px, transparent 13px);
  mask: radial-gradient(circle at 50% 50%, #000 3px, transparent 3.5px), radial-gradient(circle at 50% 50%, transparent 6px, #000 6.5px, #000 8px, transparent 8.5px), radial-gradient(circle at 50% 50%, transparent 10.5px, #000 11px, #000 12.5px, transparent 13px);
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--fg); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; text-decoration: none; color: var(--muted); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn.ok .dot { background: var(--good); }
.link-button { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 0.85rem; cursor: pointer; text-align: left; }
.link-button:hover { color: var(--fg); text-decoration: underline; }

.content {
  width: 100%; max-width: 1080px;
  padding: 36px max(24px, env(safe-area-inset-right)) 64px max(24px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 24px;
}

body.bare { min-height: 100vh; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }

.page-head { display: flex; flex-direction: column; gap: 6px; }
.page-head p.muted { max-width: 62ch; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card-head > div { display: flex; flex-direction: column; gap: 4px; }

.hero-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.hero-head h2 { font-family: var(--font-display); font-size: 1.5rem; }
.hero-head > div { display: flex; flex-direction: column; gap: 4px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile span { color: var(--muted); font-size: 0.8rem; }
.tile strong { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { align-items: center; text-align: center; padding: 48px 24px; }
.empty .muted { max-width: 46ch; }
.empty-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.empty-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.empty-line { padding: 16px 0; }

.callout { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 14px 18px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--line); }
.callout.warn { background: var(--warn-soft); }
.callout span { flex: 1 1 260px; color: var(--muted); }
.callout .button { margin-left: auto; }

.toast { padding: 12px 16px; border-radius: var(--radius-sm); background: var(--good-soft); color: var(--good); font-weight: 500; }
.toast.bad { background: var(--bad-soft); color: var(--bad); }

.footnote { color: var(--muted); font-size: 0.8rem; }

/* Pills and language badges */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.live { background: var(--live-soft); color: var(--live); }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .pill.live::before { animation: none; } }

.lang { display: inline-grid; place-items: center; min-width: 28px; height: 20px; padding: 0 6px; margin-right: 8px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); font: 600 0.72rem/1 var(--font-mono); letter-spacing: 0.04em; vertical-align: 1px; }
.lang.big { min-width: 40px; height: 32px; font-size: 0.85rem; margin: 0; }
.tag { font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); }

/* Table */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { text-align: right; }
.row-error { display: block; color: var(--bad); font-size: 0.82rem; margin-top: 4px; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 140px; }
.row > .field.narrow { flex: 0 1 96px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span:first-child, .field legend { font-size: 0.85rem; font-weight: 500; padding: 0; }
.field.narrow { max-width: 140px; }
input, select {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; width: 100%; min-height: 40px;
}
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-error, .form-error { color: var(--bad); font-size: 0.82rem; }
.form-error { background: var(--bad-soft); padding: 10px 12px; border-radius: var(--radius-sm); }
.field-error:empty { display: none; }

.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { width: 16px; height: 16px; min-height: 0; margin: 0 8px 0 0; accent-color: var(--accent); }

/* Buttons */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 16px;
  font: 500 0.9rem/1 var(--font-body); text-decoration: none; white-space: nowrap;
  color: var(--fg); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.button:hover { background: var(--surface-2); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.button.ghost:hover { background: var(--surface-2); color: var(--fg); }
.button.danger { color: var(--bad); }
.button.small { min-height: 30px; padding: 5px 10px; font-size: 0.8rem; }
.button.wide { width: 100%; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Two-column page: form on the left, list on the right. */
.split { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 24px; align-items: start; }
.split > .card:first-child { position: sticky; top: 24px; }
.section-title { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }

/* Event list */
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.event { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.events.past .event { box-shadow: none; background: transparent; }
.date-chip { width: 52px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); display: flex; flex-direction: column; align-items: center; padding: 6px 0; }
.date-chip span { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.date-chip strong { font-size: 1.35rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.events.past .date-chip { background: var(--surface-2); color: var(--muted); }
.event-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.event-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.event-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.langs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.lang-status { display: inline-flex; align-items: center; font-size: 0.78rem; color: var(--muted); padding: 2px 8px 2px 2px; border-radius: 6px; background: var(--surface-2); }
.lang-status .lang { margin-right: 6px; height: 18px; }
.lang-status.good { color: var(--good); }
.lang-status.warn { color: var(--warn); }
.lang-status.bad { color: var(--bad); }
.lang-status.live { color: var(--live); }

/* Feeds */
.feed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.feed { gap: 12px; padding: 16px 18px; }
.feed.inactive { opacity: 0.65; }
.feed-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.feed-name { display: flex; flex-direction: column; flex: 1 1 160px; min-width: 0; }
.feed-name .muted { font-size: 0.85rem; }
.feed-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.obs { margin: 0; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.obs div { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 8px; align-items: center; }
.obs dt { color: var(--muted); font-size: 0.82rem; }
.obs dd { margin: 0; display: flex; align-items: center; gap: 6px; min-width: 0; }
.obs code { background: var(--surface); flex: 1; }

/* Settings */
.settings-list { margin: 0; display: flex; flex-direction: column; }
.settings-list div { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.settings-list dt { color: var(--muted); }
.settings-list dd { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }

/* Login */
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; display: flex; flex-direction: column; gap: 18px; }

/* Phones and narrow tablets */
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .split > .card:first-child { position: static; }
}

@media (max-width: 720px) {
  body.app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    min-width: 0;
    position: sticky; top: 0; z-index: 10; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .nav { order: 3; flex-direction: row; width: 100%; min-width: 0; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  .nav a { padding: 7px 10px; white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: 12px; padding: 0; }
  .conn { font-size: 0; gap: 0; }
  .conn .dot { width: 10px; height: 10px; }
  .content { padding: 22px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); }
  h1 { font-size: 1.6rem; }
  .card { padding: 18px 16px; }
  .event { grid-template-columns: auto minmax(0, 1fr); }
  .event-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .settings-list div { grid-template-columns: 1fr; gap: 2px; }
  .feeds th:nth-child(2), .feeds td:nth-child(2) { display: none; }
}

/* Event page */
.back-link { color: var(--muted); text-decoration: none; font-size: 0.88rem; }
.back-link:hover { color: var(--fg); }
.steps { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }
.event-title a { color: inherit; text-decoration: none; }
.event-title a:hover { color: var(--accent); text-decoration: underline; }
.plain-link { color: inherit; text-decoration: none; }
.plain-link:hover { color: var(--accent); }

/* Imported calendars */
.source-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.source-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.source-list li:last-child { border-bottom: 1px solid var(--line); }
.source-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.source-main code { background: transparent; padding: 0; color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-source { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.add-source .field { flex: 1 1 160px; }
.add-source .field.grow { flex: 3 1 260px; }
@media (max-width: 720px) { .source-list li { grid-template-columns: minmax(0, 1fr) auto; } .source-list form { grid-column: 1 / -1; } }

/* Calendar suggestions */
.suggestions { display: flex; flex-direction: column; gap: 12px; }
.suggestion { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.suggestion:first-of-type { border-top: 0; }
.suggestion .date-chip { background: var(--surface-2); color: var(--fg); }
.suggestion-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.suggestion-actions { grid-column: 2; display: flex; gap: 6px; flex-wrap: wrap; }
.source-tag { font-size: 0.75rem; color: var(--muted); }

/* Today list */
.today-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.today-list.past { box-shadow: none; background: transparent; }
.today-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.today-row:first-child { border-top: 0; }
.today-time { font: 600 1.05rem/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--accent); }
.today-list.past .today-time { color: var(--muted); }
.today-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.today-main .muted { font-size: 0.85rem; }
