:root {
  color-scheme: light dark;
  --window: #ffffff;
  --sidebar: rgb(232 232 236 / 0.8);
  --toolbar: rgb(255 255 255 / 0.85);
  --control: #ffffff;
  --group: #f5f5f7;
  --separator: rgb(0 0 0 / 0.1);
  --hover: rgb(0 0 0 / 0.05);
  --label: rgb(0 0 0 / 0.88);
  --label-2: rgb(0 0 0 / 0.6);
  --label-3: rgb(0 0 0 / 0.5);
  --track: rgb(0 0 0 / 0.08);
  --accent: #007aff;
  --accent-ink: #0062cc;
  --on-accent: #ffffff;
  --green: #248a3d;
  --red: #d70015;
  --sheet-shadow: 0 16px 48px rgb(0 0 0 / 0.25);
}

@media (prefers-color-scheme: dark) {
  :root {
    --window: #1e1e20;
    --sidebar: rgb(44 44 48 / 0.8);
    --toolbar: rgb(30 30 32 / 0.85);
    --control: #3a3a3e;
    --group: #2a2a2d;
    --separator: rgb(255 255 255 / 0.12);
    --hover: rgb(255 255 255 / 0.07);
    --label: rgb(255 255 255 / 0.9);
    --label-2: rgb(255 255 255 / 0.62);
    --label-3: rgb(255 255 255 / 0.5);
    --track: rgb(255 255 255 / 0.12);
    --accent: #0a84ff;
    --accent-ink: #64b0ff;
    --green: #30d158;
    --red: #ff6961;
    --sheet-shadow: 0 16px 48px rgb(0 0 0 / 0.6);
  }
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--window);
  color: var(--label);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  cursor: default;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 13px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }

button, input, select { font: inherit; color: inherit; }

button {
  min-height: 24px;
  padding: 2px 10px;
  background: var(--control);
  border: 0.5px solid var(--separator);
  border-radius: 6px;
  box-shadow: 0 0.5px 1px rgb(0 0 0 / 0.12);
  cursor: default;
}
button:active { filter: brightness(0.94); }
button.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 500; }
button.plain { padding: 0; min-height: 0; background: none; border: 0; box-shadow: none; color: var(--accent-ink); }
button.danger { color: var(--red); }

input, select {
  width: 100%;
  min-height: 26px;
  padding: 3px 7px;
  background: var(--control);
  border: 0.5px solid var(--separator);
  border-radius: 6px;
  box-shadow: inset 0 0.5px 1px rgb(0 0 0 / 0.06);
}
input[type='checkbox'] { width: 14px; min-height: 14px; margin: 0; accent-color: var(--accent); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; }

/* Fenster */
.window { display: grid; grid-template-columns: 200px minmax(0, 1fr); height: 100%; }

.sidebar {
  padding: 14px 10px;
  overflow-y: auto;
  background: var(--sidebar);
  border-right: 0.5px solid var(--separator);
  -webkit-backdrop-filter: blur(30px);
  backdrop-filter: blur(30px);
}
.side-heading { padding: 14px 8px 4px; color: var(--label-3); font-size: 11px; font-weight: 600; }
.side-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 28px;
  padding: 3px 8px;
  background: none;
  border: 0;
  border-radius: 6px;
  box-shadow: none;
  text-align: left;
}
.side-item:hover { background: var(--hover); }
.side-item[aria-current='page'] { background: var(--accent); color: var(--on-accent); }
.side-glyph { width: 16px; color: var(--accent-ink); text-align: center; }
.side-item[aria-current='page'] .side-glyph { color: inherit; }

.content { display: flex; flex-direction: column; min-width: 0; height: 100%; }

.toolbar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 16px;
  background: var(--toolbar);
  border-bottom: 0.5px solid var(--separator);
}
.stepper { display: flex; }
.stepper button { width: 28px; padding: 0; font-size: 16px; line-height: 1; }
.stepper button:first-child { border-radius: 6px 0 0 6px; }
.stepper button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.toolbar-title { padding: 0; background: none; border: 0; box-shadow: none; font-size: 15px; font-weight: 600; }
.toolbar-action { margin-left: auto; }
.badge { padding: 1px 7px; background: var(--track); border-radius: 9px; color: var(--label-2); font-size: 11px; }

main { flex: 1; min-height: 0; padding: 18px 20px 32px; overflow-y: auto; }
.page { max-width: 880px; margin: 0 auto; }

/* Bausteine */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { padding: 10px 12px; background: var(--group); border-radius: 10px; }
.stat-label { color: var(--label-2); font-size: 12px; }
.stat-value { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.negative { color: var(--red); }
.positive { color: var(--green); }

.section { margin-bottom: 20px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 6px 10px; }
.section-sum { margin-right: 10px; color: var(--label-2); }

.list { overflow: hidden; background: var(--group); border-radius: 10px; }
.row { display: grid; align-items: center; gap: 12px; min-height: 34px; padding: 6px 10px; border-top: 0.5px solid var(--separator); }
.row:first-child { border-top: 0; }
.row.clickable:hover { background: var(--hover); }
.row[aria-selected='true'] { background: var(--accent); color: var(--on-accent); }
.row[aria-selected='true'] .sub { color: inherit; }
.row-kv { grid-template-columns: minmax(0, 1fr) auto; }
.amount { text-align: right; white-space: nowrap; }
.sub { color: var(--label-2); font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-budget { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) 84px 84px 84px 22px; }
.table-head { color: var(--label-2); font-size: 11px; font-weight: 500; }
.add { width: 22px; min-height: 22px; padding: 0; line-height: 1; }

.meter { height: 6px; overflow: hidden; background: var(--track); border-radius: 3px; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter > span.pot { background: var(--green); }
.meter > span.over { background: var(--red); }

.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; padding: 8px 12px; margin-bottom: 14px; background: var(--group); border-radius: 10px; }
.check { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; margin-top: 8px; border-radius: 10px; background: var(--group); }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.inspector { position: sticky; top: 0; padding: 12px; background: var(--group); border-radius: 10px; }
.inspector h2 { font-size: 15px; }
.inspector-value { margin: 2px 0 8px; font-size: 24px; font-weight: 600; }
.inspector dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; margin: 0 0 10px; }
.inspector dt { color: var(--label-2); }
.inspector dd { margin: 0; text-align: right; }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.inspector h3 { margin: 10px 0 4px; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 12px; }
.filters select { width: 240px; }
.inline-check { display: flex; align-items: center; gap: 6px; }

.row-tx { grid-template-columns: 78px minmax(0, 1fr) 100px 124px; }
.row-tx .tx-actions { display: flex; gap: 10px; visibility: hidden; }
.row-tx:hover .tx-actions, .row-tx:focus-within .tx-actions { visibility: visible; }

.row-setting { grid-template-columns: minmax(0, 1fr) 110px auto; }
.row-setting input { text-align: right; }
.row-setting.archived { color: var(--label-3); }

.empty { padding: 24px 12px; color: var(--label-2); text-align: center; }

.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart-grid { stroke: var(--separator); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); stroke: var(--group); stroke-width: 2; }
.chart-label { fill: var(--label-2); font-size: 11px; }
.chart-cross { stroke: var(--label-3); stroke-width: 1; }
.chart-tip { position: absolute; top: 0; padding: 4px 8px; background: var(--control); border: 0.5px solid var(--separator); border-radius: 6px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.15); font-size: 12px; white-space: nowrap; pointer-events: none; transform: translateX(-50%); }

/* Abschluss */
.steps { display: grid; gap: 14px; }
.step { padding: 12px; background: var(--group); border-radius: 10px; }
.step h2 { margin-bottom: 6px; }
.step-note { margin-bottom: 8px; color: var(--label-2); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.calc { display: grid; grid-template-columns: 1fr auto; row-gap: 2px; margin-top: 10px; }
.calc > :nth-child(even) { padding-left: 12px; text-align: right; }
.calc .total { padding-top: 4px; border-top: 0.5px solid var(--separator); font-weight: 600; }
.radio { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--label); font-size: 13px; }
.radio input { width: 14px; min-height: 14px; margin: 0; accent-color: var(--accent); }

label { display: block; color: var(--label-2); font-size: 12px; }
label > input, label > select { margin-top: 2px; color: var(--label); font-size: 13px; }

/* Sheets hängen wie am Mac oben am Fenster */
dialog {
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: 0 auto;
  padding: 0;
  color: var(--label);
  background: var(--window);
  border: 0.5px solid var(--separator);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  box-shadow: var(--sheet-shadow);
}
dialog[open] { animation: sheet-in 0.18s ease-out; }
dialog::backdrop { background: rgb(0 0 0 / 0.2); }
@keyframes sheet-in { from { transform: translateY(-16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { dialog[open] { animation: none; } }
#sheet-form { display: grid; gap: 10px; padding: 16px; }
#sheet-form h2 { font-size: 14px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.sheet-actions .danger { margin-right: auto; }
.form-error { color: var(--red); font-size: 12px; }
.annual-line { display: grid; grid-template-columns: minmax(0, 1fr) 90px 22px; gap: 6px; }
.annual-line input:last-of-type { text-align: right; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 3;
  max-width: calc(100vw - 32px);
  padding: 6px 12px;
  background: var(--label);
  color: var(--window);
  border-radius: 8px;
  transform: translateX(-50%);
}
#toast.error { background: var(--red); color: #ffffff; }

/* Anmeldung */
.login { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 16px; }
.login-card { display: grid; gap: 12px; width: min(340px, 100%); padding: 20px; background: var(--group); border-radius: 14px; text-align: center; }
.login-card label { text-align: left; }
.login-card .plain { justify-self: center; }
.code { padding: 8px; background: var(--window); border-radius: 8px; font: 13px/1.5 ui-monospace, Menlo, monospace; user-select: all; overflow-wrap: anywhere; }

/* iPhone: nur Ansicht */
body.phone { font-size: 15px; }
body.phone #app { display: block; height: auto; }
body.phone .section-head { flex-wrap: wrap; }
body.phone .sidebar, body.phone #new-booking { display: none; }
body.phone .content { height: auto; }
body.phone .toolbar { position: sticky; top: 0; z-index: 1; padding-top: max(8px, env(safe-area-inset-top)); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
body.phone main { padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); overflow: visible; }
body.phone .stat-value { font-size: 30px; }
body.phone .row { min-height: 40px; }
body.phone .sub { font-size: 13px; }

@media (max-width: 980px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .inspector { position: static; }
  .row-budget { grid-template-columns: minmax(0, 1.5fr) 76px 76px 76px 22px; }
  .row-budget .meter, .row-budget .col-meter { display: none; }
}
