:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e5e9f0;
  --border-strong: #cbd2dc;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 14px;

  --c-U: #dcfce7; --c-U-fg: #15803d;
  --c-K: #fee2e2; --c-K-fg: #b91c1c;
  --c-frei: #f3f4f6; --c-frei-fg: #9ca3af;
  --c-shift: #eff6ff; --c-shift-fg: #1e40af;

  --weekend-bg: #f9fafb;
  --today-ring: #0ea5e9;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1700px; margin: 0 auto; padding: 18px 22px 60px; }

/* ============== Splash ============== */
.splash {
  position: fixed; inset: 0;
  background: linear-gradient(140deg, #f0f9ff, #fef3c7);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 50;
}
.splash[hidden] { display: none; }
.splash-card {
  background: white;
  border-radius: 24px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .12);
  max-width: 460px; width: 100%;
}
.splash-card h1 { margin: 16px 0 4px; font-size: 28px; }
.splash-sub { color: var(--muted); margin: 0 0 28px; }
.splash-actions { display: flex; flex-direction: column; gap: 10px; }
.btn.big { padding: 14px 18px; font-size: 15px; border-radius: 12px; }
.logo.big { width: 64px; height: 64px; margin: 0 auto; font-size: 32px; border-radius: 16px; }
.muted { color: var(--muted); font-weight: 400; }

/* ============== Topbar ============== */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.logo {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white; font-weight: 700; font-size: 20px;
  border-radius: 12px;
  display: grid; place-items: center;
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.subtitle { color: var(--muted); font-size: 12px; }

.month-nav {
  display: flex; align-items: center; gap: 6px;
  flex: 1 1 auto; justify-content: center;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: white; color: var(--text);
  font-size: 20px; cursor: pointer; line-height: 1; transition: .15s;
}
.icon-btn:hover { background: var(--bg); border-color: var(--border-strong); }
.month-select, .year-select {
  padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: white; font-size: 14px; font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5l3 3 3-3' stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.actions { display: flex; gap: 8px; flex: 0 0 auto; }
.btn {
  padding: 9px 16px; border-radius: 10px;
  font-weight: 600; font-size: 14px; cursor: pointer;
  border: 1px solid transparent; transition: .15s;
  background: transparent;
}
.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: white; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--bg); border-color: var(--border-strong); }
.btn.danger { background: white; border-color: #fecaca; color: #b91c1c; }
.btn.danger:hover { background: #fef2f2; }
.btn.block { width: 100%; padding: 12px; margin-top: 12px; }

/* ============== Legend ============== */
.legend {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.legend-title { font-size: 12px; color: var(--muted); }
.legend-items { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 4px 10px; border-radius: 999px;
  font-weight: 600; font-size: 12px;
  border: 1px solid transparent;
}
.code-shift { background: var(--c-shift); color: var(--c-shift-fg); }
.code-U { background: var(--c-U); color: var(--c-U-fg); }
.code-K { background: var(--c-K); color: var(--c-K-fg); }
.code-frei { background: var(--c-frei); color: var(--c-frei-fg); }

/* ============== Table ============== */
.plan-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.plan-scroll { overflow-x: auto; }

table.plan {
  border-collapse: separate; border-spacing: 0;
  width: 100%;
}
table.plan th, table.plan td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  padding: 0;
  font-size: 12px;
  background: white;
}
table.plan thead th {
  position: sticky; top: 0; z-index: 3;
  background: #f9fafb;
  font-weight: 600;
  color: var(--text);
  padding: 6px 4px;
  border-bottom: 2px solid var(--border-strong);
}
table.plan thead th .dow { display: block; font-size: 10px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
table.plan thead th .dom { font-size: 14px; font-weight: 700; }
table.plan thead th.day-col { min-width: 76px; }
table.plan th.name-col, table.plan td.name-cell {
  text-align: left; padding: 10px 12px 10px 14px;
  position: sticky; left: 0; z-index: 2;
  background: white;
  min-width: 150px;
  border-right: 2px solid var(--border-strong);
  font-weight: 600;
}
table.plan thead th.name-col { z-index: 4; background: #f9fafb; }
table.plan td.name-cell {
  border-left: 6px solid var(--emp-color, #94a3b8);
  padding-left: 10px;
  background: color-mix(in srgb, var(--emp-color, #94a3b8) 18%, white);
}
table.plan tbody tr td.day {
  background: color-mix(in srgb, var(--emp-color, #94a3b8) 7%, white);
}
table.plan tbody tr td.day.weekend {
  background: color-mix(in srgb, var(--emp-color, #94a3b8) 14%, #f9fafb);
}
table.plan tbody tr:hover td.name-cell {
  background: color-mix(in srgb, var(--emp-color, #94a3b8) 26%, white);
}
table.plan tbody tr:hover td.day:not(.editing) {
  background: color-mix(in srgb, var(--emp-color, #94a3b8) 12%, white);
}
table.plan td.name-cell .emp-row {
  display: flex; align-items: center; gap: 8px;
}
table.plan td.name-cell .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--emp-color, #94a3b8);
  flex: 0 0 auto;
}
table.plan th.summary, table.plan td.summary {
  background: #fafbfc;
  font-weight: 600;
  padding: 8px 6px;
  min-width: 56px;
}
table.plan thead th.summary { font-size: 10px; line-height: 1.1; padding: 6px; }

.cell {
  width: 100%; min-height: 36px;
  display: grid; place-items: center;
  padding: 4px 4px;
  cursor: default;
  font-weight: 600; font-size: 11.5px;
  user-select: none;
  transition: transform .08s, background .1s;
  word-break: keep-all;
  white-space: nowrap;
  letter-spacing: -.01em;
}
body.is-angie .cell { cursor: pointer; }
body.is-angie .cell:hover { background: #f0f9ff; }
.cell.empty { color: #d1d5db; font-weight: 400; }
body.is-angie .cell.empty:hover { color: var(--accent); }
body.is-angie .cell.empty:hover::before { content: "+ Zeit"; font-size: 10px; }

.cell.code-U { background: var(--c-U); color: var(--c-U-fg); }
.cell.code-K { background: var(--c-K); color: var(--c-K-fg); }
.cell.code-frei { background: var(--c-frei); color: var(--c-frei-fg); }
.cell.code-shift { background: var(--c-shift); color: var(--c-shift-fg); }

td.weekend { background: var(--weekend-bg); }
th.weekend { background: #f3f4f6 !important; color: var(--muted); }
th.today { box-shadow: inset 0 -3px 0 var(--today-ring); }

td.editing { padding: 0 !important; background: white !important; }
.cell-input {
  width: 100%; height: 36px;
  border: 2px solid var(--accent);
  background: white;
  text-align: center;
  font-weight: 600; font-size: 12px;
  outline: none;
  padding: 0 4px;
  border-radius: 0;
}

tfoot td {
  background: #f9fafb !important;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 4px !important;
}
tfoot td.label { text-align: left; padding-left: 14px !important; }

.footer { margin-top: 14px; text-align: center; color: var(--muted); font-size: 12px; }

/* ============== Modal ============== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .4);
  display: grid; place-items: center;
  z-index: 200;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: white;
  border-radius: 16px;
  width: 100%; max-width: 480px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
  overflow: hidden;
}
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.login-modal input[type="password"] {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px;
}
.login-error {
  margin-top: 10px; padding: 10px 12px;
  background: #fef2f2; color: #b91c1c;
  border: 1px solid #fecaca; border-radius: 10px;
  font-size: 13px;
}

.emp-list {
  list-style: none; padding: 0; margin: 0 0 16px;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 360px; overflow-y: auto;
}
.emp-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfc;
  border-left: 6px solid var(--emp-color, #94a3b8);
}
.emp-list li input.rename {
  flex: 1; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px;
}
.emp-list li input.color {
  width: 32px; height: 32px;
  padding: 0; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; background: none;
}
.add-form { display: flex; gap: 8px; }
.add-form input {
  flex: 1; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px;
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: white;
  padding: 10px 16px; border-radius: 10px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast[hidden] { display: none; }

.print-title { display: none; }

/* role visibility */
body.is-angie .view-only { display: none !important; }
body:not(.is-angie) .angie-only { display: none !important; }
body.is-angie [hidden].angie-only,
body:not(.is-angie) [hidden].view-only {
  /* hidden by default */
}
body.is-angie .angie-only[hidden] { display: revert !important; }
body:not(.is-angie) .view-only[hidden] { display: revert !important; }

/* ============== Print ============== */
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: white; font-size: 8pt; }
  .splash, .modal-backdrop, .toast { display: none !important; }
  .app { max-width: none; padding: 0; }
  .no-print { display: none !important; }
  .plan-wrap { box-shadow: none; border: none; border-radius: 0; }
  .plan-scroll { overflow: visible; }
  table.plan { font-size: 7.5pt; }
  table.plan thead th.day-col { min-width: 0; }
  table.plan th.name-col, table.plan td.name-cell { position: static; min-width: auto; padding: 3px 6px 3px 8px; border-left-width: 4px; }
  table.plan thead th { position: static; padding: 3px 2px; }
  table.plan thead th .dom { font-size: 9pt; }
  table.plan thead th .dow { font-size: 7pt; }
  .print-title {
    display: block; text-align: center;
    font-size: 14pt; font-weight: 700;
    margin: 0 0 6px;
  }
  .cell { min-height: 16px; height: 16px; font-size: 7.5pt; padding: 1px 2px; }
  table.plan th, table.plan td { font-size: 7pt; }
  table.plan tbody tr:hover td:not(.summary):not(.name-cell) { background: white; }
  .cell.empty { color: white; }
  .cell.empty::before { content: "" !important; }
  td.name-cell .dot { width: 7px; height: 7px; }
  /* keep employee colors on print */
  table.plan td.name-cell { background: white !important; }
  .cell.code-U, .cell.code-K, .cell.code-frei, .cell.code-shift {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
