:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1f2328;
  --muted: #6b6f76;
  --line: #e2ddd4;
  --accent: #2f6f62;
  --accent-text: #ffffff;
  --danger: #b3412e;

  --stomi: #b5652b;
  --stomi-soft: #f6e6d8;
  --urin: #b48a10;
  --urin-soft: #f6eccb;
  --vaeske: #2d6fb3;
  --vaeske-soft: #dceaf7;

  --radius: 18px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --surface: #1f2328;
    --surface-2: #2a2f35;
    --text: #eceae6;
    --muted: #9aa0a8;
    --line: #333940;
    --accent: #5fb3a1;
    --accent-text: #0e1a17;
    --danger: #ef7d68;

    --stomi: #e59a5f;
    --stomi-soft: #3a2a1d;
    --urin: #e2bf4c;
    --urin-soft: #362f17;
    --vaeske: #6aa8e8;
    --vaeske-soft: #1b2c3e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .9rem; min-height: 1.3em; }
.hint { color: var(--muted); font-size: .85rem; }
.center { text-align: center; margin: 8px 0 24px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-t)) 18px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.title { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.subtitle { color: var(--muted); font-size: .9rem; }
.sync {
  font-size: .8rem; padding: 4px 10px; border-radius: 99px;
  background: var(--urin-soft); color: var(--text);
}

main {
  max-width: 560px; margin: 0 auto;
  padding: 4px 16px calc(96px + var(--safe-b));
}
.section-label {
  font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 18px 4px 8px;
}

/* ---------- Kort ---------- */
.cards { display: grid; gap: 10px; }
.card {
  position: relative; text-align: left;
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto;
  column-gap: 12px;
  padding: 16px 18px; border: 0; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.card:active { transform: scale(.985); }
.card-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .95rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.card-value { font-size: 1rem; color: var(--muted); }
.card-value b { font-size: 2.1rem; font-weight: 700; color: var(--text); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card-meta { font-size: .85rem; color: var(--muted); }
.card-plus {
  grid-column: 2; grid-row: 1 / span 3; align-self: center;
  width: 52px; height: 52px; border-radius: 16px;
  display: grid; place-items: center;
  font-size: 1.9rem; font-weight: 400; line-height: 1;
  background: var(--soft); color: var(--c);
}
.t-stomi { --c: var(--stomi); --soft: var(--stomi-soft); }
.t-urin { --c: var(--urin); --soft: var(--urin-soft); }
.t-vaeske { --c: var(--vaeske); --soft: var(--vaeske-soft); }

.balance {
  margin-top: 10px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.balance-label { font-weight: 600; font-size: .95rem; }
.balance-sub { color: var(--muted); font-size: .8rem; }
.balance-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.balance-value.neg { color: var(--danger); }

/* ---------- Tidslinje ---------- */
.timeline {
  display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px;
  height: 84px; align-items: end;
  padding: 10px 10px 0; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
}
.tl-col { display: flex; flex-direction: column-reverse; gap: 1px; height: 100%; justify-content: flex-start; }
.tl-col.future { background: repeating-linear-gradient(0deg, transparent 0 6px, var(--line) 6px 7px); opacity: .5; border-radius: 3px; }
.tl-col.now { box-shadow: inset 0 -2px 0 var(--accent); }
.tl-col span { display: block; border-radius: 2px; min-height: 2px; }
.tl-col .s { background: var(--stomi); }
.tl-col .u { background: var(--urin); }
.tl-col .v { background: var(--vaeske); }
.timeline-axis {
  display: flex; justify-content: space-between;
  padding: 4px 10px 8px; font-size: .72rem; color: var(--muted);
  background: var(--surface); border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Lister ---------- */
.entries { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.entries:empty::before { content: "Ingen registreringer endnu – tryk på + ovenfor."; display: block; padding: 18px; color: var(--muted); font-size: .9rem; }
.entry {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; background: none; text-align: left;
  border-top: 1px solid var(--line);
}
.entries li:first-child .entry { border-top: 0; }
.entry-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; width: 46px; flex: none; }
.entry-type { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.entry-type small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-ml { font-weight: 600; font-variant-numeric: tabular-nums; }
.entry.pending { opacity: .6; }

.day { margin-bottom: 16px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 0 4px 8px; font-weight: 600; flex-wrap: wrap; gap: 4px 12px;
}
.day-head small { font-weight: 400; font-size: .8rem; }
.day-totals { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.pill {
  font-size: .8rem; padding: 3px 10px; border-radius: 99px;
  background: var(--soft); color: var(--text); font-variant-numeric: tabular-nums;
}
.pill b { color: var(--c); }
.pill.bal { --soft: var(--surface-2); }

/* ---------- Paneler & felter ---------- */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: grid; gap: 12px; margin-bottom: 8px; }
.row-link { display: flex; justify-content: space-between; color: var(--accent); font-weight: 600; text-decoration: none; }
.field { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.field input {
  width: 100%; padding: 12px 14px; font-size: 1rem; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  min-height: 48px;
}
.field input:focus, .ml-field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.wide { width: 100%; }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: .5; }

/* ---------- Login ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; text-align: center; display: grid; gap: 10px; }
.auth-card form { display: grid; gap: 12px; text-align: left; margin-top: 12px; }
.auth-logo { margin: 0 auto; border-radius: 16px; }
.auth h1 { font-size: 1.6rem; }

/* ---------- Bundmenu ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: grid; justify-items: center; gap: 2px;
  border: 0; background: none; padding: 6px 0; font-size: .75rem; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* ---------- Registrerings-ark ---------- */
.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 24px 24px 0 0;
  background: var(--surface); color: var(--text);
  max-height: 94dvh;
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 24px; } }
.sheet::backdrop { background: rgba(0,0,0,.4); }
.sheet[open] { animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet form { display: grid; gap: 14px; padding: 10px 18px calc(18px + var(--safe-b)); }
.sheet-grip { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 4px; }
.sheet h2 { font-size: 1.15rem; }

.type-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.type-switch label { position: relative; }
.type-switch input { position: absolute; opacity: 0; inset: 0; }
.type-switch span {
  display: block; text-align: center; padding: 10px 0; border-radius: 12px;
  border: 1.5px solid var(--line); font-weight: 600; font-size: .95rem;
}
.type-switch input:checked + span { background: var(--soft); border-color: var(--c); color: var(--text); }
.type-switch input:focus-visible + span { outline: 2px solid var(--accent); }

.ml-field { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.ml-field input {
  width: 6ch; text-align: right; font-size: 3rem; font-weight: 700; letter-spacing: -.02em;
  border: 0; border-bottom: 2px solid var(--line); background: none; padding: 0 4px; border-radius: 0;
  -moz-appearance: textfield;
}
.ml-field input::-webkit-outer-spin-button, .ml-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ml-field span { font-size: 1.3rem; color: var(--muted); }

.presets, .quick-time { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.presets button, .quick-time button {
  min-height: 40px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--bg); font-size: .9rem; font-variant-numeric: tabular-nums;
}
.presets button.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.when { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  transition: .2s ease; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast button { margin-left: 10px; background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
