/* Zeittracker – Styles */
:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --line: #dcdfd7;
  --text: #15181a;
  --muted: #646a6d;
  --accent: #16a34a;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --warn-bg: #fff7e0;
  --warn-ink: #7a5300;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1012;
    --surface: #171a1d;
    --surface-2: #20242a;
    --line: #2b3037;
    --text: #eef0f1;
    --muted: #9aa1a8;
    --accent: #22c55e;
    --accent-ink: #06210f;
    --danger: #f87171;
    --warn-bg: #2a2310;
    --warn-ink: #f5d27a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- Layout */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 2px 16px; }
.topbar h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
.topbar .sub { color: var(--muted); font-size: .9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 1rem; margin: 0 0 12px; }
.card h2 .muted { font-weight: 400; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: center; z-index: 20;
}
.nav-inner { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; max-width: 560px; }
.nav button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .72rem; color: var(--muted); padding: 6px 0;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.active { color: var(--text); font-weight: 600; }
.nav button.active svg { color: var(--accent); }

/* ---------------------------------------------------------------- Buttons & Formulare */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
input[type=text], input[type=password], input[type=date], input[type=datetime-local], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 6px; min-height: 46px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: flex-start; gap: 12px; color: var(--text); font-size: .95rem; padding: 8px 0; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: .8rem; }
.err { color: var(--danger); font-size: .9rem; margin: 0 0 12px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.stack > * + * { margin-top: 10px; }

/* ---------------------------------------------------------------- Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand b { font-size: 1.3rem; display: block; }

/* ---------------------------------------------------------------- Tracker */
.running-strip { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.run-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--accent));
  border-radius: 12px; padding: 8px 8px 8px 12px;
}
.run-chip .nm { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-chip .t { font-variant-numeric: tabular-nums; color: var(--muted); }
.run-chip button { min-height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; font-size: .85rem; }

.hero { display: flex; justify-content: center; padding: 8px 0 22px; }
.big {
  --c: var(--accent);
  position: relative; width: min(72vw, 260px); aspect-ratio: 1; border-radius: 50%;
  border: 0; padding: 0; background: var(--surface);
  box-shadow: inset 0 0 0 6px var(--c), var(--shadow);
  display: grid; place-items: center; text-align: center;
  transition: transform .12s ease, background .25s ease;
  touch-action: manipulation;
}
.big:active { transform: scale(.97); }
.big:disabled { opacity: .7; }
.big-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0 22px; max-width: 100%; }
.big-state { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.big-time { font-size: 2.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big-cat { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.big-hint { font-size: .78rem; color: var(--muted); }
.big .play { width: 54px; height: 54px; color: var(--c); }
.big.is-running { background: var(--c); color: #fff; box-shadow: var(--shadow); }
.big.is-running .big-state, .big.is-running .big-hint { color: rgba(255,255,255,.85); }
.big.is-running::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%;
  border: 3px solid var(--c); opacity: .5; animation: pulse 2.2s ease-out infinite; pointer-events: none;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.big.is-running .dot { animation: blink 1.4s ease-in-out infinite; }
@keyframes pulse { 0% { transform: scale(.96); opacity: .55; } 100% { transform: scale(1.12); opacity: 0; } }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .big.is-running::after, .big.is-running .dot { animation: none; } }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 10px; }
.section-title h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0; }
.catlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cat {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 56px; padding: 10px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
}
.cat.sel { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.sw { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.cat .nm { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .meta { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.cat .live { color: var(--c); font-weight: 700; }
.tag { font-size: .68rem; font-weight: 700; letter-spacing: .05em; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.add-cat { margin-top: 10px; width: 100%; min-height: 48px; border: 1px dashed var(--line); background: transparent; border-radius: 14px; color: var(--muted); font-weight: 600; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* ---------------------------------------------------------------- Einträge */
.datebar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.datebar .label { flex: 1; text-align: center; font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.entry:last-child { border-bottom: 0; }
.entry .body { flex: 1; min-width: 0; }
.entry .t1 { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.entry .t2 { color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }
.entry .note { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .dur { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge-run { color: var(--accent); font-size: .75rem; font-weight: 700; }
.badge-auto { color: var(--warn-ink); background: var(--warn-bg); font-size: .7rem; padding: 1px 6px; border-radius: 6px; }

/* ---------------------------------------------------------------- Auswertung */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; min-height: 38px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.kpi .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .k { font-size: .78rem; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-bottom: 0; }
td.wrap { white-space: normal; min-width: 120px; }
.bar { height: 6px; border-radius: 3px; background: var(--c); min-width: 2px; }
.bar-cell { width: 30%; min-width: 60px; }
.catname { display: flex; align-items: center; gap: 8px; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------------------------------------------------------------- Einstellungen */
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; }
.list-row .s { font-size: .82rem; color: var(--muted); }
.list-row.click { cursor: pointer; }
.list-row.archived { opacity: .55; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 8px 0 14px; }
.swatches button { aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; background: var(--c); }
.swatches button.on { border-color: var(--text); }
.custom-color { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
.custom-color input { width: 48px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; }

.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 12px; margin: 10px 0; }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; }
code.secret { display: block; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; font-size: .9rem; user-select: all; }

/* ---------------------------------------------------------------- Modal & Toast */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease;
}
@media (min-width: 640px) { .modal-back { align-items: center; } .modal { border-radius: 20px; } }
.modal h3 { margin: 0 0 14px; font-size: 1.15rem; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .5; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: .9rem; font-weight: 600; z-index: 60; max-width: calc(100% - 32px);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

.boot { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); }

/* ---------------------------------------------------------------- Setup-Seite */
body.setup { display: grid; place-items: center; padding: 24px 16px; }
.setup-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; max-width: 460px; width: 100%; }
.setup-card h1 { margin-top: 0; font-size: 1.3rem; }
.setup-card hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.setup-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-all; }

.datebar .label { position: relative; }
.datebar .label input[type=date] { position: absolute; inset: 0; opacity: 0; margin: 0; min-height: 0; width: 100%; height: 100%; cursor: pointer; }
.icon-btn:disabled { opacity: .35; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0 14px; }
table.az { font-size: .82rem; }
table.az th, table.az td { padding: 8px 5px; }
table.az td:first-child, table.az th:first-child { padding-left: 0; }
table.az td:last-child, table.az th:last-child { padding-right: 0; }
.chart .axis { font-size: 9px; }
