* { box-sizing: border-box; }
html {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #222;
  background: #f4f5f7;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.center { display: grid; place-items: center; height: 100vh; }
.muted { color: #777; }
.error { color: #b00020; }
.banner { padding: 8px 16px; }
button { padding: 6px 10px; border-radius: 6px; border: 1px solid #ccc; background: #fff; cursor: pointer; }
button:hover { background: #f0f0f0; }
button.primary { background: #2563eb; color: #fff; border: none; }
button.primary:hover { background: #1d4ed8; }
input, select { font-family: inherit; }

/* ---------- Login ---------- */
.login-wrap { display: grid; place-items: center; height: 100vh; }
.login-card {
  background: #fff; padding: 28px; border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12); width: 300px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-card input, .login-card button { padding: 8px; border-radius: 6px; border: 1px solid #ccc; }
.login-card button { background: #2563eb; color: #fff; border: none; cursor: pointer; }

/* ---------- Layout ---------- */
.app { padding: 12px 16px 40px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px; margin-bottom: 12px;
}
.nav { display: flex; align-items: center; gap: 10px; }
.nav h2 { margin: 0; min-width: 160px; text-align: center; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ctrl { display: flex; flex-direction: column; font-size: 11px; color: #555; }
.ctrl input, .ctrl select { padding: 4px; }
.user { font-weight: 600; margin-left: 8px; }

/* ---------- Tabelle ---------- */
.table-scroll { overflow-x: auto; background: #fff; border-radius: 8px; }
table.plan { border-collapse: collapse; width: 100%; table-layout: fixed; }
table.plan th, table.plan td {
  border: 1px solid #d9d9d9; padding: 2px 4px; text-align: center; vertical-align: top;
}
table.plan th {
  background: #eef1f5;
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 15px;
  font-weight: 700;
  padding: 6px 4px;
  border-bottom: 3px solid #334155;
}
.th-sub { font-size: 10px; color: #555; font-weight: 400; }
.base-input {
  width: 60px; font-size: 12px; text-align: center; color: #111;
  border: 1px solid #ccc; border-radius: 4px; padding: 2px;
}
.base-input.base-override { color: #c2410c; font-weight: 700; border-color: #f59e0b; background: #fff7ed; }
.base-row { display: flex; align-items: center; gap: 4px; }
.reset-btn {
  font-size: 14px; line-height: 1; padding: 3px 6px; border: 1px solid #ccc;
  border-radius: 4px; background: #fff; cursor: pointer; color: #555;
}
.reset-btn:hover { background: #f0f0f0; }
.lock-on { background: #fee2e2; border-color: #b91c1c; color: #b91c1c; font-weight: 700; }
.col-day { width: 34px; }
.col-wd { width: 34px; }
.col-termin { width: 150px; }
.col-who { width: 96px; }
.col-count { width: 62px; font-weight: 700; }
/* Personenspalten (ab Spalte 6) teilen sich den Rest gleichmaessig (auto) */
.emp-head { font-size: 13px; }
.row-weekend { background: #e8e8ec; }
.row-holiday { background: #fcd4d4; }
.holiday-dot { color: #b00020; margin-left: 2px; }

.termin-input { width: 100%; border: none; background: transparent; font-size: 12px; }
.termin-input:focus { background: #fffbe6; outline: 1px solid #e0c000; }
.termin-print { display: none; }

.who-chips { display: flex; gap: 2px; justify-content: center; flex-wrap: wrap; }
.chip {
  width: 22px; height: 22px; border-radius: 50%; padding: 0;
  border: 1px solid #bbb; font-size: 11px; background: #fff; color: #888; cursor: pointer;
}
.chip-on { color: #111; font-weight: 700; border-color: #666; }

/* Zellen */
.cell { min-width: 0; }
.cell-rb { box-shadow: inset 3px 0 0 #f59e0b; }
.cell-row { display: flex; gap: 2px; align-items: center; }
.status-sel { flex: 1; border: none; font-size: 12px; padding: 2px; border-radius: 4px; background: transparent; }
.status-D { font-weight: 700; color: #0f3d6b; }
.status-FREI { color: #6b7280; font-style: italic; }
.status-U { font-weight: 700; color: #b45309; }
.status-empty { color: #333; }
.rb-btn { font-size: 9px; padding: 1px 3px; border-radius: 4px; color: #bbb; border: 1px solid #ddd; cursor: pointer; }
.rb-on { background: #f59e0b; color: #fff; border-color: #f59e0b; font-weight: 700; }
.cell-meta { display: flex; gap: 3px; align-items: center; justify-content: center; margin-top: 1px; }
.cell-print { display: none; }
.time-input { width: 46px; font-size: 10px; border: 1px solid #ddd; border-radius: 4px; }
.hours-wrap { font-size: 10px; color: #2563eb; display: inline-flex; align-items: center; gap: 1px; }
.hours-input { width: 30px; font-size: 10px; text-align: right; border: 1px solid #ddd; border-radius: 4px; color: #2563eb; background: #fff; }
.hours-input.hours-override { color: #c2410c; font-weight: 700; border-color: #f59e0b; background: #fff7ed; }
.wish-btn { font-size: 16px; line-height: 1; padding: 0 3px; color: #d3d3d3; border: none; background: none; cursor: pointer; }
.wish-on { color: #e11d8f; }

/* ---------- Statistik ---------- */
.stats { margin-top: 16px; display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.stats-info { padding: 8px; }
.stats-table { border-collapse: collapse; }
.stats-table th, .stats-table td { border: 1px solid #ddd; padding: 4px 10px; text-align: center; }
.stats-table .pos { color: #b00020; }
.stats-table .neg { color: #c47f00; }
.stats-print { display: none; }

/* Summen-Fußzeile unter den Personen-Spalten */
.sum-row td { border-top: 3px solid #334155; padding: 5px 4px; }
.sum-label { text-align: right; font-weight: 700; color: #333; }
.sum-cell { text-align: center; }
.sum-h { font-weight: 800; font-size: 14px; }
.sum-diff { font-size: 11px; }
.sum-diff.pos { color: #b00020; }
.sum-diff.neg { color: #c47f00; }

.legend { margin-top: 16px; font-size: 12px; color: #555; line-height: 1.5; max-width: 900px; }
.print-title { display: none; font-size: 20px; font-weight: 700; margin: 8px 0; }

/* ---------- Druck / PDF ---------- */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-title { display: block; font-size: 18px; margin: 0 0 6px; }
  .app { padding: 0; }
  .table-scroll { overflow: visible; }

  /* Größere, gut lesbare Tabelle für den Druck */
  table.plan { width: 100%; table-layout: fixed; }
  table.plan th, table.plan td {
    padding: 1px 2px;
    font-size: 10px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  table.plan th { position: static; }
  table.plan th {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 2px;
    border-bottom: 2px solid #000;
  }
  .th-sub { font-size: 8px; }

  /* Spaltenbreiten fürs Drucken: vorne genug Platz, Personen teilen den Rest */
  .col-day { width: 28px; }
  .col-wd { width: 28px; }
  .col-termin { width: 120px; }
  .col-who { width: 66px; }
  .col-count { width: 44px; }
  .emp-head { font-size: 11px; }

  /* Interaktive Zell-Elemente ausblenden, kompakte Druckdarstellung zeigen */
  .cell-row, .cell-meta { display: none !important; }
  .cell-print { display: block; font-size: 10px; line-height: 1.15; }
  .cp-main { font-weight: 700; }
  .cp-rb { color: #b45309; font-weight: 700; }
  .cp-sub { display: block; color: #1d4ed8; font-weight: 400; font-size: 9px; }

  /* "Wer macht Termin" */
  .who-chips { gap: 1px; }
  .chip { width: 14px; height: 14px; font-size: 8px; border: none; }

  /* Leeres "Beginn"-Feld ausblenden (greift auch in cell-print nicht, da Text) */
  .time-input.empty { display: none !important; }

  /* Termine als umbrechender Text statt Eingabefeld */
  .termin-input { display: none; }
  .termin-print {
    display: block;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: 10px;
    line-height: 1.15;
  }

  /* Statistik: nur die kompakte Ein-Zeilen-Version */
  .stats { display: none !important; }
  .stats-print {
    display: block;
    font-size: 11px;
    margin-top: 6px;
    font-weight: 600;
  }

  /* Summen-Fußzeile kompakt */
  .sum-row td { border-top: 2px solid #000; padding: 2px 3px; }
  .sum-h { font-size: 12px; }
  .sum-diff { font-size: 9px; }

  /* Legende im Druck ausblenden */
  .legend { display: none !important; }

  @page { size: A4 portrait; margin: 8mm; }
}
