:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b6f76;
  --border: #dedad3;
  --accent: #2f5d8a;
  --accent-hover: #244a6f;
  --accent-soft: #e5edf5;
  --ok: #2e7d4f;
  --ok-soft: #e3f2e8;
  --warn: #a8640c;
  --warn-soft: #fbefdc;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--accent); }

.hidden { display: none !important; }

/* Kopfzeile */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

.brand span { color: var(--accent); }

.topbar nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 15px; }
.topbar nav a { text-decoration: none; }
.topbar nav a:hover { text-decoration: underline; }
.user-name { color: var(--muted); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

h1 { font-size: 24px; margin: 4px 0 16px; font-weight: 600; }
h2 { font-size: 19px; margin: 28px 0 10px; font-weight: 600; }
h3 { font-size: 16px; margin: 0 0 8px; font-weight: 600; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.page-head h1 { margin-bottom: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Formulare */
label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 15px; }
label:first-child { margin-top: 0; }

input[type=text], input[type=password], select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea { resize: vertical; min-height: 80px; }

.hint { color: var(--muted); font-size: 14px; margin-top: 6px; }

button, .button {
  font: inherit;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:hover, .button:hover { background: #f7f6f3; }
button:disabled { opacity: .55; cursor: default; }

.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-hover); }
.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.success:hover { background: #256a42; }
.danger { color: var(--danger); border-color: #e6b8b4; }
.danger:hover { background: var(--danger-soft); }
.icon-button { min-width: 40px; padding: 6px 10px; }
.toggle[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.message { margin: 12px 0; padding: 10px 12px; border-radius: 8px; white-space: pre-line; }
.message.error { background: var(--danger-soft); color: var(--danger); }
.message.info { background: var(--accent-soft); color: var(--accent-hover); }
.message.ok { background: var(--ok-soft); color: var(--ok); }

/* Status-Badges */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.draft { background: #ecebe7; color: #55595f; }
.badge.released { background: var(--ok-soft); color: var(--ok); }
.badge.changed { background: var(--warn-soft); color: var(--warn); }

/* Übersicht */
.sunday-group { margin-bottom: 18px; }

.sunday-title {
  font-weight: 600;
  margin: 0 0 8px;
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.set-list { display: grid; gap: 8px; }

.set-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}

.set-item:hover { border-color: var(--accent); }
.set-item .set-main { flex: 1; min-width: 0; }
.set-item .set-title { font-weight: 600; overflow-wrap: anywhere; }
.set-item .set-meta { color: var(--muted); font-size: 14px; }

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .5);
}

details.past { margin-top: 28px; }
details.past > summary {
  cursor: pointer;
  font-size: 19px;
  font-weight: 600;
  padding: 6px 0;
}

/* Editor */
.editor {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

.editor-side { position: sticky; top: 72px; }

#referencesInput { min-height: 180px; font-family: inherit; }

.slides-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.slides { display: grid; gap: 12px; }

.slide-card {
  display: grid;
  grid-template-columns: minmax(200px, 360px) 1fr;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.slide-preview canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.slide-number { text-align: center; color: var(--muted); font-size: 14px; margin-top: 4px; }

.slide-fields { display: grid; gap: 8px; align-content: start; min-width: 0; }
.slide-fields .row { display: flex; gap: 6px; align-items: center; }
.slide-fields .row input { flex: 1; min-width: 0; }
.slide-fields textarea { min-height: 110px; }
.slide-tools { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 70%, rgba(244, 242, 238, 0));
  padding: 16px 0 8px;
  margin-top: 16px;
}

/* Editor nutzt fast die ganze Fensterbreite (body.wide nur auf edit.html). */
body.wide main, body.wide .topbar-inner { max-width: 92vw; }
body.wide .editor { grid-template-columns: 360px 1fr; }
body.wide .slide-card { grid-template-columns: minmax(260px, 520px) 1fr; }
body.wide .slide-fields textarea { min-height: 170px; }

/* Tabellen (Admin) */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 14px; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; align-items: end; }
.checkbox { display: flex; gap: 8px; align-items: center; font-weight: normal; margin: 14px 0 8px; }
.token-box {
  font-family: Consolas, "Courier New", monospace;
  background: #fffbe6;
  border: 1px solid #e8d48a;
  padding: 10px;
  border-radius: 8px;
  overflow-wrap: anywhere;
  user-select: all;
}

/* Login */
.login-wrap { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.login-wrap h1 { text-align: center; }
.login-wrap button { width: 100%; margin-top: 18px; }

@media (max-width: 800px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .slide-card { grid-template-columns: 1fr; }
  body.wide .editor, body.wide .slide-card { grid-template-columns: 1fr; }
  body.wide main, body.wide .topbar-inner { max-width: none; }
  .sticky-actions { position: static; background: none; }
  h1 { font-size: 21px; }
}

/* Dialoge (confirmDialog/promptDialog in common.js) */
dialog.modal {
  padding: 0;
  border: none;
  border-radius: 12px;
  width: min(440px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .22), 0 2px 8px rgba(0, 0, 0, .08);
}

dialog.modal::backdrop {
  background: rgba(31, 35, 40, .45);
  backdrop-filter: blur(2px);
}

dialog.modal[open] { animation: modal-in .16s ease-out; }
dialog.modal[open]::backdrop { animation: backdrop-in .16s ease-out; }

@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes backdrop-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  dialog.modal[open], dialog.modal[open]::backdrop { animation: none; }
}

.modal-body { padding: 22px 24px 20px; }
.modal-title { font-size: 19px; font-weight: 600; margin: 0 0 8px; }
.modal-text { margin: 0; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.modal-field { margin: 16px 0 0; }
.modal-field input { margin-top: 6px; font-weight: normal; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.danger-solid:hover { background: #962019; }

.spacer { flex: 1; }
.no-margin { margin: 0; }
.login-wrap h1 span { color: var(--accent); }
#fetchButton { margin-top: 14px; width: 100%; }
.bold-toggle { font-weight: 700; }
.italic-toggle { font-style: italic; font-family: Georgia, serif; }
.narrow { max-width: 460px; }
.section-card { margin-bottom: 20px; }
.top-gap { margin-top: 16px; }
