:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #0f766e;
  --primary-soft: #ccfbf1;
  --primary-tint: #f0fdfa;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 8px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 24px; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 20px; padding-top: calc(10px + env(safe-area-inset-top)); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav a {
  display: flex; align-items: center; gap: 6px;
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: var(--radius);
}
#nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
#nav .label-short { display: none; }
.user-area { position: relative; }
.user-menu { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.menu-btn { display: none; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-brand h1 { margin: 0; font-size: 1.8rem; letter-spacing: -.02em; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.toolbar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer, .spacer { flex: 1; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stat { font-size: 1.6rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Formulare */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: .95rem; }
input, select, textarea {
  font: inherit; color: var(--text); padding: 7px 9px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; min-width: 0;
}
textarea { resize: vertical; min-height: 60px; }
input[type=color] { padding: 2px; height: 36px; width: 60px; }
input[type=checkbox] { width: 16px; height: 16px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-grid input:not([type=checkbox]):not([type=radio]), .form-grid select, .form-grid textarea { width: 100%; }
dialog { overflow-x: hidden; }
.form-grid .full { grid-column: 1 / -1; }
.hours-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.hours-grid input { width: 100%; text-align: center; }

button {
  font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; color: var(--text); cursor: pointer;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
button.ok { color: var(--ok); border-color: #bbf7d0; }
button.small { padding: 3px 8px; font-size: .85rem; }
button.link { border: none; background: none; color: var(--primary); padding: 0; }
.error { color: var(--danger); min-height: 1em; margin: 8px 0 0; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f9fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--muted); }
tfoot td { font-weight: 600; }
.actions { white-space: nowrap; text-align: right; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; background: #f3f4f6; }
.badge.requested { background: #fef3c7; color: #92400e; }
.badge.approved { background: #dcfce7; color: #166534; }
.badge.rejected { background: #fee2e2; color: #991b1b; }

/* Kalender */
#calendar { background: var(--surface); padding: 12px; border-radius: var(--radius); border: 1px solid var(--border); }
.fc .ev-requested { opacity: .55; border-style: dashed !important; }
.fc .ev-holiday { font-weight: 600; }
.fc .fc-bg-event.ev-holiday { background: #fde68a; opacity: .45; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }

/* Login */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; }

/* Dialog */
dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, 95vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 42, .4); }
dialog form { padding: 20px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100;
}

.badge.tooltime { background: #e0e7ff; color: #3730a3; font-size: .72rem; vertical-align: middle; }
.toast { white-space: pre-line; max-width: min(640px, 92vw); }
.notice { background: #fef3c7; color: #92400e; padding: 8px 10px; border-radius: 6px; margin: 0; }
.history { margin: 8px 0 0; padding-left: 18px; font-size: .85rem; }
.history li { margin-bottom: 4px; }
.badge.violation { background: #fee2e2; color: #991b1b; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.info { background: #e0f2fe; color: #075985; }
tr.cancelled td { text-decoration: line-through; color: var(--muted); }
.flag { cursor: help; }

/* Schnell-Erfassung (nur mobil sichtbar) */
.fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 20;
  width: 56px; height: 56px; border-radius: 50%; border: none; padding: 0;
  background: var(--primary); color: #fff; box-shadow: 0 6px 18px rgba(15, 118, 110, .4);
  display: none; align-items: center; justify-content: center;
}
.fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; }

/* Hinweis "Als App installieren" */
.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 50;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .18); max-width: 560px; margin: 0 auto;
}
.install-banner img { border-radius: 10px; }
.install-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 180px; font-size: .9rem; }
.install-text span { color: var(--muted); }
.install-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.ios-share { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.has-bottom-nav .install-banner { bottom: calc(76px + env(safe-area-inset-bottom)); }

/* ---------- Smartphones ---------- */
@media (max-width: 760px) {
  :root { font-size: 15px; }
  body.has-bottom-nav { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }

  .topbar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 8px; justify-content: space-between; }

  /* Navigation als Leiste am unteren Rand */
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; flex-wrap: nowrap; gap: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  #nav a { flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: .7rem; text-align: center; border-radius: 10px; min-width: 0; }
  #nav a svg { width: 22px; height: 22px; }
  #nav a.active { background: none; }
  #nav a.active svg { stroke-width: 2.4; }
  #nav .label-long { display: none; }
  #nav .label-short { display: inline; }

  /* Benutzermenü als Ausklapp-Menü */
  .menu-btn {
    display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0;
    border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; border: none;
  }
  .user-menu {
    display: none; position: absolute; right: 0; top: 46px; z-index: 40; min-width: 220px;
    flex-direction: column; align-items: stretch; gap: 0; padding: 6px 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgba(15, 23, 42, .18);
  }
  .user-menu.open { display: flex; }
  .user-menu > span, .user-menu > button.link { padding: 14px 16px; text-align: left; }
  .user-menu #me-name { color: var(--text); font-weight: 600; border-bottom: 1px solid var(--border); }

  main { padding: 12px; }
  .fab.visible { display: flex; }

  /* Formulare: 16px verhindert das automatische Zoomen auf dem iPhone */
  input, select, textarea, button { font-size: 16px; }
  input, select, textarea { padding: 10px; }
  button { padding: 10px 14px; }
  button.small { padding: 6px 10px; font-size: .9rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .form-grid > * { grid-column: 1 / -1; }
  .form-grid > .half { grid-column: auto; }
  .desktop-only { display: none !important; }
  .legend { display: none; }
  .toolbar { gap: 8px; }
  .toolbar > label { flex: 1 1 140px; }
  .toolbar > button, .toolbar > form { flex: 1 1 auto; }
  .toolbar .spacer { display: none; }
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 12px; }
  .stat { font-size: 1.3rem; }
  .hours-grid { gap: 4px; }
  .hours-grid input { padding: 8px 2px; }

  /* Tabellen werden zu Karten: jede Zeile ein Block, Spaltentitel als Beschriftung */
  main table.responsive thead { display: none; }
  main table.responsive, main table.responsive tbody, main table.responsive tfoot { display: block; width: 100%; }
  main table.responsive tr {
    display: block; padding: 10px 0; border-bottom: 1px solid var(--border);
  }
  main table.responsive td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    border: none; padding: 3px 0; text-align: right;
  }
  main table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex-shrink: 0; }
  main table.responsive td:not([data-label])::before, main table.responsive td[data-label='']::before { content: none; }
  main table.responsive td:empty { display: none; }
  main table.responsive td:first-child { font-weight: 600; text-align: left; justify-content: flex-start; }
  main table.responsive td:first-child::before { content: none; }
  main table.responsive td.actions { justify-content: flex-end; padding-top: 8px; }
  main table.responsive td.actions::before { content: none; }
  .table-wrap { overflow: visible; }

  /* Dialoge im Vollbild */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog form { min-height: 100%; display: flex; flex-direction: column; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); }
  #dialog-body { flex: 1; }
  .dialog-actions {
    position: sticky; bottom: 0; background: var(--surface); margin: 16px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
  }

  /* Kalender kompakter */
  #calendar { padding: 6px; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 6px; }
  .fc .fc-toolbar-title { font-size: 1.05rem; }
  .fc .fc-button { padding: 6px 10px; font-size: .85rem; }
  .legend { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; }

  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* Als installierte App: kein Browser-Rahmen, daher etwas Abstand oben */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; }
  input, textarea, td, p { -webkit-user-select: text; user-select: text; }
}
.install-steps { padding-left: 20px; line-height: 1.7; }

/* Kompakte Eintragsliste (nur mobil) */
.mobile-only { display: none; }
@media (max-width: 760px) {
  .mobile-only { display: block; }
  .entry-list { list-style: none; margin: 0; padding: 0; }
  .entry-day { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 14px 2px 6px; display: flex; justify-content: space-between; }
  .entry-item {
    display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px; margin-bottom: 8px; cursor: pointer;
  }
  .entry-item.cancelled { opacity: .55; text-decoration: line-through; }
  .entry-item .bar { width: 4px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
  .entry-item .main { flex: 1; min-width: 0; }
  .entry-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .entry-item .sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .entry-item .dur { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .entry-day span:last-child { text-transform: none; }
  .tabs { display: none; }
  .entry-total { display: flex; justify-content: space-between; font-weight: 700; padding: 8px 4px; }
}

/* ---------- Stempeluhr ---------- */
.clock-card {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
}
.clock-card.running { border-color: #86efac; background: linear-gradient(90deg, #f0fdf4, var(--surface)); }
.clock-card.on-break { border-color: #fcd34d; background: linear-gradient(90deg, #fffbeb, var(--surface)); }
.clock-info { flex: 1; min-width: 180px; }
.clock-title { font-weight: 600; }
.clock-card.running .clock-title { color: var(--ok); }
.clock-card.on-break .clock-title { color: var(--warn); }
.clock-time { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock-actions { display: flex; gap: 8px; }
.clock-btn { padding: 10px 18px; font-weight: 600; }

/* ---------- Tageskarten ---------- */
.days { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.day-card { margin-bottom: 0; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.day-sum { font-weight: 700; font-variant-numeric: tabular-nums; }
.day-section { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.section-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer; }
.line:hover { background: #f3f4f6; }
.line.muted, .line.cancelled { cursor: default; }
.line.cancelled { text-decoration: line-through; color: var(--muted); }
.line-main { min-width: 0; }
.line-dur { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress { height: 6px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin: 8px 0 6px; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.progress.over span { background: var(--danger, #dc2626); }
.day-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.day-actions { display: flex; gap: 6px; }
tr.unbooked td { color: var(--muted); font-style: italic; }

/* ---------- Dialoge: Buchung ---------- */
.segmented { display: flex; background: #f3f4f6; border-radius: 10px; padding: 3px; gap: 3px; }
.segmented label { flex: 1; flex-direction: row; justify-content: center; align-items: center; gap: 6px; padding: 7px; border-radius: 8px; color: var(--text); cursor: pointer; font-size: .9rem; }
.segmented label:has(input:checked) { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.segmented input { display: none; }
.day-info { margin: 0; background: var(--primary-tint); border-radius: 8px; padding: 8px 10px; font-size: .88rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.book-now { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px 12px; margin: 0; }
.book-now legend { font-size: .85rem; color: var(--text); padding: 0 4px; }
.quick-add { display: flex; flex-direction: column; gap: 10px; }
.quick-add button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px 16px; text-align: left; border-radius: 12px; }
.quick-add button span { font-size: .85rem; opacity: .85; }

@media (max-width: 760px) {
  .clock-card { padding: 12px; }
  .clock-actions { width: 100%; }
  .clock-btn { flex: 1; }
  .day-actions { width: 100%; }
  .day-actions button { flex: 1; }
  .line:hover { background: none; }
}

/* Kundensuche (Eingabefeld mit Trefferliste) */
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.picker { position: relative; color: var(--text); font-size: 1rem; }
.picker-field { position: relative; }
.picker-field .picker-input { width: 100%; padding-right: 40px; }
.picker-clear { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; padding: 6px 10px; cursor: pointer; }
.picker-clear:hover { color: var(--text); background: none; }
.picker-list { list-style: none; margin: 4px 0 0; padding: 4px; border: 1px solid var(--border, #e5e7eb); border-radius: 10px; background: var(--surface, #fff); max-height: min(45vh, 320px); overflow-y: auto; box-shadow: 0 8px 24px rgba(15, 23, 42, .12); }
.picker-list li { padding: 10px 12px; border-radius: 8px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.picker-list li b { font-weight: 600; }
.picker-list li span { font-size: .82rem; color: var(--muted); }
.picker-list li.active, .picker-list li[data-i]:hover { background: var(--primary-tint); }
.picker-list li.picker-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 6px 12px 2px; cursor: default; }
.picker-list li.picker-empty { color: var(--muted); cursor: default; }
.tt-new-project { background: var(--primary-tint); border-radius: 8px; padding: 10px 12px; align-items: flex-start; }
.tt-new-project input { margin-top: 3px; }

/* Stundenzettel je Kunde (Auswertung) */
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--primary-tint); }
.ts-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin: 14px 0 4px; }
.ts-project { margin: 16px 0 6px; font-size: .95rem; }
.ts-project .muted { font-weight: 400; font-size: .85rem; margin-left: 6px; }

/* Anmeldeseite: Passwort vergessen / festlegen */
.login-link { align-self: center; font-size: .9rem; }
#token-intro { margin: 0; line-height: 1.5; }
.access-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mail-test { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.mail-test label { flex: 1 1 240px; }

/* Verwaltung auf dem Handy: aufklappbares Bereichsmenü statt Reiterleiste */
.section-nav { display: none; position: relative; margin-bottom: 14px; }
.section-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); text-align: left;
}
.section-current { display: flex; flex-direction: column; gap: 2px; }
.section-current strong { font-size: 1.05rem; color: var(--text); }
.section-toggle svg { width: 22px; height: 22px; fill: none; stroke: var(--primary); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; flex: 0 0 auto; }
.section-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.section-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 12px 32px rgba(15, 23, 42, .16);
}
.section-list.hidden { display: none; }
.section-list button { border: 0; background: none; text-align: left; padding: 13px 12px; border-radius: 8px; font-size: 1rem; color: var(--text); display: flex; justify-content: space-between; }
.section-list button.active { background: var(--primary-tint); color: var(--primary); font-weight: 600; }
@media (max-width: 760px) {
  .section-nav { display: block; }
}

/* Verwaltung → Sicherung */
.cloud-fields[hidden] { display: none; }
.notice.warn { background: #fee2e2; color: #991b1b; margin-bottom: 12px; }
.backup-status { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.backup-status > div { display: flex; flex-direction: column; gap: 4px; }

