:root {
  --ink: #e7ebf1;
  --ink-soft: #c4ccd8;
  --cream: #0e131a;
  --paper: #19212c;
  --line: #2a3441;
  --ocker: #1fb2a6;
  --ocker-dark: #2fcabd;
  --text: #d3dae3;
  --muted: #8a94a3;
  --green: #4ade80;
  --green-bg: #16341f;
  --blue: #6aa8ff;
  --blue-bg: #16263d;
  --amber: #fbbf24;
  --amber-bg: #392c10;
  --red: #f87171;
  --red-bg: #3a1616;
  --grau: #9ca3af;
  --grau-bg: #2a2e35;
  --sidebar-bg: #0a0e14;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
  --font-body: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-display: "Plus Jakarta Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(31, 178, 166, .10), transparent 60%),
    var(--cream);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 40px 34px;
}
.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 27px;
  letter-spacing: -.5px;
  color: var(--ink);
}
.brand .dot { color: var(--ocker); }
.login-card p.sub { color: var(--muted); margin: 6px 0 28px; font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--ink-soft); }
input, select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ocker);
  box-shadow: 0 0 0 3px rgba(31, 178, 166, .15);
}
.field { margin-bottom: 16px; }

.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ocker); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--ocker-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--cream); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }

.error { color: #a8341f; font-size: 13px; margin-top: 12px; min-height: 18px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 18px; line-height: 1.5; }

/* ---------- App-Shell ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar-bg);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  padding: 26px 18px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { color: #fff; font-size: 22px; padding: 0 8px 26px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  color: #ffffff;
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--ocker); color: #fff; }
.nav a.hidden { display: none; }

.user-box {
  border-top: 1px solid rgba(255, 255, 255, .1);
  padding-top: 16px; margin-top: 16px;
}
.user-box .name { font-weight: 500; color: #fff; font-size: 14px; }
.user-box .role {
  display: inline-block; margin-top: 4px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
  padding: 2px 8px; border-radius: 20px;
  background: rgba(255,255,255,.14); color: #fff;
}
.user-box button { margin-top: 12px; width: 100%; background: transparent; border: 1px solid rgba(255,255,255,.18); color: #fff; }
.user-box button:hover { background: rgba(255,255,255,.08); color: #fff; }

.main { padding: 36px 44px; overflow: auto; }
.page-title { font-family: var(--font-display); font-weight: 700; font-size: 28px; color: var(--ink); letter-spacing: -.5px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 22px;
}
.card h3 { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--ink); margin-bottom: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ---------- Tabelle ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .4px; color: var(--muted);
  padding: 0 12px 10px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(31, 178, 166, .04); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.proj-name { font-weight: 500; color: var(--ink); }
.proj-nr { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.proj-nr.leer { color: var(--ocker); font-style: italic; }

.pill {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 20px;
}
.pill.offen { background: var(--amber-bg); color: var(--amber); }
.pill.aktiv { background: var(--blue-bg); color: var(--blue); }
.pill.berechnet { background: var(--green-bg); color: var(--green); }
.pill.merken { background: var(--red-bg); color: var(--red); }
.pill.keinerechnung { background: var(--grau-bg); color: var(--grau); }

.anm-input {
  display: block;
  width: 100%;
  min-width: 120px;
  min-height: 30px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  resize: none;
  overflow: hidden;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-break: break-word;
}
.anm-input:hover { background: var(--paper); border-color: var(--line); }
.anm-input:focus { background: var(--paper); border-color: var(--line); outline: none; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(30, 27, 22, .45);
  display: none; place-items: center; padding: 24px; z-index: 50;
}
.modal-backdrop.show { display: grid; }
.modal {
  background: var(--paper); border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 440px; padding: 26px;
}
.modal h3 { font-family: var(--font-display); font-weight: 600; font-size: 19px; color: var(--ink); margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.view { display: none; }
.view.active { display: block; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #11161d; color: #fff; padding: 13px 18px;
  border-radius: 10px; box-shadow: var(--shadow); font-size: 14px;
  opacity: 0; transform: translateY(8px); transition: .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.empty { color: var(--muted); text-align: center; padding: 36px; font-size: 14px; }

/* ---------- Stundenliste / Klick auf Nummer ---------- */
.nr-cell { cursor: pointer; }
.nr-cell:hover .proj-nr { text-decoration: underline; }
.proj-nr.leer::after { content: " ✎"; font-style: normal; opacity: .7; }

.filterbar { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.filter-toggle { display: none; }
.filterbar select, .filterbar input[type="text"] {
  min-width: 200px;
  font-family: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--text);
}
.filterbar label { margin-bottom: 3px; font-size: 12px; }
.sl-summe { margin-left: auto; text-align: right; }
.sl-summe-label { color: var(--muted); font-size: 12px; }
.sl-summe-wert { font-family: var(--font-display); font-weight: 700; font-size: 22px; color: var(--ink); }
.sl-anzahl { color: var(--muted); font-size: 13px; }

/* Tagesüberschrift in der Stundenliste */
.day-row td {
  background: var(--cream);
  font-family: var(--font-display);
  font-size: 13.5px;
  color: var(--ink);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.day-row:hover td { background: var(--cream); }

/* Status direkt in der Spalte änderbar */
.pill-click { cursor: pointer; user-select: none; transition: filter .12s, box-shadow .12s; }
.pill-click:hover { filter: brightness(1.08); box-shadow: 0 0 0 2px rgba(255,255,255,.12); }

/* ---------- Stundenliste als abgesetzte Tageskarten ---------- */
.sl-head {
  display: grid;
  grid-template-columns: 150px 34px 1.4fr 64px 64px 130px 1.4fr;
  gap: 10px;
  padding: 0 17px 8px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600;
}
.day-card {
  display: grid;
  grid-template-columns: 150px 1fr;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
}
.day-card-side {
  background: var(--cream);
  border-right: 1px solid var(--line);
  padding: 12px 14px;
}
.day-name { font-family: var(--font-display); font-weight: 700; font-size: 14px; color: var(--ink); }
.day-date { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.day-side-sum { color: var(--ocker); font-weight: 700; font-size: 13px; margin-top: 8px; }
.day-card-body { padding: 0; display: flex; flex-direction: column; }
.sl-row {
  display: grid;
  grid-template-columns: 34px 1.4fr 64px 64px 130px 1.4fr;
  gap: 10px; align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.day-card-body .sl-row:last-child { border-bottom: none; }
.sl-row:hover { background: rgba(31, 178, 166,.07); }
.sl-row[data-edit] { cursor: pointer; }
.buchen-inline { max-width: 640px; }

/* Sortierbare Spaltenköpfe */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
.sort-arr { color: var(--ocker); font-size: 11px; }

/* Benutzer-Initialen-Avatar */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  color: #fff; font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
}

/* Kalender-Icon hell im Dark-Theme */
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.7); cursor: pointer; }

/* Offene (noch nicht beendete) Buchung: rot hinterlegt */
.offen-rot {
  display: inline-block;
  background: rgba(220, 70, 70, .22);
  color: #ff8a8a;
  border: 1px solid rgba(220, 70, 70, .5);
  padding: 1px 8px; border-radius: 6px; font-size: 12.5px; font-weight: 600;
}

/* Auge-Button im Passwortfeld */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; width: 100%; }
.pw-eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1;
  padding: 4px; color: var(--muted);
}
.pw-eye:hover { color: var(--ink); }

/* Druck-Optimierung */
@media print {
  .sidebar, .filterbar, .buchen-inline, .page-head button, .row-actions,
  .modal-backdrop, .toast, #addBuchungBtn { display: none !important; }
  .app { display: block !important; }
  .main { padding: 0 !important; }
  body { background: #fff !important; }
  .card, .day-card { box-shadow: none !important; border-color: #ccc !important; break-inside: avoid; }
  :root {
    --cream: #fff; --paper: #fff; --ink: #111; --text: #111; --muted: #555; --line: #ccc;
  }
  .day-card-side { background: #f3f3f3 !important; }
  .pill { border: 1px solid #999; }
}

/* Klickbare Projektzeile */
.proj-row { cursor: pointer; }
.muted-arrow { color: var(--muted); text-align: right; font-size: 18px; }

/* Stundenliste: Tageskarten als Flex-Spalte; im Druck älteste zuerst (oben) */
#slList { display: flex; flex-direction: column; }
@media print { #slList { flex-direction: column-reverse; } .day-card-body { flex-direction: column-reverse; } }

/* ============================================================
   Responsive: Tablet & Handy
   ============================================================ */

/* --- Tablet: schlanke Kopfleiste --- */
@media (min-width: 641px) and (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; align-self: auto; overflow: visible;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 8px 14px; padding: 12px 16px;
  }
  .sidebar .brand { padding: 0; font-size: 18px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav a { padding: 8px 12px; }
  .user-box {
    border-top: none; padding-top: 0; margin-top: 0; margin-left: auto;
    display: flex; align-items: center; gap: 10px;
  }
  .user-box .name { font-size: 13px; }
  .user-box .role { margin-top: 0; }
  .user-box button { margin-top: 0; width: auto; padding: 6px 12px; }
  .main { padding: 20px 16px; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .view .card table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* --- Handy: App-Layout (App-Leiste oben, Tab-Navigation unten) --- */
@media (max-width: 640px) {
  .app { display: block; }

  /* Obere App-Leiste */
  .sidebar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    height: 54px; align-self: auto; overflow: visible;
    flex-direction: row; align-items: center; gap: 12px; padding: 0 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .sidebar .brand { padding: 0; font-size: 16px; }
  .user-box { border: none; margin: 0 0 0 auto; padding: 0; display: flex; align-items: center; gap: 8px; }
  .user-box .name { display: none; }
  .user-box .role { margin: 0; }
  .user-box button { margin: 0; width: auto; padding: 6px 10px; font-size: 12px; }

  /* Untere Tab-Navigation */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    flex-direction: row; gap: 0;
    background: var(--sidebar-bg);
    border-top: 1px solid rgba(255,255,255,.08);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .nav a {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 10.5px; padding: 6px 2px; border-radius: 10px; color: #aeb6c2;
  }
  .nav a::before {
    content: ""; width: 22px; height: 22px;
    background-color: currentColor;
    -webkit-mask: var(--icon) center / 22px 22px no-repeat;
    mask: var(--icon) center / 22px 22px no-repeat;
  }
  .nav a[data-view="stundenliste"] { --icon: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Ccircle%20cx='12'%20cy='12'%20r='9'/%3E%3Cpath%20d='M12%207v5l3%202'/%3E%3C/svg%3E"); }
  .nav a[data-view="projekte"] { --icon: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M3%207a2%202%200%200%201%202-2h4l2%202h8a2%202%200%200%201%202%202v8a2%202%200%200%201-2%202H5a2%202%200%200%201-2-2z'/%3E%3C/svg%3E"); }
  .nav a[data-view="verwaltung"] { --icon: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Ccircle%20cx='12'%20cy='8'%20r='4'/%3E%3Cpath%20d='M4%2021a8%208%200%200%201%2016%200'/%3E%3C/svg%3E"); }
  .nav a:hover { background: transparent; color: #cfd6df; }
  .nav a.active { color: var(--ocker); background: rgba(31, 178, 166, .16); }

  /* Inhalt zwischen den Leisten */
  .main { padding: 66px 14px calc(74px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 22px; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 16px; }

  /* Filterzeile gestapelt + einklappbar */
  .filter-toggle { display: inline-flex; margin-bottom: 12px; }
  #filterCard { display: none; }
  #filterCard.offen { display: block; }
  .filterbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .filterbar select, .filterbar input[type="text"] { min-width: 0; width: 100%; }
  .sl-summe { margin-left: 0; text-align: left; }
  .buchen-inline { max-width: none; }

  /* Stundenliste: Tageskarte gestapelt, kein Seiten-Scroll */
  .sl-head { display: none; }
  .day-card { grid-template-columns: 1fr; }
  .day-card-side {
    border-right: none; border-bottom: 1px solid var(--line);
    display: flex; align-items: baseline; gap: 10px; padding: 10px 14px;
  }
  .day-side-sum { margin-top: 0; margin-left: auto; }
  .sl-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 11px 14px;
  }
  .sl-row > div { font-size: 13px; }
  .sl-row > div:nth-child(1) { order: 1; flex: 0 0 auto; }
  .sl-row > div:nth-child(2) { order: 2; flex: 1 1 55%; font-weight: 600; color: var(--ink); }
  .sl-row > div:nth-child(5) { order: 3; margin-left: auto; font-weight: 600; }
  .sl-row > div:nth-child(3) { order: 4; flex: 0 0 auto; color: var(--muted); }
  .sl-row > div:nth-child(3)::after { content: '–'; margin-left: 6px; color: var(--muted); }
  .sl-row > div:nth-child(4) { order: 5; flex: 0 0 auto; color: var(--muted); }
  .sl-row > div:nth-child(6):not(:empty) { order: 6; flex: 1 1 100%; color: var(--muted); }

  /* Tabellen (Projekte, Verwaltung) als gestapelte Karten – kein Seiten-Scroll */
  .view .card table, .view .card tbody, .view .card tr, .view .card td { display: block; width: auto; }
  .view .card thead { display: none; }
  .view .card tbody tr {
    border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
    padding: 6px 12px; margin-bottom: 10px;
  }
  .view .card tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none; padding: 6px 0; text-align: right;
  }
  .view .card tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 500; text-align: left;
  }
  .view .card tbody td.proj-name { font-weight: 700; color: var(--ink); }
  .view .card tbody td.muted-arrow, .view .card tbody td:empty { display: none; }
  .view .card tbody td.row-actions { justify-content: flex-end; }
  .view .card tbody td.row-actions::before { content: ""; }

  /* Dialoge als Bottom-Sheet */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100%; max-width: none; max-height: 88vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); }

  /* Hinweis-Toast über der Tab-Leiste */
  .toast { left: 14px; right: 14px; bottom: calc(80px + env(safe-area-inset-bottom)); text-align: center; }
}

/* Login/Reset auf Handy */
@media (max-width: 640px) {
  .login-screen { padding: 16px; }
  .login-card { padding: 30px 22px; border-radius: 14px; }
  .login-card .brand { font-size: 20px; overflow-wrap: anywhere; line-height: 1.2; }
}

/* Anmerkung per +-Button einblenden */
.anm-cell { display: flex; align-items: center; gap: 8px; }
.anm-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; padding: 0;
  border: 1px solid var(--line); background: transparent;
  font-size: 15px; line-height: 1; cursor: pointer; flex: 0 0 auto;
  color: var(--muted);
}
.anm-toggle.hat { color: #39ff14; border-color: rgba(57, 255, 20, .55); }
.anm-toggle.leer { color: var(--muted); cursor: default; }
.anm-text { display: none; color: var(--muted); }
.anm-cell.offen .anm-text { display: inline; }
