:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface2: #eef0f6;
  --line: #e3e6ee;
  --text: #171a26;
  --muted: #6b7185;
  --accent: #5b5bf0;
  --accent-soft: #ececff;
  --accent-text: #fff;
  --now: #ff4d5e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20,24,50,.06), 0 4px 14px rgba(20,24,50,.06);
  --font: Inter, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #181b25; --surface2: #222636; --line: #2b3042;
  --text: #eceef6; --muted: #8e94aa; --accent: #8083ff; --accent-soft: #25274a; --accent-text: #0f1117;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #181b25; --surface2: #222636; --line: #2b3042;
    --text: #eceef6; --muted: #8e94aa; --accent: #8083ff; --accent-soft: #25274a; --accent-text: #0f1117;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
#app { display: flex; flex-direction: column; height: 100vh; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* Kopfzeile: Marke + Navigation */
.menubar { display: flex; align-items: center; gap: 4px; padding: 10px 18px 0; }
.menubar::before { content: "▶ TV·Magazin"; font-weight: 800; font-size: 16px; letter-spacing: -.02em; margin-right: 18px;
  background: linear-gradient(90deg, var(--accent), #e04fd0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.menubar span { padding: 4px 10px; border-radius: 8px; color: var(--muted); cursor: default; }
.menubar span:hover { background: var(--surface2); color: var(--text); }

/* Werkzeugleiste */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 18px; flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
button { font: inherit; font-weight: 500; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
button:hover { background: var(--surface2); }
button:active { transform: scale(.97); }
button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.toolbar b { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0 7px; margin-left: 2px; font-weight: 600; }
button.active b { background: rgba(255,255,255,.25); color: inherit; }
.search input { font: inherit; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); width: 240px; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search { color: transparent; font-size: 0; }
.search input { font-size: 13px; }

.main { display: flex; flex: 1; min-height: 0; gap: 14px; padding: 0 18px 12px; }

/* Seitenleiste als Karte */
#sidebar { width: 220px; flex: none; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; padding: 14px; }
#sidebar h3 { margin: 16px 0 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#sidebar section:first-child h3 { margin-top: 0; }
.datenav { display: flex; align-items: center; gap: 6px; }
.datenav span { flex: 1; text-align: center; font-weight: 600; }
.datenav button { padding: 3px 10px; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-top: 8px; }
.days button { padding: 5px 0; border-radius: 10px; border-color: transparent; background: var(--surface2); font-size: 11px; text-align: center; }
.days button.active { background: var(--accent); }
.days small { display: block; font-size: 9px; opacity: .75; }
.timebtns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.timebtns button { padding: 5px 0; background: var(--surface2); border-color: transparent; }
.tree label { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.tree label:hover { background: var(--surface2); }
.tree input { accent-color: var(--accent); }
.tree .grp { font-weight: 600; margin-top: 8px; color: var(--muted); font-size: 11px; }
.tree .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; gap: 14px; }
.view { flex: 1; min-height: 0; overflow: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Programmtafel im Zeitungsstil */
#view-grid { --tint: 9%; --paper: #fbf8f0; --ink: #1b1a17; --ink2: #5a564c; --rule: #cfc8b6; background: var(--paper); color: var(--ink); font-family: var(--font); }
:root[data-theme="dark"] #view-grid { --paper: #141720; --ink: #eef0f7; --ink2: #9aa1b8; --rule: #2a2f42; --tint: 20%; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #view-grid { --paper: #141720; --ink: #eef0f7; --ink2: #9aa1b8; --rule: #2a2f42; --tint: 20%; } }
.np-head { position: sticky; top: 0; z-index: 5; display: grid; background: var(--paper); border-bottom: 3px double var(--ink); }
.np-head div { padding: 8px 10px 6px; border-left: 1px solid var(--rule); text-align: center; }
.np-head .corner { position: sticky; left: 0; z-index: 6; background: var(--paper); border-left: 0; }
.np-head span { display: block; font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.np-head small { color: var(--ink2); font-size: 11px; }
.np-grid { display: grid; position: relative; }
.np-timecol { position: sticky; left: 0; z-index: 3; background: var(--paper); border-right: 1px solid var(--rule); }
.np-timecol div { position: absolute; left: 0; right: 0; padding: 0 6px; font-weight: 700; font-size: 11px; font-variant-numeric: tabular-nums; transform: translateY(-7px); background: var(--paper); }
.np-timecol div:first-child { transform: none; }
.np-col { position: relative; border-left: 1px solid var(--rule); min-width: 0; }
.hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--rule); pointer-events: none; }
.np { position: absolute; left: 3px; right: 3px; overflow: hidden; display: grid; grid-template-columns: 38px 1fr; gap: 4px; padding: 5px 7px; cursor: pointer; border: 1px solid var(--rule); border-left: 3px solid var(--c); border-radius: 3px; background: color-mix(in srgb, var(--c) var(--tint), var(--paper)); }
.np:hover { background: color-mix(in srgb, var(--c) calc(var(--tint) * 2), var(--paper)); z-index: 2; }
.np.sel { background: color-mix(in srgb, var(--accent) 16%, var(--paper)); outline: 2px solid var(--accent); z-index: 2; }
.np.past { opacity: .5; filter: grayscale(1); color: var(--ink2); }
:root[data-theme="dark"] .np.past { opacity: .6; }
.np.dim { opacity: .18; }
.np.live { background: color-mix(in srgb, var(--now) calc(var(--tint) * .6), var(--paper)); border-left-color: var(--now); }
.np-now { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--now); z-index: 4; pointer-events: none; }
.np-now b { position: sticky; left: 0; display: inline-block; margin-top: -9px; transform: translateY(-1px); background: var(--now); color: #fff; font: 700 9px var(--font); padding: 1px 4px; border-radius: 0 3px 3px 0; }
.np.fav::after { content: "★"; position: absolute; right: 8px; top: 5px; color: #d98e00; }
.np-time { font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.np-title { font-weight: 700; font-size: 13.5px; line-height: 1.2; letter-spacing: -.005em; }
.np-title em { font: 700 9px var(--font); font-style: normal; background: var(--now); color: #fff; padding: 1px 5px; border-radius: 3px; vertical-align: 2px; letter-spacing: .05em; }
.np-sub { font: 600 10px var(--font); text-transform: uppercase; letter-spacing: .05em; color: var(--ink2); margin: 2px 0 3px; }
.np-sub i { display: inline-block; width: 7px; height: 7px; background: var(--c); margin-right: 5px; }
.np-img { display: block; width: 100%; height: 60px; object-fit: cover; margin: 3px 0 4px; border: 1px solid var(--rule); }
.np p { margin: 0; font-size: 12px; line-height: 1.38; hyphens: auto; text-align: left; }
.np p span { color: var(--ink2); }

/* Liste */
table.list { width: 100%; border-collapse: collapse; }
table.list th { position: sticky; top: 0; background: var(--surface); text-align: left; padding: 12px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); }
table.list td { padding: 9px 14px; border-bottom: 1px solid var(--line); }
table.list tr.row { cursor: pointer; }
table.list tr.row:hover td { background: var(--surface2); }
table.list tr.sel td { background: var(--accent-soft); }
.chip { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; color: var(--text);
  background: color-mix(in srgb, var(--c, #ccc) 35%, var(--surface)) !important; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Detail */
.detail { flex: none; min-height: 120px; max-height: 180px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; overflow: auto; }
.detail-empty { color: var(--muted); padding: 30px 0; text-align: center; }
.detail h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -.01em; }
.detail .meta { color: var(--muted); margin-bottom: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.detail p { margin: 4px 0; max-width: 80ch; }
.detail .actions { margin-top: 10px; display: flex; gap: 8px; }
.detail .actions button:first-child { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.statusbar { display: flex; gap: 16px; padding: 6px 20px 10px; color: var(--muted); font-size: 11px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

@media (max-width: 760px) {
  .main { position: relative; padding: 0 8px 8px; }
  #sidebar { position: absolute; z-index: 20; top: 0; bottom: 8px; left: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
  .search input { width: 140px; }
  .menubar, .toolbar { padding-left: 8px; padding-right: 8px; }
}

.d-img { display: block; width: 100%; max-width: 480px; height: auto; margin: 6px 0 8px; border: 1px solid var(--rule); }
#st-credit { opacity: .6; margin-right: 12px; }
