:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #dde2ea;
  --text: #1d2533;
  --muted: #667085;
  --accent: #1f5fd1;
  --accent-text: #ffffff;
  --accent-soft: #e6eefc;
  --ok: #1a8f4c;
  --ok-soft: #e3f5ea;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --bad: #c62f2f;
  --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1b212b;
    --surface-2: #232a36;
    --border: #2f3846;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --accent: #5b8ef0;
    --accent-text: #0b1220;
    --accent-soft: #1e2a44;
    --ok: #4cc27f;
    --ok-soft: #173325;
    --warn: #f0a543;
    --warn-soft: #3a2a12;
    --bad: #f07272;
    --bad-soft: #3d1c1c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.hidden, [hidden] { display: none !important; }
/* Unsichtbar, aber per Tastatur und Screenreader erreichbar */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.boot { padding: 40px; color: var(--muted); }

/* Kopfzeile */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--muted); font-size: 14px; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Schaltflächen und Formulare */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-ghost { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }

.icon-btn {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }

label { display: block; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label > input:not([type=checkbox]), label > select { display: block; width: 100%; margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-error { color: var(--bad); font-size: 14px; min-height: 0; }
.form-error:not(:empty) { margin-top: 10px; padding: 8px 10px; background: var(--bad-soft); border-radius: 7px; }
.hint { font-size: 13px; color: var(--muted); }

/* Karten */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-head > div { flex: 1; min-width: 0; }
.card-head h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 13px; color: var(--muted); }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

.dot { width: 11px; height: 11px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.status-line { font-size: 14px; font-weight: 600; }
.status-line.ok { color: var(--ok); }
.status-line.bad { color: var(--bad); }
.status-line.muted { color: var(--muted); font-weight: 400; }

.now-playing { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.now-playing .label { font-size: 12px; color: var(--muted); }
.now-playing .thumb-sm { width: 64px; height: 36px; }

.schedule { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  flex-direction: column;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.35;
}
.chip small { color: var(--muted); font-size: 12px; }
.chip.active { background: var(--accent-soft); color: var(--accent); }
.chip.active small { color: var(--accent); }

.warn, .info {
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 7px;
}
.warn { background: var(--warn-soft); color: var(--warn); }
.info { background: var(--accent-soft); color: var(--accent); }

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
}
.code { font-family: Consolas, "Courier New", monospace; font-weight: 700; letter-spacing: 1px; }

details.tech { font-size: 13px; color: var(--muted); }
details.tech summary { cursor: pointer; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; color: var(--text); word-break: break-all; }

.empty {
  text-align: center;
  padding: 48px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}
.empty h2 { color: var(--text); }

/* Playlists */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.split > * { min-width: 0; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list a {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.list a:last-child { border-bottom: 0; }
.list a:hover { background: var(--surface-2); }
.list a.active { background: var(--accent-soft); }
.list .sub { display: block; }
.badge-dirty { color: var(--warn); font-size: 12px; font-weight: 600; }

.editor { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.editor-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.title-input { font-size: 19px; font-weight: 600; flex: 1; min-width: 200px; }
.table-wrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
table.items th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.items td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.items tr.dragging { opacity: 0.4; }
table.items tr.drop-target td { border-top: 2px solid var(--accent); }
table.items tr.drop-after td { border-bottom: 2px solid var(--accent); }
table.items input[type=number] { width: 74px; }
table.items input[type=date] { width: 140px; }
.handle { cursor: grab; color: var(--muted); user-select: none; padding: 0 4px; }
.item-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-left: 6px; }
.badge.live { background: var(--ok-soft); color: var(--ok); }
.badge.planned { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.badge.expired { background: var(--bad-soft); color: var(--bad); }

/* Medien */
.dropzone:focus-within, .day input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone {
  position: relative;
  display: block;
  padding: 26px;
  margin-bottom: 16px;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
}
.dropzone small { color: var(--muted); font-size: 13px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

.uploads { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.upload { display: grid; grid-template-columns: 1fr 160px; gap: 10px; align-items: center; font-size: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.upload .msg { font-size: 12px; color: var(--muted); }
.upload.error .msg { color: var(--bad); }
.upload.done .msg { color: var(--ok); }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.media-card { padding: 0; overflow: hidden; gap: 0; }
.media-card .media-info { padding: 10px 12px 4px; }
.media-card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card .card-actions { padding: 6px 10px 10px; }
.media-card .warn { margin-top: 6px; }

.thumb, .thumb-sm {
  position: relative;
  background: #0b0f15;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #cfd6e2;
  flex: none;
}
.thumb { aspect-ratio: 16 / 9; width: 100%; }
.thumb-sm { width: 80px; height: 45px; border-radius: 5px; }
.thumb img, .thumb-sm img { width: 100%; height: 100%; object-fit: contain; }
.type-tag {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
}

.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; max-height: 55vh; overflow-y: auto; margin: 12px 0; }
.pick { position: relative; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: pointer; display: block; color: var(--text); }
.pick input { position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; z-index: 2; }
.pick.selected { border-color: var(--accent); }
.pick .name { font-size: 12px; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .order { position: absolute; z-index: 2; top: 6px; left: 6px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; border-radius: 999px; min-width: 22px; height: 22px; display: none; align-items: center; justify-content: center; }
.pick.selected .order { display: flex; }

/* Zeitplan */
.sched-rows { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.sched-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: flex-end;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}
.sched-row > label:first-child { flex: 1 1 200px; }
.sched-row .days { display: flex; gap: 3px; }
.sched-row .row-end { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.day { position: relative; }
.day input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.day span {
  display: inline-block;
  width: 30px;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.day input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.pair { display: flex; gap: 6px; }
.pair label input { width: 120px; }
.row-tools { display: flex; gap: 2px; align-self: center; }

/* Tabellen (Benutzer) */
table.plain { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.plain th, table.plain td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; }
table.plain th { font-size: 12px; color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.panel h2 { margin-bottom: 14px; }
.copy { display: flex; gap: 8px; align-items: center; margin: 6px 0 12px; }
.copy code, code.block { font-family: Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 6px 10px; border-radius: 6px; }
.help h3 { margin-top: 18px; }
.help li { margin-bottom: 4px; }

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
dialog.wide { width: min(1100px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 15, 25, 0.45); }
dialog form > label { margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.dialog-actions .left { margin-right: auto; display: flex; gap: 8px; }

/* Anmeldung */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { margin-bottom: 6px; }
.login p { margin-top: 0; color: var(--muted); font-size: 14px; }
.login label { margin-bottom: 12px; }
.login .btn { width: 100%; justify-content: center; margin-top: 6px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 18px;
  border-radius: 10px;
  background: #1d2533;
  color: #fff;
  font-size: 14px;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px; }
  .nav { order: 3; width: 100%; }
  main { padding: 16px; }
  .split { grid-template-columns: 1fr; }
  .sched-row { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
}
