:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #5d6b78;
  --border: #d9dee3;
  --primary: #1f5f8b;
  --primary-text: #ffffff;
  --danger: #c0362c;
  --success: #2d7d46;
  --invoice: #7a4fc4;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 25, 35, .06), 0 2px 8px rgba(15, 25, 35, .05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f151b;
    --surface: #18212a;
    --surface-2: #212c37;
    --text: #e6edf3;
    --muted: #93a1ae;
    --border: #2e3b47;
    --primary: #5aa9e6;
    --primary-text: #08131c;
    --danger: #f0776c;
    --success: #5cc27f;
    --invoice: #b293ef;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f151b;
  --surface: #18212a;
  --surface-2: #212c37;
  --text: #e6edf3;
  --muted: #93a1ae;
  --border: #2e3b47;
  --primary: #5aa9e6;
  --primary-text: #08131c;
  --danger: #f0776c;
  --success: #5cc27f;
  --invoice: #b293ef;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
}

a { color: var(--primary); }

[hidden] { display: none !important; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-left: -8px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn svg, .tabbar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  outline: none;
}

/* ---------- Navigation unten ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: .72rem;
  text-decoration: none;
}

.tabbar a.active { color: var(--primary); }

.tabbar .tab-primary {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}

.tabbar .tab-primary.active { color: var(--primary-text); outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); }

/* ---------- Buttons & Formulare ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn.small { min-height: 34px; padding: 6px 12px; font-size: .88rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin: 12px 0; }
.btn:active { transform: translateY(1px); }

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { font-size: .85rem; font-weight: 600; color: var(--muted); padding: 0; }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.check { display: flex; align-items: center; gap: 10px; }
.check input { width: 20px; min-height: 20px; }

.grid-2, .grid-3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 420px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 > :last-child { grid-column: span 2; }
}

.form-section {
  margin: 8px 0 -4px;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.form-actions .primary { flex: 1 1 160px; }

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

.colors { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch input { position: absolute; opacity: 0; pointer-events: none; }
.color-swatch span {
  display: block;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--c);
  cursor: pointer;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.color-swatch input:checked + span { box-shadow: 0 0 0 2px var(--text); }
.color-swatch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.segmented {
  display: flex;
  padding: 4px;
  margin: 16px 0 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented > a, .segmented > button {
  flex: 1;
  padding: 9px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.segmented.small { margin: 0; }
.segmented .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.summary {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: .95rem;
}

/* ---------- Karten, Listen, Kennzahlen ---------- */

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

.card-title { margin: 0 0 10px; font-size: 1.05rem; }

.hero { padding: 32px 8px; text-align: center; }
.hero p { color: var(--muted); max-width: 32em; margin: 8px auto 20px; }

.section-title { margin: 20px 0 10px; font-size: 1rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: .8rem; color: var(--muted); }

.list {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.project-item { border-left: 4px solid var(--accent); }

.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub, .item-desc { font-size: .87rem; color: var(--muted); }
.item-desc { color: var(--text); opacity: .85; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-value { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }

.dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; vertical-align: 1px; }

.badge {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
}
.badge.travel { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
.badge.invoice { color: var(--invoice); background: color-mix(in srgb, var(--invoice) 14%, transparent); }

.thumb {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
}
.thumb.invoice { color: var(--invoice); }

.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.empty pre { white-space: pre-wrap; text-align: left; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar select { flex: 1; min-width: 0; }
.toolbar .btn { min-height: 44px; }

.project-head {
  margin-bottom: 12px;
  padding-left: 12px;
  border-left: 4px solid var(--accent);
}
.project-head .notes { margin: 6px 0 0; white-space: pre-wrap; }

/* ---------- Timer ---------- */

.timer { display: flex; flex-direction: column; gap: 12px; }
.timer.running { border-color: var(--primary); }
.timer-head { display: flex; align-items: center; }
.timer-clock { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.timer .row .btn { flex: 1; }

/* ---------- Upload ---------- */

.upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.upload-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.upload-preview { display: grid; place-items: center; max-height: 340px; overflow: hidden; background: var(--surface-2); text-decoration: none; }
.upload-preview img { display: block; max-width: 100%; max-height: 340px; object-fit: contain; }
.file-icon {
  display: grid;
  place-items: center;
  width: 90px;
  height: 110px;
  margin: 20px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-weight: 800;
  font-size: 1.3rem;
}
.upload-meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; font-size: .85rem; }
.upload-meta > span:first-child { min-width: 0; overflow-wrap: anywhere; }

.danger-zone .card-title { color: var(--danger); }

/* ---------- Bericht ---------- */

.report {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .92rem;
}
.report h2 { margin: 0 0 6px; }
.report h3 { margin: 22px 0 8px; font-size: 1rem; }
.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.report-from { text-align: right; }
.table-wrap { overflow-x: auto; }
.report table { width: 100%; border-collapse: collapse; }
.report th, .report td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.report thead th { font-size: .8rem; color: var(--muted); }
.report tfoot th { border-top: 2px solid var(--text); border-bottom: 0; }
.report .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.report small { color: var(--muted); }
.report .calc { max-width: 520px; margin-left: auto; }
.report .calc .total td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: 0; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 56px; }
.signatures div { padding-top: 6px; border-top: 1px solid var(--text); font-size: .8rem; color: var(--muted); }

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

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: .92rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

@media print {
  :root { --text: #000; --muted: #444; --border: #bbb; --surface: #fff; --bg: #fff; color-scheme: light; }
  body { padding: 0; background: #fff; }
  .topbar, .tabbar, #toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .report { border: 0; padding: 0; }
  .report tr { break-inside: avoid; }
}
.nowrap { white-space: nowrap; }
