/* =====================================================================
   Arbeitszeit – App-Styles
   Mobile-First · Light/Dark · Safe-Areas (iPhone) · WCAG-AA-Kontraste
   ===================================================================== */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --ink: #15171c;
  --muted: #5d6372;
  --line: #e2e4ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;

  --work: #15803d;      /* Arbeit läuft */
  --work-soft: #e7f6ec;
  --pause: #b45309;     /* Pause */
  --pause-soft: #fdf1e3;
  --stop: #374151;
  --danger: #c0352b;
  --danger-soft: #fdecea;
  --neg: #c0352b;
  --pos: #15803d;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --ink: #eceef2;
    --muted: #a0a6b4;
    --line: #2a2f38;
    --accent: #4c8dff;
    --work: #3ccf76;
    --work-soft: #12301f;
    --pause: #f2a33a;
    --pause-soft: #33240f;
    --stop: #c7ccd6;
    --danger: #ff6b5e;
    --danger-soft: #3a1714;
    --neg: #ff7a6e;
    --pos: #46d282;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.spacer { flex: 1; }

.skip { position: absolute; left: -9999px; top: 8px; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* ---------- Kopf & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.01em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: background .3s; }
body[data-status="working"] .brand-dot { background: var(--work); box-shadow: 0 0 0 4px var(--work-soft); }
body[data-status="paused"] .brand-dot { background: var(--pause); box-shadow: 0 0 0 4px var(--pause-soft); }
body[data-status="stale"] .brand-dot { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); }

/* backdrop-filter würde die fixierte Tab-Leiste an den Header binden
   (neuer Containing Block) → auf Mobilgeräten deckender Hintergrund */
@media (max-width: 759.98px) {
  .topbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .table .col-note, .table td.note { display: none; }
}

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .tabs { position: static; display: flex; height: auto; padding: 0; background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; margin-left: auto; gap: 4px; }
  .tab { flex-direction: row; gap: 6px; font-size: .9rem; padding: 8px 12px; border-radius: 10px; }
  .tab svg { width: 18px; height: 18px; }
  .tab[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
}

/* ---------- Layout ---------- */
main { max-width: 920px; margin: 0 auto; padding: 16px; outline: none; }
.view { display: grid; gap: 16px; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } * { transition: none !important; } }

.banner { max-width: 920px; margin: 12px auto 0; padding: 10px 14px; border-radius: var(--radius-sm); font-size: .92rem; }
.banner-warn { background: var(--pause-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--pause) 40%, transparent); margin-inline: 16px; }
.banner-danger { background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); margin-inline: 16px; }
@media (min-width: 952px) { .banner-warn, .banner-danger { margin-inline: auto; } }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border: 1px solid var(--line); }
.card-flush { padding: 0; overflow: hidden; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 50%, transparent); background: var(--danger-soft); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-title { font-size: 1.05rem; margin: 0 0 10px; letter-spacing: -.01em; }
.card-head .card-title { margin: 0; }
.card-subtitle { font-size: .95rem; margin: 0 0 6px; }
.link { font-weight: 600; text-decoration: none; font-size: .92rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type="date"], .toolbar input[type="month"] { flex: 1 1 160px; min-width: 0; }

/* ---------- Stempeluhr ---------- */
.clock-card { text-align: center; padding: 22px 18px; }
.clock-head { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: .85rem; background: var(--surface-2); color: var(--muted); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
body[data-status="working"] .pill { background: var(--work-soft); color: var(--work); }
body[data-status="paused"] .pill { background: var(--pause-soft); color: var(--pause); }
body[data-status="stale"] .pill { background: var(--danger-soft); color: var(--danger); }
body[data-status="working"] .pill::before { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.clock-time { font-size: clamp(3.2rem, 15vw, 5rem); font-weight: 750; letter-spacing: -.04em; line-height: 1.05; margin: 14px 0 2px; }
.clock-sub { font-size: .92rem; }
.clock-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.clock-actions .btn:only-child, .clock-actions .btn.full { grid-column: 1 / -1; }

/* ---------- Kennzahlen ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; }
.stat-sub { font-size: .8rem; color: var(--muted); }
.neg { color: var(--neg); } .pos { color: var(--pos); }

/* ---------- Hinweise ---------- */
.hints { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hints li { background: var(--pause-soft); border-left: 3px solid var(--pause); padding: 8px 12px; border-radius: 8px; font-size: .9rem; }

/* ---------- Zeitleiste ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.timeline li { display: grid; grid-template-columns: 12px 1fr auto; gap: 12px; align-items: center; padding: 10px 6px; border-radius: 10px; }
.timeline li + li { border-top: 1px solid var(--line); }
.timeline .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--work); }
.timeline .is-break .dot, .timeline li.is-break .dot { background: var(--pause); }
.timeline .t-main { font-weight: 600; }
.timeline .t-note { display: block; font-size: .85rem; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.timeline .t-dur { font-weight: 700; white-space: nowrap; }
.timeline .empty { display: block; color: var(--muted); padding: 10px 6px; border: 0; }
.timeline-edit li { cursor: pointer; }
.timeline-edit li:hover { background: var(--surface-2); }
.tag-open { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--work-soft); color: var(--work); margin-left: 6px; vertical-align: middle; }
.tag-open.stale { background: var(--danger-soft); color: var(--danger); }

.day-totals { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: .92rem; color: var(--muted); margin-bottom: 8px; }
.day-totals strong { color: var(--ink); }

/* ---------- Formulare ---------- */
.grid-form { display: grid; gap: 12px; }
.grid-2, .grid-3 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.span-all { grid-column: 1 / -1; }
label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; /* verhindert iOS-Zoom */
  color: var(--ink); background: var(--surface); width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type="file"] { padding: 8px; }
textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
input:invalid:not(:placeholder-shown):not(:focus) { border-color: var(--danger); }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 0; font-size: .9rem; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented label { display: block; color: var(--ink); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 1px; }
.segmented span { display: block; text-align: center; padding: 8px; border-radius: 9px; font-weight: 600; cursor: pointer; }
.segmented input:checked + span { background: var(--surface); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); }

/* ---------- Buttons ---------- */
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.btn {
  appearance: none; -webkit-appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 650; text-decoration: none;
  cursor: pointer; transition: transform .08s ease, background .15s, opacity .15s; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.is-busy { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn-icon { width: 44px; padding: 0; font-size: 1.4rem; line-height: 1; }
.btn-xl { min-height: 64px; font-size: 1.12rem; border-radius: 16px; border: 0; color: #fff; }
.btn-start { background: var(--work); }
.btn-pause { background: var(--pause); }
.btn-stop { background: var(--stop); }
@media (prefers-color-scheme: dark) { .btn-xl { color: #0f1115; } }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.table td.note { white-space: normal; max-width: 260px; color: var(--muted); font-size: .85rem; }
.table .num { text-align: right; }
.table tr.weekend td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table tr.today td { box-shadow: inset 3px 0 0 var(--accent); }
.table tr.has-stale td { background: var(--danger-soft); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tfoot th { padding: 10px 12px; text-align: left; }

/* ---------- Audit / Checks ---------- */
.audit { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.audit li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.audit .a-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.audit .a-action { font-weight: 700; }
.audit .a-meta { color: var(--muted); font-size: .8rem; }
.audit .a-diff { color: var(--muted); font-size: .82rem; word-break: break-word; }
.checks, .plain-list { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.checks li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: start; }
.checks .c-val { color: var(--muted); text-align: right; }
.checks .c-hint { grid-column: 2 / -1; font-size: .82rem; color: var(--danger); }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; }
.details summary { cursor: pointer; font-weight: 600; margin-top: 14px; }

/* ---------- Dialoge & Toast ---------- */
.dialog { border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.dialog::backdrop { background: rgba(10, 12, 16, .45); backdrop-filter: blur(2px); }
.dialog-sm { width: min(400px, calc(100vw - 24px)); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  max-width: min(560px, calc(100vw - 24px)); padding: 12px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: .92rem; box-shadow: var(--shadow);
  white-space: pre-line;
}
.toast.is-error { background: var(--danger); color: #fff; }
@media (min-width: 760px) { .toast { bottom: 24px; } }

/* ---------- Pause eintragen ---------- */
.clock-secondary { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.btn-soft { background: var(--surface-2); border-color: transparent; min-height: 40px; padding: 8px 14px; font-size: .92rem; }
.row-actions-tight { margin-top: 0; }
.chips { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 8px 14px; font: inherit; font-weight: 600; min-height: 40px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--pause); border-color: var(--pause); color: #fff; }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { color: #0f1115; } }
