* { box-sizing: border-box; }
:root {
  --bg: #f8fafc;            /* slate-50, wie Landing */
  --fg: #0f172a;            /* slate-900 */
  --muted: #64748b;         /* slate-500 */
  --brand: #5f8530;         /* primary-600 (Landing) */
  --brand-dark: #4a6826;    /* primary-700 (Landing) */
  --brand-light: #f3f8eb;   /* primary-50 */
  --border: #e2e8f0;        /* slate-200 */
  --card: #ffffff;
  --ok: #5f8530;            /* gleicher Grün-Ton fürs OK-Feedback */
  --err: #b91c1c;           /* red-700 */
}
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--fg); }
[hidden] { display: none !important; }

header#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 2rem; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--fg); font-size: 1.1rem; text-decoration: none; }
.brand .logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: .375rem;
  background: var(--brand); color: white; font-weight: 700; font-size: .95rem;
}
.brand a { color: inherit; text-decoration: none; }
.brand .sep { color: var(--muted); margin: 0 .25rem; font-weight: 400; }
.brand .kanzlei { color: var(--muted); font-weight: 500; }
.meta { display: flex; gap: 1rem; align-items: center; color: var(--muted); }
.badge { background: var(--brand); color: white; padding: 2px 8px; border-radius: 10px; font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; }
/* color:white muss explizit gesetzt sein — sonst überschreibt die globale
   .muted-Helper-Klasse (color: var(--muted)) und macht den Text unleserlich. */
.badge.muted { background: var(--muted); color: white; }
button.link { background: none; border: none; color: var(--brand); cursor: pointer; text-decoration: underline; padding: 0; }
button.link:hover { color: var(--brand-dark); }

main { max-width: 880px; margin: 2rem auto; padding: 0 1.5rem; }
main.card {
  max-width: 460px; margin-top: 6rem; padding: 2.25rem; background: var(--card);
  border-radius: 12px; box-shadow: 0 4px 24px rgba(15,23,42,0.08);
  border: 1px solid var(--border);
}
main.card .brand-header {
  display: flex; flex-direction: column; align-items: center; gap: .65rem; margin-bottom: 1.5rem;
}
main.card .brand-header .logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 3rem; height: 3rem; border-radius: .5rem;
  background: var(--brand); color: white; font-weight: 700; font-size: 1.4rem;
  box-shadow: 0 2px 8px rgba(95,133,48,0.25);
}
main.card .brand-header .wordmark { font-weight: 600; font-size: 1.15rem; color: var(--fg); }
main.card h1 { font-size: 1.5rem; text-align: center; margin-bottom: .25rem; }
main.card > p.muted { text-align: center; }
h1, h2, h3 { color: var(--fg); margin-top: 0; }
p.muted, small.hint, .muted { color: var(--muted); font-size: 0.9rem; }

form#login-form, form#activate-form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1.25rem; }
input, select, button, textarea {
  font: inherit; padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--fg);
}
button { background: var(--brand); color: white; cursor: pointer; border-color: var(--brand); transition: background .15s; }
button:hover { background: var(--brand-dark); }
button[type="submit"] { padding: .7rem 1rem; }
input[readonly] { background: var(--bg); color: var(--muted); }

nav.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
nav.tabs .tab {
  background: transparent; color: var(--muted); border: none; padding: .75rem 1.25rem;
  border-bottom: 2px solid transparent; border-radius: 0; cursor: pointer; font-weight: 500;
}
nav.tabs .tab:hover { color: var(--fg); }
nav.tabs .tab.active { color: var(--brand); border-bottom-color: var(--brand); }

section.tab-pane { display: none; background: var(--card); padding: 1.5rem 2rem; border-radius: 12px; box-shadow: 0 1px 8px rgba(20,30,60,0.05); }
section.tab-pane.active { display: block; }

form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem 1.5rem; margin-top: 1rem; }
form.grid label { display: flex; flex-direction: column; gap: .35rem; }
form.grid label span { font-weight: 500; }
form.grid .section-title { grid-column: 1 / -1; margin: 1rem 0 0; padding-bottom: .35rem; border-bottom: 1px solid var(--border); font-size: 1.05rem; color: var(--brand); }
form.grid .section-title:first-child { margin-top: 0; }
form.grid fieldset { grid-column: 1 / -1; border: 1px solid var(--border); border-radius: 6px; padding: .75rem 1rem; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; }
form.grid fieldset legend { color: var(--muted); padding: 0 .35rem; font-size: .9rem; }
form.grid fieldset label.inline { margin-right: 0; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; margin-right: 1rem; font-weight: normal; }
.actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; }
.status { font-size: .9rem; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: .65rem .5rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); font-size: .9rem; }
#calls-table tbody tr { cursor: pointer; }
#calls-table tbody tr:hover { background: var(--bg); }
.audio-yes { color: var(--ok); }
.audio-no  { color: var(--muted); }
.call-live td { font-weight: 600; }
.live-dot {
  display: inline-block; width: .65rem; height: .65rem; border-radius: 50%;
  background: var(--err); margin-right: .35rem; vertical-align: middle;
  animation: live-pulse 1.4s infinite ease-in-out;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.75); }
}

.staff-source { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0 1.5rem; }
.staff-source label.inline { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.staff-source label.inline:hover { background: var(--bg); }
.staff-source label.inline b { color: var(--fg); }
.staff-source small { margin-left: 1.4rem; }

.hint-box { background: var(--brand-light); border-left: 3px solid var(--brand); padding: .85rem 1rem; border-radius: 4px; margin-bottom: 1rem; font-size: .95rem; }
.hint-box pre { background: var(--card); padding: .5rem .75rem; border-radius: 4px; white-space: pre-wrap; word-break: break-all; font-size: .85rem; max-height: 6rem; overflow: auto; }

label.block { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1.5rem; }
label.block span { font-weight: 500; }

#staff-table input, #users-table input, #users-table select {
  width: 100%; padding: .4rem .5rem; font-size: .9rem;
}
#staff-table .col-del, #users-table .col-del { width: 2rem; text-align: center; }
.del-btn { background: none; color: var(--err); border: 1px solid transparent; padding: .2rem .4rem; cursor: pointer; font-size: 1.1rem; }
.del-btn:hover { border-color: var(--err); border-radius: 4px; }

#staff-add { background: transparent; color: var(--brand); border: 1px dashed var(--brand); margin-top: .25rem; }
#staff-add:hover { background: var(--bg); color: var(--brand-dark); }

/* Settings-Form: Hints und Spezial-Buttons über volle Breite */
form.grid small.hint-full { grid-column: 1 / -1; margin-top: -.75rem; }
form.grid table { grid-column: 1 / -1; }
form.grid #overrides-add, form.grid .link-btn {
  grid-column: 1 / -1; background: transparent; color: var(--brand);
  border: 1px dashed var(--brand); padding: .5rem 1rem; cursor: pointer; font-weight: 500;
  border-radius: 6px;
}
form.grid #overrides-add:hover { background: var(--bg); color: var(--brand-dark); }

#schedule-table input[type="time"],
#overrides-table input[type="time"],
#overrides-table input[type="date"] {
  padding: .35rem .5rem; font-size: .9rem; width: 100%;
}
#schedule-table td:first-child { font-weight: 500; color: var(--fg); width: 28%; }
#schedule-table td.col-closed,
#overrides-table td.col-closed { width: 6rem; text-align: center; }
#schedule-table input.sched-closed:checked ~ * { opacity: .3; }
#schedule-table tr.is-closed input[type="time"] { opacity: .35; background: var(--bg); }
#overrides-table td.col-del { width: 2.5rem; text-align: center; }

/* Dashboard */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.25rem; }
.dash-grid .card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem 1.5rem; box-shadow: 0 1px 4px rgba(15,23,42,0.04);
}
.dash-grid .card h3 { margin: 0 0 .75rem; font-size: 1rem; color: var(--brand-dark); }
.dash-grid .card.card-wide { grid-column: 1 / -1; }
.dash-grid .card.card-tarif { grid-column: span 2; }
.dash-grid .card .hint { font-size: .85rem; margin: 0 0 1rem; }

.tarif-plan { font-size: 1.5rem; font-weight: 600; color: var(--fg); margin-bottom: .25rem; text-transform: capitalize; }
.tarif-period { font-size: .85rem; margin-bottom: 1rem; }

.meter { margin-top: .5rem; }
.meter-bar { background: var(--bg); border-radius: 6px; height: 12px; overflow: hidden; }
.meter-fill { background: var(--brand); height: 100%; width: 0%; transition: width .4s; }
.meter-fill.over { background: var(--err); }
.meter-labels { display: flex; justify-content: space-between; margin-top: .5rem; font-size: .9rem; }

.overflow { margin-top: 1rem; padding: .75rem 1rem; background: #fef2f2; border-left: 3px solid var(--err); border-radius: 4px; }
.overflow-min { color: var(--err); font-size: 1.1rem; }
.overflow-eur { font-size: .9rem; margin-top: .25rem; }

.stats-row { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.stats-row > div { flex: 1; min-width: 5rem; }
.stat-num { font-size: 1.75rem; font-weight: 600; color: var(--brand-dark); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.kpi { margin-top: 1rem; display: flex; justify-content: space-between; font-size: .9rem; padding-top: .75rem; border-top: 1px solid var(--border); }

.heatmap { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 80px; }
.heatmap > div {
  background: var(--brand); border-radius: 2px 2px 0 0; min-height: 4px;
  position: relative;
}
.heatmap > div[title]:hover { background: var(--brand-dark); }
.heatmap-labels { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; margin-top: .25rem; font-size: .7rem; color: var(--muted); }
.heatmap-labels > div { text-align: center; }

.outcome-table { width: 100%; }
.outcome-table td { padding: .35rem .5rem; border-bottom: 1px solid var(--border); }
.outcome-table td:last-child { text-align: right; font-weight: 600; }
.outcome-table td:last-child.muted { font-weight: normal; }

/* Vorlage-Fieldset */
form.grid fieldset.bulk-fill {
  grid-column: 1 / -1; background: var(--brand-light); border-color: var(--brand);
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center;
}
form.grid fieldset.bulk-fill legend { color: var(--brand-dark); font-weight: 600; }
form.grid fieldset.bulk-fill label.inline { gap: .5rem; }
form.grid fieldset.bulk-fill label.inline input[type="time"] { padding: .35rem .5rem; }
.bulk-buttons { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto; }
.bulk-buttons button {
  background: white; color: var(--brand-dark); border: 1px solid var(--brand);
  padding: .4rem .85rem; font-size: .85rem; font-weight: 500;
}
.bulk-buttons button:hover { background: var(--brand); color: white; }

#detail-overlay {
  position: fixed; inset: 0; background: rgba(20,30,60,0.45); display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.detail-card {
  background: var(--card); border-radius: 12px; max-width: 720px; width: 100%; max-height: 90vh; overflow: auto; padding: 1.75rem; position: relative;
}
.detail-card .close { position: absolute; top: .5rem; right: .75rem; background: none; border: none; color: var(--muted); font-size: 1.5rem; cursor: pointer; padding: 0 .5rem; }
.detail-card .close:hover { color: var(--fg); }
.detail-card audio { width: 100%; margin-bottom: 1rem; }
.detail-card pre { background: var(--bg); padding: 1rem; border-radius: 6px; white-space: pre-wrap; word-break: break-word; max-height: 60vh; overflow: auto; }
code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }

/* ============================================================
 * Responsive / Mobile-Anpassungen
 * ============================================================ */

/* Sicherheitsnetz: kein horizontaler Page-Scroller mehr — Inhalte die
   trotzdem rauslaufen wandern in scrollbare Container (siehe unten). */
html, body { max-width: 100vw; overflow-x: hidden; }

/* Tabellen-Wrapper: schützt vor zu breiten Tabellen ohne Layout-Hacks. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }

@media (max-width: 720px) {
  main { padding: 1rem .75rem; margin: .5rem auto; max-width: 100%; }
  main.card { margin-top: 2rem; padding: 1.5rem; }

  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 1rem; }

  /* Topbar einklappen */
  header#topbar { padding: .65rem 1rem; flex-direction: column; align-items: flex-start; gap: .5rem; }
  header#topbar .meta { flex-direction: row; flex-wrap: wrap; align-items: center; gap: .65rem; font-size: .85rem; }
  .brand { font-size: 1rem; }
  .brand .sep { display: none; }
  .brand .kanzlei { display: block; font-size: .8rem; margin-top: .1rem; }

  /* Tabs: horizontal scrollbar */
  nav.tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; padding-bottom: .15rem; }
  nav.tabs .tab { white-space: nowrap; flex-shrink: 0; padding: .65rem 1rem; font-size: .9rem; }

  /* Formulare einspaltig */
  form.grid { grid-template-columns: 1fr; gap: .75rem 1rem; }
  form.grid fieldset { flex-direction: column; align-items: stretch; }
  /* Ausnahme: Vorlage-Übernehmen-Box — Öffnung + Schließung nebeneinander 50/50 */
  form.grid fieldset.bulk-fill { flex-direction: row; flex-wrap: wrap; align-items: end; gap: .5rem; }
  form.grid fieldset.bulk-fill label.inline {
    display: flex; flex-direction: column; align-items: stretch;
    gap: .25rem; flex: 1 1 0; min-width: 0;
  }
  form.grid fieldset.bulk-fill label.inline span { font-size: .8rem; color: var(--muted); }
  form.grid fieldset.bulk-fill label.inline input[type="time"] {
    width: 100%; min-width: 0; padding: .35rem .5rem; font-size: .9rem;
  }
  form.grid fieldset.bulk-fill .bulk-buttons { width: 100%; flex-direction: column; gap: .35rem; }
  .actions { flex-direction: column; align-items: stretch; gap: .5rem; }
  .actions button, .actions input, .actions select { width: 100%; }

  /* Dashboard-Karten 1-spaltig */
  .dash-grid { grid-template-columns: 1fr; gap: 1rem; }
  .dash-grid .card.card-wide,
  .dash-grid .card.card-tarif { grid-column: 1; }
  /* Stats-Row bleibt horizontal — .stats-row hat flex-wrap+min-width,
     wrappt von selbst wenn's nicht passt. Nur Gap kompakter. */
  .stats-row { gap: .75rem; }
  .stats-row > div { min-width: 4rem; }

  /* Heatmap kompakter */
  .heatmap { height: 60px; }

  /* Tabellen scrollbar im Tab-Container — Fallback für Tables ohne Mobile-Layout */
  section.tab-pane { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table th, table td { white-space: normal; word-break: break-word; padding: .5rem .35rem; font-size: .85rem; }

  /* Schedule- und Overrides-Tabelle: pro Zeile = eine Karte (Card-View)
     Verhindert horizontalen Scroller bei vielen Spalten mit Time/Date-Inputs. */
  #schedule-table { display: block; }
  #schedule-table thead { display: none; }
  #schedule-table tbody, #schedule-table tr { display: block; width: 100%; }
  #schedule-table tr {
    background: var(--bg); border-radius: 6px;
    padding: .65rem .75rem; margin-bottom: .5rem;
    display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .75rem;
  }
  #schedule-table td { display: block; padding: 0; border: none; font-size: .85rem; }
  #schedule-table td:first-child {
    grid-column: 1 / -1; font-weight: 600; color: var(--fg);
    border-bottom: 1px solid var(--border); padding-bottom: .35rem;
  }
  #schedule-table td:nth-child(2)::before { content: "Öffnung"; }
  #schedule-table td:nth-child(3)::before { content: "Schließung"; }
  #schedule-table td:nth-child(2)::before,
  #schedule-table td:nth-child(3)::before {
    display: block; color: var(--muted); font-size: .7rem;
    text-transform: uppercase; letter-spacing: .4px; margin-bottom: .2rem;
  }
  #schedule-table td.col-closed {
    grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem;
  }
  #schedule-table td.col-closed::before {
    content: "Geschlossen"; color: var(--muted); font-size: .85rem; order: 2;
    white-space: nowrap;
  }
  #schedule-table td.col-closed input { order: 1; }
  #schedule-table input[type="time"] { padding: .35rem .5rem; font-size: .9rem; width: 100%; }

  /* Sondertage / Overrides: gleiches Card-Pattern, 6 Spalten anders verteilt */
  #overrides-table { display: block; }
  #overrides-table thead { display: none; }
  #overrides-table tbody, #overrides-table tr { display: block; width: 100%; }
  #overrides-table tr {
    background: var(--bg); border-radius: 6px;
    padding: .65rem .75rem; margin-bottom: .5rem;
    display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .75rem;
    position: relative;
  }
  #overrides-table td { display: block; padding: 0; border: none; font-size: .85rem; }
  /* Datum + Geschlossen oben nebeneinander */
  #overrides-table td:nth-child(1)::before { content: "Datum"; }
  #overrides-table td:nth-child(2)::before { content: "Öffnung"; }
  #overrides-table td:nth-child(3)::before { content: "Schließung"; }
  #overrides-table td:nth-child(1)::before,
  #overrides-table td:nth-child(2)::before,
  #overrides-table td:nth-child(3)::before {
    display: block; color: var(--muted); font-size: .7rem;
    text-transform: uppercase; letter-spacing: .4px; margin-bottom: .2rem;
  }
  #overrides-table td.col-closed { display: flex; align-items: center; gap: .5rem; }
  #overrides-table td.col-closed::before {
    content: "Geschlossen"; color: var(--muted); font-size: .85rem; order: 2;
    white-space: nowrap;
  }
  #overrides-table td.col-closed input { order: 1; }
  /* Grund (5. Spalte) volle Breite */
  #overrides-table td:nth-child(5) {
    grid-column: 1 / -1;
  }
  #overrides-table td:nth-child(5)::before {
    content: "Grund (optional)"; display: block; color: var(--muted);
    font-size: .7rem; text-transform: uppercase; letter-spacing: .4px; margin-bottom: .2rem;
  }
  /* Lösch-Button (6. Spalte) als Karten-Eck-Element */
  #overrides-table td.col-del {
    position: absolute; top: .35rem; right: .5rem; width: auto;
  }
  #overrides-table input[type="time"],
  #overrides-table input[type="date"],
  #overrides-table input[type="text"] {
    padding: .35rem .5rem; font-size: .9rem; width: 100%;
  }

  /* Modal: fast Vollbild */
  .detail-card, #detail-overlay { padding: .5rem; }
  .detail-card { padding: 1.25rem; max-height: 95vh; border-radius: 8px; }
}
