/* TimeTool – Handy zuerst. Hell/Dunkel nach System. Keine Schrift von aussen. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --fg: #15181d;
  --muted: #5d6673;
  --line: #d9dde3;
  --accent: #1f6feb;
  --accent-fg: #ffffff;
  --in: #1a7f47;
  --in-fg: #ffffff;
  --out: #c2410c;
  --out-fg: #ffffff;
  --warn-bg: #fff4d6;
  --warn-fg: #7a4b00;
  --danger: #b42318;
  --pos: #1a7f47;
  --neg: #b42318;
  --focus: #1f6feb;
  --heat-0: #e7eaee;
  --heat-1: #bfd7ff;
  --heat-2: #86b3ff;
  --heat-3: #4a8cf5;
  --heat-4: #1f5fd1;
  --radius: 14px;
  --tabs-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --fg: #e9edf2;
    --muted: #9aa4b1;
    --line: #2f3640;
    --accent: #5b9dff;
    --accent-fg: #0b1220;
    --in: #2ea56a;
    --in-fg: #06130c;
    --out: #f07a3e;
    --out-fg: #1b0b02;
    --warn-bg: #3a2e10;
    --warn-fg: #ffd98a;
    --danger: #ff6b5e;
    --pos: #4cc38a;
    --neg: #ff7b6e;
    --focus: #8ab8ff;
    --heat-0: #222831;
    --heat-1: #1d3a66;
    --heat-2: #24539a;
    --heat-3: #3a74cf;
    --heat-4: #6aa2ff;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 0.4rem; }
p { margin: 0.4rem 0; }
small, .small { font-size: 0.85rem; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.9rem; }
.center { text-align: center; }
.mono, .recovery-key, .raw { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

.view { padding: calc(16px + var(--safe-t)) 16px 24px; }
.view.center { flex: 1; display: grid; place-items: center; }
.view.narrow { width: 100%; max-width: 480px; margin: 0 auto; }
.view.main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding-top: 12px;
  padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 24px);
}

.brand { font-size: 1.6rem; margin: 0.6rem 0 0.4rem; }
.lead { color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > label { margin-top: 6px; font-weight: 600; font-size: 0.95rem; }

/* Eingaben: ≥ 16 px Schrift (kein Zoom auf iOS), ≥ 48 px hoch */
input[type=email], input[type=text], input[type=password], input[type=number], input[type=date], input[type=time] {
  font: inherit;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  min-width: 0;
}
input:focus { border-color: var(--accent); }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.big { min-height: 72px; font-size: 1.3rem; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.55; cursor: default; }

.error { color: var(--danger); font-weight: 600; }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.check input { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }

.row { display: flex; flex-direction: column; gap: 6px; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.row-buttons .btn { flex: 1 1 120px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 label { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }

/* Anmelden: Mail an uns */
.btn-link { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.copy-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}
.copy-label { flex: none; font-weight: 600; color: var(--muted); }
.copy-value { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 1.05rem; user-select: all; }
.copy-value.code-big { font-size: 1.8rem; letter-spacing: 0.12em; font-weight: 700; }
.copy-field .btn { flex: none; }
.warn-line { background: var(--warn-bg); color: var(--warn-fg); padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.wait-state { font-weight: 600; margin-bottom: 0; }

/* QR */
.qr-box { display: flex; justify-content: center; margin: 8px 0; }
.qr { width: min(280px, 80vw); height: auto; border-radius: 8px; }
.qr-box.small .qr { width: min(200px, 60vw); }

.recovery-key {
  font-size: 1.2rem;
  letter-spacing: 0.04em;
  padding: 14px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 10px;
  word-break: break-all;
  text-align: center;
  user-select: all;
}

/* Kopfzeile und Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(6px + var(--safe-t)) 16px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 700; }
.sync {
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  background: none;
  border: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  cursor: pointer;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--pos); }
.dot.busy { background: var(--accent); }
/* .warn weiter unten ist ein Hinweiskasten; der Punkt darf dessen Abstände nicht erben. */
.dot.warn { background: var(--out); margin: 0; padding: 0; border-radius: 50%; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
}
.tabs button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tabs-h);
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  background: none;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tabs .ico { font-size: 1.25rem; line-height: 1; }
.tabs button[aria-current=page] { color: var(--accent); font-weight: 700; }

.banner {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 0.9rem;
}

/* Start: Stand oben, grosser Knopf im unteren Drittel */
.start { display: flex; flex-direction: column; }
.status { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 12px 0; }
.state { font-size: 1.05rem; color: var(--muted); }
.clock {
  font-size: clamp(2.6rem, 15vw, 4.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin: 0.2rem 0;
}
.today { font-size: 1.15rem; }
.today strong { font-variant-numeric: tabular-nums; font-size: 1.4rem; }
.warn {
  margin: 14px auto 0;
  padding: 10px 14px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  max-width: 420px;
}
.punch-area { padding-bottom: 8px; }
.punch {
  width: 100%;
  min-height: max(128px, 26vh);
  border: 0;
  border-radius: 28px;
  font: inherit;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.15);
  transition: transform 0.08s ease;
}
.punch:active { transform: scale(0.98); }
.punch.in { background: var(--in); color: var(--in-fg); }
.punch.out { background: var(--out); color: var(--out-fg); }
.punch:disabled { opacity: 0.85; }

/* Liste */
.week { margin-bottom: 18px; }
.week-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 10px 0 6px;
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.week-head .sum { color: var(--fg); font-variant-numeric: tabular-nums; text-transform: none; }
.week-head small { color: var(--muted); font-weight: 400; }
.day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
}
.day.open { border-color: var(--out); }
.day header { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.day .date { font-weight: 700; }
.day header .sum { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.live { background: var(--in); color: var(--in-fg); }
.pairs { list-style: none; margin: 0; padding: 0; }
.pair { border-top: 1px solid var(--line); }
.pair:first-child { border-top: 0; }
.pair-row { display: flex; align-items: center; gap: 4px; }
.pair .time {
  font: inherit;
  font-variant-numeric: tabular-nums;
  min-height: 48px;
  min-width: 72px;
  padding: 0 8px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
}
.pair .time:active { background: var(--surface-2); }
.pair .time.missing { color: var(--out); font-weight: 700; text-decoration: underline; }
.pair.running .time.missing { color: var(--in); text-decoration: none; }
.pair .dash { color: var(--muted); }
.pair .dur { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.pair .note { margin: -6px 0 8px 8px; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 32px 8px; }

.fab {
  position: fixed;
  right: calc(16px + var(--safe-r));
  bottom: calc(var(--tabs-h) + var(--safe-b) + 16px);
  z-index: 4;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.25);
  cursor: pointer;
}

/* Dialoge als Blatt von unten */
dialog.sheet {
  width: 100%;
  max-width: 520px;
  margin: auto auto 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
  background: var(--surface);
  color: var(--fg);
  max-height: 92dvh;
  overflow-y: auto;
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin-top: 0; }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 20px; }
}

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg label { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; cursor: pointer; font-weight: 600; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-fg); }
.seg input { accent-color: var(--accent); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(64px + var(--safe-t)); /* oben, damit der Stempel-Knopf frei bleibt */
  z-index: 20;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--fg);
  color: var(--bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
}
.toast .btn { background: var(--bg); color: var(--fg); }
.app[data-view=login] .toast, .app[data-view=setup] .toast, .app[data-view=unlock] .toast { top: calc(16px + var(--safe-t)); }

/* Nerd-Modus */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.card .label { font-size: 0.8rem; color: var(--muted); }
.card strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.card .small { color: var(--muted); font-size: 0.75rem; overflow-wrap: anywhere; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.chart { width: 100%; height: auto; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 9px; font-family: system-ui, sans-serif; }
.chart .bar { fill: var(--accent); opacity: 0.75; }
.chart .bar-ok { fill: var(--pos); opacity: 0.9; }
.chart .target { stroke: var(--out); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart.heat .axis { font-size: 8px; }
.hc0 { fill: var(--heat-0); }
.hc1 { fill: var(--heat-1); }
.hc2 { fill: var(--heat-2); }
.hc3 { fill: var(--heat-3); }
.hc4 { fill: var(--heat-4); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.raw {
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin: 0;
}

@media (min-width: 720px) {
  .view.main { padding-left: 24px; padding-right: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 360px) {
  .tabs button { font-size: 0.7rem; }
}
.btn-link.disabled { opacity: 0.55; pointer-events: none; }
