:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f7f7fa;
  --text: #11131a;
  --text-2: #6b7280;
  --text-3: #9aa0ab;
  --line: #e3e3e9;
  --accent: #0a6cff;
  --accent-soft: #e8f0ff;
  --plus: #0a8a4a;
  --minus: #d4351c;
  --warn: #b35309;
  --warn-soft: #fff4e5;
  --radius: 14px;
  --tap: 46px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #f5f5f7;
    --text-2: #9ea3ad;
    --text-3: #70757f;
    --line: #333337;
    --accent: #4b94ff;
    --accent-soft: #10243f;
    --plus: #3ddc84;
    --minus: #ff6b5e;
    --warn: #ffb570;
    --warn-soft: #332312;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

.app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.4px; }

.sync-badge {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--text-2); font-size: 12.5px; font-weight: 600;
  padding: 7px 11px; border-radius: 999px; cursor: pointer;
  min-height: 34px;
}
.sync-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.sync-badge.ok .dot { background: var(--plus); }
.sync-badge.pending .dot { background: var(--warn); }
.sync-badge.error .dot { background: var(--minus); }
.sync-badge.busy .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- Layout ---------- */

.view {
  flex: 1;
  padding: 14px 16px calc(84px + var(--safe-b));
  max-width: 620px; width: 100%; margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 12px;
}
.card.flush { padding: 0; overflow: hidden; }

.section-title {
  margin: 20px 4px 8px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-3);
}
.section-title:first-child { margin-top: 4px; }

.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 10px; }

/* ---------- Heute ---------- */

.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav .nav-btn {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 19px; cursor: pointer;
}
.daynav .day-label { flex: 1; text-align: center; }
.daynav .day-label b { display: block; font-size: 16px; font-weight: 650; }
.daynav .day-label span { display: block; font-size: 12.5px; color: var(--text-2); }

.balance { text-align: center; padding: 18px 14px 16px; }
.balance .value { font-size: 40px; font-weight: 700; letter-spacing: -1.2px; line-height: 1.05; }
.balance .caption { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }

.stamp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stamp button {
  min-height: 54px; border-radius: var(--radius); border: 0;
  font-size: 16px; font-weight: 650; cursor: pointer;
  background: var(--accent); color: #fff;
}
.stamp button.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--line); }
.stamp button:disabled { opacity: .4; }

.times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12px; font-weight: 650; color: var(--text-2); letter-spacing: .2px; }
.field input, .field select, .field textarea {
  font: inherit; color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 12px; min-height: var(--tap);
  width: 100%; appearance: none;
}
.field input[type="time"] { font-variant-numeric: tabular-nums; }
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.field.wide { grid-column: 1 / -1; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 999px; padding: 9px 13px; font-size: 14px; font-weight: 600;
  min-height: 40px; cursor: pointer;
}
.chip.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; text-align: center; }
.totals .cell { padding: 12px 6px; background: var(--card-2); }
.totals .cell:first-child { border-radius: 11px 0 0 11px; }
.totals .cell:last-child { border-radius: 0 11px 11px 0; }
.totals .k { font-size: 11.5px; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.totals .v { font-size: 20px; font-weight: 700; margin-top: 2px; }

.notice {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--warn-soft); color: var(--warn);
  border-radius: 11px; padding: 11px 12px; font-size: 13.5px; font-weight: 550;
}
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice b { font-weight: 700; }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.hol { background: var(--warn-soft); color: var(--warn); }

/* ---------- Monat ---------- */

.monthnav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.monthnav .nav-btn {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 19px; cursor: pointer;
}
.monthnav .month-label { flex: 1; text-align: center; font-size: 16px; font-weight: 650; }

.dayrow {
  display: grid;
  grid-template-columns: 44px 1fr 62px 62px;
  align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; color: inherit; font: inherit; cursor: pointer;
}
.dayrow:last-child { border-bottom: 0; }
.dayrow.is-weekend { background: var(--card-2); }
.dayrow.is-today { box-shadow: inset 3px 0 0 var(--accent); }
.dayrow .d { font-weight: 650; }
.dayrow .d span { display: block; font-size: 11px; color: var(--text-2); font-weight: 500; }
.dayrow .t { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dayrow .t b { color: var(--text); font-weight: 600; }
.dayrow .n { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.dayrow .n.sub { color: var(--text-2); font-size: 12.5px; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: 11px; overflow: hidden; }
.summary div { background: var(--card); padding: 11px 12px; }
.summary .k { font-size: 11.5px; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.summary .v { font-size: 17px; font-weight: 650; margin-top: 1px; font-variant-numeric: tabular-nums; }

/* ---------- Buttons / Listen ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); width: 100%;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; padding: 10px 14px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--minus); }
.btn:disabled { opacity: .45; cursor: default; }
.btn + .btn { margin-top: 8px; }

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item .k { font-size: 14px; font-weight: 600; }
.list-item .v { font-size: 13.5px; color: var(--text-2); text-align: right; word-break: break-word; }

.steps { counter-reset: step; }
.steps li { margin-bottom: 10px; font-size: 14px; }
.steps code {
  background: var(--card-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px; font-size: 12.5px;
  word-break: break-all;
}

/* ---------- Tabbar ---------- */

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1 1 0; max-width: 170px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; cursor: pointer;
  color: var(--text-3); font-size: 10.5px; font-weight: 600;
  padding: 5px 2px;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }

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

.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(86px + var(--safe-b));
  background: #1c1c1e; color: #fff;
  padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 550;
  max-width: min(92vw, 420px); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 50; box-shadow: 0 8px 28px rgba(0,0,0,.28);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--minus); }

@media (prefers-color-scheme: dark) {
  .toast { background: #3a3a3c; }
}

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.linklike {
  background: none; border: 0; padding: 0; margin: 0;
  color: var(--accent); font: inherit; font-size: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
a.btn { text-decoration: none; }
