/* ==========================================================================
   BayFood Abwesenheitsplaner
   Farb-Tokens: validierte Palette (hell + dunkel), siehe README
   ========================================================================== */

:root {
  --page:           #f9f9f7;
  --surface:        #fcfcfb;
  --ink:            #0b0b0b;
  --ink-secondary:  #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --border:         rgba(11, 11, 11, 0.10);
  --baseline:       #c3c2b7;

  --accent:         #2a78d6;
  --accent-ink:     #ffffff;
  --danger:         #d03b3b;
  --danger-ink:     #ffffff;
  --good-text:      #006300;

  /* Abwesenheitsarten (kategoriale Palette, CVD-geprüft) */
  --type-U-bg:  #2a78d6;  --type-U-ink:  #ffffff;   /* Urlaub */
  --type-K-bg:  #e34948;  --type-K-ink:  #ffffff;   /* Krank */
  --type-SU-bg: #1baf7a;  --type-SU-ink: #0b0b0b;   /* Sonderurlaub */
  --type-FB-bg: #4a3aa7;  --type-FB-ink: #ffffff;   /* Fortbildung */
  --type-SO-bg: #eb6834;  --type-SO-ink: #0b0b0b;   /* Sonstiges */

  --weekend-bg:  #f0efec;
  --holiday-bg:  #e4ebf6;
  --today-ring:  #2a78d6;

  /* Sequenzielle Blautöne für die Monatsmatrix */
  --heat-1: #cde2fb;  --heat-1-ink: #0b0b0b;
  --heat-2: #9ec5f4;  --heat-2-ink: #0b0b0b;
  --heat-3: #5598e7;  --heat-3-ink: #ffffff;
  --heat-4: #256abf;  --heat-4-ink: #ffffff;

  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 6px 20px rgba(11, 11, 11, 0.06);
  --radius: 12px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page:           #101010;
    --surface:        #1d1d1b;
    --ink:            #f6f6f2;
    --ink-secondary:  #cfcec3;
    --ink-muted:      #9c9a92;
    --grid:           #343431;
    --border:         rgba(255, 255, 255, 0.14);
    --baseline:       #4c4b45;

    --accent:         #3987e5;
    --accent-ink:     #ffffff;
    --danger:         #d03b3b;
    --good-text:      #34c246;

    --type-U-bg:  #3987e5;  --type-U-ink:  #ffffff;
    --type-K-bg:  #e66767;  --type-K-ink:  #1a1a19;
    --type-SU-bg: #199e70;  --type-SU-ink: #0b0b0b;
    --type-FB-bg: #9085e9;  --type-FB-ink: #1a1a19;
    --type-SO-bg: #d95926;  --type-SO-ink: #0b0b0b;

    --weekend-bg:  #141413;
    --holiday-bg:  #223554;
    --today-ring:  #6aa9f7;

    --heat-1: #184f95;  --heat-1-ink: #ffffff;
    --heat-2: #1c5cab;  --heat-2-ink: #ffffff;
    --heat-3: #2a78d6;  --heat-3-ink: #ffffff;
    --heat-4: #6da7ec;  --heat-4-ink: #0b0b0b;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

/* ---------- Kopfzeile ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 19px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--ink-secondary); }

.tabs {
  display: flex;
  gap: 2px;
  background: color-mix(in srgb, var(--grid) 55%, transparent);
  padding: 4px;
  border-radius: 999px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { background: var(--surface); color: var(--ink); }
.tab.active { background: var(--accent); color: var(--accent-ink); }

.header-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease, filter 0.15s ease;
}
.btn:hover { background: var(--grid); }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.1); background: var(--accent); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn-danger:hover { filter: brightness(1.1); background: var(--danger); }

.btn-ghost { background: transparent; }

.btn-nav {
  padding: 5px 11px;
  font-size: 16px;
  line-height: 1;
}

/* ---------- Hauptbereich ---------- */

main { padding: 26px 28px 48px; max-width: 1500px; margin: 0 auto; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar h1 {
  font-size: 19px;
  margin: 0 6px;
  min-width: 170px;
  text-align: center;
}

.toolbar .spacer, .dialog-actions .spacer { flex: 1; }

/* Legende */
.legend { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--ink-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch {
  width: 20px; height: 15px;
  border-radius: 4px;
  display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700;
}
.legend-swatch.plain { border: 1px solid var(--baseline); }

/* ---------- Karten & Kacheln ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 22px;
}

.card h2 { font-size: 16px; margin: 0 0 12px; }
.card .card-note { font-size: 13px; color: var(--ink-secondary); margin: 8px 0 0; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
}
.stat-tile .stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.stat-tile .stat-label { font-size: 13px; color: var(--ink-secondary); margin-top: 2px; }

/* ---------- Tabellen (allgemein) ---------- */

.table-wrap { overflow-x: auto; }

table.data {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td {
  border: 1px solid var(--grid);
  padding: 8px 12px;
  text-align: left;
}
table.data th {
  background: var(--page);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-secondary);
}
table.data td.num, table.data th.num { text-align: right; }
table.data td.negative { color: var(--danger); font-weight: 700; }

/* ---------- Plantafel (Monatskalender) ---------- */

.plan-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table.plan {
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

table.plan th, table.plan td {
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  padding: 0;
}

table.plan th.emp-col, table.plan td.emp-col {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--surface);
  min-width: 160px;
  max-width: 220px;
  padding: 6px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 2px solid var(--baseline);
}

table.plan thead th {
  background: var(--page);
  font-weight: 500;
  color: var(--ink-secondary);
}
table.plan thead th.emp-col { z-index: 6; background: var(--page); }

table.plan .day-head {
  min-width: 34px;
  text-align: center;
  padding: 4px 2px;
  font-size: 12px;
  line-height: 1.2;
}
.day-head .dnum { display: block; font-weight: 700; color: var(--ink); }
.day-head .dow { display: block; font-size: 10px; }
.day-head .holiday-dot {
  display: block; width: 5px; height: 5px;
  border-radius: 50%; background: var(--accent);
  margin: 2px auto 0;
}

table.plan td.cell {
  min-width: 36px;
  height: 36px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: outline-color 0.1s ease;
}
table.plan td.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
table.plan tbody tr:hover td.emp-col { color: var(--accent); }

.weekend { background: var(--weekend-bg); }
.holiday { background: var(--holiday-bg); }

table.plan .today { box-shadow: inset 0 0 0 2px var(--today-ring); }
table.plan thead th.today { box-shadow: inset 0 0 0 2px var(--today-ring); }

/* Abwesenheits-Zellen: 2px Abstand zur Nachbarzelle über inset-Schatten */
td.cell.type-U  { background: var(--type-U-bg);  color: var(--type-U-ink); }
td.cell.type-K  { background: var(--type-K-bg);  color: var(--type-K-ink); }
td.cell.type-SU { background: var(--type-SU-bg); color: var(--type-SU-ink); }
td.cell.type-FB { background: var(--type-FB-bg); color: var(--type-FB-ink); }
td.cell.type-SO { background: var(--type-SO-bg); color: var(--type-SO-ink); }

.legend-swatch.type-U  { background: var(--type-U-bg);  color: var(--type-U-ink); }
.legend-swatch.type-K  { background: var(--type-K-bg);  color: var(--type-K-ink); }
.legend-swatch.type-SU { background: var(--type-SU-bg); color: var(--type-SU-ink); }
.legend-swatch.type-FB { background: var(--type-FB-bg); color: var(--type-FB-ink); }
.legend-swatch.type-SO { background: var(--type-SO-bg); color: var(--type-SO-ink); }

/* Halbe Tage: abgeschwächte Typfarbe + ½ im Kürzel */
td.cell.half.type-U  { background: color-mix(in srgb, var(--type-U-bg) 40%, var(--surface));  color: var(--ink); }
td.cell.half.type-K  { background: color-mix(in srgb, var(--type-K-bg) 40%, var(--surface));  color: var(--ink); }
td.cell.half.type-SU { background: color-mix(in srgb, var(--type-SU-bg) 40%, var(--surface)); color: var(--ink); }
td.cell.half.type-FB { background: color-mix(in srgb, var(--type-FB-bg) 40%, var(--surface)); color: var(--ink); }
td.cell.half.type-SO { background: color-mix(in srgb, var(--type-SO-bg) 40%, var(--surface)); color: var(--ink); }

/* Summenzeile */
table.plan tr.sum-row td, table.plan tr.sum-row th {
  border-top: 2px solid var(--baseline);
  background: var(--page);
  font-size: 12px;
  color: var(--ink-secondary);
  text-align: center;
  height: 28px;
}
table.plan tr.sum-row th.emp-col { font-weight: 600; text-align: left; }
table.plan tr.sum-row td.crit { background: var(--danger); color: var(--danger-ink); font-weight: 700; }

/* Chips (Art-Kennzeichnung in Liste/Matrix) */
.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.chip.type-U  { background: var(--type-U-bg);  color: var(--type-U-ink); }
.chip.type-K  { background: var(--type-K-bg);  color: var(--type-K-ink); }
.chip.type-SU { background: var(--type-SU-bg); color: var(--type-SU-ink); }
.chip.type-FB { background: var(--type-FB-bg); color: var(--type-FB-ink); }
.chip.type-SO { background: var(--type-SO-bg); color: var(--type-SO-ink); }

/* Monatsmatrix */
td.heat-1 { background: var(--heat-1); color: var(--heat-1-ink); }
td.heat-2 { background: var(--heat-2); color: var(--heat-2-ink); }
td.heat-3 { background: var(--heat-3); color: var(--heat-3-ink); }
td.heat-4 { background: var(--heat-4); color: var(--heat-4-ink); }

/* ---------- Heute-Leiste ---------- */

.today-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 9px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.today-panel strong { color: var(--ink); }
.today-all-present { color: var(--good-text); font-weight: 600; }
.today-note { color: var(--ink-secondary); }
.today-absent { display: inline-flex; align-items: center; gap: 6px; }
.today-until { color: var(--ink-muted); font-size: 13px; }

/* ---------- Formulare ---------- */

label { display: block; font-size: 13px; color: var(--ink-secondary); margin-bottom: 10px; }
label .optional { color: var(--ink-muted); }

input[type="text"], input[type="date"], input[type="number"], select {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 7px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--baseline);
  border-radius: 6px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

input[type="date"] { cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.75;
}
@media (prefers-color-scheme: dark) {
  /* Kalender-Symbol im Dunkelmodus aufhellen */
  input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }
}

.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }

.inline-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.inline-form label { margin-bottom: 0; }
.inline-form .grow { flex: 1; min-width: 180px; }

/* Inline-Eingaben in Tabellen */
table.data input[type="text"] { min-width: 150px; }
table.data input[type="number"] { width: 80px; }
table.data input, table.data select { margin-top: 0; }

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.check-label input[type="checkbox"] { width: auto; margin: 0; }

.form-hint { font-size: 13px; color: var(--ink-secondary); margin: 2px 0 10px; }
.form-error { font-size: 13px; color: var(--danger); font-weight: 600; margin: 2px 0 10px; }

/* ---------- Dialog ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  padding: 24px 26px;
  width: min(440px, calc(100vw - 40px));
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
dialog[open] { animation: pop-in 0.18s ease; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 16px; font-size: 17px; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

@keyframes rise-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- Leerzustand ---------- */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-secondary);
}
.empty-state h2 { color: var(--ink); }
.empty-state .btn { margin: 4px; }

/* ---------- Anmeldemaske ---------- */

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: var(--page);
  padding: 20px;
}
/* display:grid würde sonst das hidden-Attribut aushebeln */
.login-screen[hidden] { display: none; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: min(370px, 100%);
  text-align: center;
  animation: pop-in 0.25s ease;
}
.login-card .brand-mark { margin: 0 auto 12px; width: 48px; height: 48px; font-size: 26px; border-radius: 12px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p { font-size: 14px; color: var(--ink-secondary); margin: 0 0 16px; }
.login-card label { text-align: left; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-card .form-error { text-align: left; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--page);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 50;
  animation: rise-in 0.22s ease;
}

/* ---------- Kleine Bildschirme (Handy) ---------- */

@media (max-width: 760px) {
  body { font-size: 14px; }

  .app-header { padding: 8px 12px; gap: 8px; }
  .brand-text span { display: none; }
  .tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab { white-space: nowrap; padding: 6px 10px; }
  .header-actions .btn { padding: 6px 10px; }

  main { padding: 12px; }
  .toolbar { gap: 6px; }
  .toolbar h1 { font-size: 16px; min-width: 0; }
  .legend { font-size: 12px; gap: 8px; }

  table.plan th.emp-col, table.plan td.emp-col {
    min-width: 104px;
    max-width: 130px;
    padding: 6px 8px;
    font-size: 13px;
  }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 12px; }
  .form-row { flex-direction: column; gap: 0; }
}

/* ---------- Druck ---------- */

@media print {
  body { background: #fff; font-size: 12px; }
  .app-header, .toolbar .btn, .toast, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .plan-wrap, .card, .stat-tile { box-shadow: none; border-color: #999; }
  table.plan td.cell { height: 24px; min-width: 24px; }
  .print-title { display: block !important; font-size: 16px; font-weight: 700; margin-bottom: 8px; }
}
.print-title { display: none; }

@page { size: A4 landscape; margin: 12mm; }
