/* Dienstplan — Themes: Microsoft, Hell, Dunkel, Automatisch */

:root,
[data-theme="microsoft"] {
  --bg: #f3f2f1;
  --surface: #ffffff;
  --surface-2: #faf9f8;
  --border: #e1dfdd;
  --text: #201f1e;
  --text-muted: #605e5c;
  --accent: #0078d4;
  --accent-hover: #106ebe;
  --accent-soft: #deecf9;
  --success: #107c10;
  --success-soft: #dff6dd;
  --warn: #a16b00;
  --warn-soft: #fff4ce;
  --danger: #a4262c;
  --danger-soft: #fde7e9;
  --info-soft: #eff6fc;
  --shadow: 0 1.6px 3.6px rgba(0, 0, 0, .10), 0 .3px .9px rgba(0, 0, 0, .07);
  --radius: 4px;
  --radius-lg: 8px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="light"] {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e5e5e8;
  --text: #1b1b1f;
  --text-muted: #63636b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e5edff;
  --radius: 8px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg: #1b1a19;
  --surface: #252423;
  --surface-2: #2d2c2b;
  --border: #3b3a39;
  --text: #f3f2f1;
  --text-muted: #a19f9d;
  --accent: #4aa3f0;
  --accent-hover: #6cb6f5;
  --accent-soft: #123a5c;
  --success: #6bb700;
  --success-soft: #123512;
  --warn: #ffd34e;
  --warn-soft: #3d3316;
  --danger: #f1707b;
  --danger-soft: #4a1d21;
  --info-soft: #16324a;
  --shadow: 0 1.6px 3.6px rgba(0, 0, 0, .4);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #1b1a19;
    --surface: #252423;
    --surface-2: #2d2c2b;
    --border: #3b3a39;
    --text: #f3f2f1;
    --text-muted: #a19f9d;
    --accent: #4aa3f0;
    --accent-hover: #6cb6f5;
    --accent-soft: #123a5c;
    --success: #6bb700;
    --success-soft: #123512;
    --warn: #ffd34e;
    --warn-soft: #3d3316;
    --danger: #f1707b;
    --danger-soft: #4a1d21;
    --info-soft: #16324a;
    --shadow: 0 1.6px 3.6px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 8px; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar .brand { font-weight: 600; font-size: 15px; color: #fff; }
.topbar .brand:hover { text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar a { color: #fff; opacity: .92; }
.topbar .chip {
  background: rgba(255, 255, 255, .18);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
}

.nav-badge {
  display: inline-block; min-width: 16px; padding: 1px 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  line-height: 1.4; text-align: center;
}

/* ---------- Kompakter Header: Hamburger-Menü + Favoriten ---------- */
.menu-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .3);
  color: #fff; border-radius: var(--radius); padding: 5px 10px;
  font-size: 13px; font-family: inherit; cursor: pointer;
}
.menu-toggle:hover { background: rgba(255, 255, 255, .26); }
.menu-toggle .menu-icon, .menu-toggle .icon { font-size: 14px; line-height: 1; }

.favorites { display: flex; align-items: center; gap: 2px; overflow-x: auto; }
.favorites a {
  padding: 6px 10px; border-radius: var(--radius); font-size: 13px;
  color: #fff; opacity: .92; white-space: nowrap;
}
.favorites a:hover { background: rgba(255, 255, 255, .16); text-decoration: none; opacity: 1; }

.menu-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 90;
}
.app-menu {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 88vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, .22); z-index: 95;
  display: flex; flex-direction: column; overflow-y: auto;
}
/* [hidden] muss trotz .app-menu { display:flex } wirken — sonst steht das
   Menü beim ersten Rendern offen, bevor JS eingreift. */
.app-menu[hidden], .menu-backdrop[hidden] { display: none; }
.app-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
  position: sticky; top: 0; background: var(--surface);
}
.menu-close {
  background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer;
  color: var(--text-muted); padding: 0 4px;
}
.menu-close:hover { color: var(--text); }
.app-menu-body { padding: 4px 0 24px; }
.menu-group { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.menu-group:last-child { border-bottom: none; }
.menu-group h4 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 700;
}
.menu-group a { display: block; padding: 7px 6px; color: var(--text); font-size: 14px;
  border-radius: var(--radius); }
.menu-group a:hover { background: var(--surface-2); text-decoration: none; }
.menu-group a.active { color: var(--accent); font-weight: 600; }
.hide-lg { display: none; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; max-width: 420px; width: 100%; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.modal h2 { margin-top: 0; font-size: 16px; }

.container { max-width: 1500px; margin: 0 auto; padding: 16px; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px;
}
.page-head .spacer { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card.tight { padding: 12px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }

/* ---------- Kennzahlen ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .value { font-size: 22px; font-weight: 600; }
.stat .label { font-size: 12px; color: var(--text-muted); }
.pos { color: var(--success); }
.neg { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 12px; font-size: 13px; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Live-Zeiterfassung (P4.2) ---------- */
.time-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.time-status { flex-basis: 100%; font-size: 13px; color: var(--text-muted); }
.time-action-form { margin: 0; }
.time-action-btn {
  min-height: 52px; min-width: 160px; padding: 0 22px;
  font-size: 16px; font-weight: 600; justify-content: center; border-radius: var(--radius);
}
.btn.secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.time-hint { border-left: 4px solid var(--accent); }

@media (max-width: 640px) {
  .time-actions { flex-direction: column; align-items: stretch; }
  .time-action-form { width: 100%; }
  .time-action-btn { width: 100%; min-height: 56px; font-size: 17px; }
}

/* ---------- Formulare ---------- */
label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 3px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="color"], select, textarea {
  width: 100%; padding: 6px 8px; font-size: 13px; font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin-bottom: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.check input { width: auto; }
.option-row { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; font-size: 13px; }
.option-row input { width: auto; margin-top: 3px; }
.option-list { display: flex; flex-direction: column; gap: 2px; }
.option-list .option-row { border-bottom: 1px solid var(--border); padding: 8px 0; }
.option-list .option-row:last-child { border-bottom: none; }
details > summary { cursor: pointer; }
details[open] > summary { margin-bottom: 8px; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }

/* ---------- Meldungen ---------- */
.alert {
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px;
  border-left: 3px solid var(--accent); background: var(--info-soft);
}
.alert.success { border-color: var(--success); background: var(--success-soft); }
.alert.warning { border-color: var(--warn); background: var(--warn-soft); }
.alert.danger { border-color: var(--danger); background: var(--danger-soft); }
.alert.info { border-color: var(--accent); background: var(--info-soft); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-muted);
}
.badge.blocker { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--accent); border-color: var(--accent); }
.badge.ok { background: var(--success-soft); color: var(--success); border-color: var(--success); }

/* ---------- Kalender ---------- */
.calendar { width: 100%; border-collapse: collapse; table-layout: fixed; }
.calendar th {
  text-align: center; padding: 6px 2px; font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.calendar td {
  vertical-align: top; height: 96px; padding: 4px; border: 1px solid var(--border);
  background: var(--surface);
}
.calendar td.outside { background: var(--surface-2); opacity: .55; }
.calendar td.weekend { background: var(--surface-2); }
.calendar td.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.calendar td.selected { background: var(--accent-soft); }
.calendar .daynum { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 3px; }
.calendar a.daycell { display: block; color: inherit; height: 100%; }
.calendar a.daycell:hover { text-decoration: none; }

.shift-pill {
  display: block; border-radius: var(--radius); padding: 2px 6px; margin-bottom: 3px;
  font-size: 12px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.shift-pill .time { opacity: .9; font-size: 11px; }
.pill-absence {
  display: block; border-radius: var(--radius); padding: 2px 6px; margin-bottom: 3px;
  font-size: 12px; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn);
}
.pill-free { font-size: 12px; color: var(--text-muted); }
.pill-break {
  display: inline-block; border-radius: 8px; padding: 0 6px; font-size: 11px;
  background: var(--surface-2); border: 1px dashed var(--border); color: var(--text-muted);
}

/* ---------- Planungsraster ---------- */
.plan-grid { border-collapse: collapse; width: 100%; font-size: 12px; }
.plan-grid th, .plan-grid td { border: 1px solid var(--border); padding: 3px 4px; }
.plan-grid th.employee, .plan-grid td.employee {
  position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 160px;
  text-align: left;
}
.plan-grid td.day { min-width: 62px; text-align: center; vertical-align: top; }
.plan-grid td.weekend { background: var(--surface-2); }
.plan-grid td.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.plan-grid .cell-add { color: var(--text-muted); opacity: 0; font-size: 14px; }
.plan-grid td:hover .cell-add { opacity: 1; }
.plan-grid .locked::after { content: " ⚲"; }

.coverage-bar { display: flex; gap: 1px; align-items: stretch; height: 48px; }
.coverage-bar .bar {
  flex: 1; height: 100%; background: var(--surface-2); position: relative;
  border-radius: 2px 2px 0 0;
}
.coverage-bar .bar span {
  display: block; background: var(--accent); width: 100%; position: absolute; bottom: 0;
}

.board-col { min-width: 260px; }
.board-slot {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 8px; margin-bottom: 6px; background: var(--surface-2);
}
.board-open {
  border: 1px dashed var(--danger); color: var(--danger); border-radius: var(--radius);
  padding: 6px 8px; margin-bottom: 6px; text-align: center; font-size: 12px;
}

/* ---------- Tausch/Übernahme ---------- */
.exchange-options { display: flex; flex-direction: column; gap: 10px; }
.exchange-option {
  display: block; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; background: var(--surface);
}
.exchange-option:hover { background: var(--surface-2); }
.exchange-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.exchange-entry {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 10px;
}
.exchange-entry:last-child { margin-bottom: 0; }
.option-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.option-head input { width: auto; margin: 0; }
.swap-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.swap-pair:has(.swap-leg:only-child) { grid-template-columns: minmax(0, 1fr); }
.swap-leg { border-left: 3px solid var(--border); padding-left: 10px; }
.swap-leg.give { border-left-color: var(--warn); }
.swap-leg.take { border-left-color: var(--success); }
.swap-leg.plain { border-left-color: var(--accent); }
.swap-leg .leg-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin-bottom: 2px;
}
.swap-leg .leg-date { font-weight: 600; }
.swap-leg .leg-shift { margin: 2px 0; }
.plain-text { margin: 10px 0 0; font-size: 13px; }
.reason-groups { margin: 6px 0 0; padding-left: 18px; color: var(--text-muted); }

/* ---------- Mobile ---------- */
.bottom-nav { display: none; }

@media (max-width: 900px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .container { padding: 10px 10px 76px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 18px; }
  .calendar td { height: 62px; padding: 2px; }
  .calendar .daynum { font-size: 11px; }
  .swap-pair { grid-template-columns: minmax(0, 1fr); }
  .shift-pill { font-size: 11px; padding: 1px 4px; }
  .topbar .hide-sm { display: none; }
  .topbar { gap: 8px; padding: 0 10px; }
  .hide-lg { display: block; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 0 max(4px, env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; text-align: center; font-size: 11px; color: var(--text-muted);
    padding: 4px 2px; text-decoration: none; background: none; border: none;
    font-family: inherit; cursor: pointer;
  }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .bottom-nav .icon { display: block; font-size: 17px; line-height: 1.2; }
  table { font-size: 12px; }
}

@media print {
  .topbar, .app-menu, .menu-backdrop, .bottom-nav, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
