:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ecebe6;
  --text: #1c1c1a;
  --muted: #6b6a64;
  --line: #dddcd5;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcece6;
  --styrke: #1f6f5c;
  --gange: #c47a2c;
  --svomming: #2f6fb3;
  --annet: #8a8780;
  --good: #1f7a4d;
  --warn: #b5541c;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121311;
    --surface: #1c1d1a;
    --surface-2: #262724;
    --text: #edece7;
    --muted: #9c9b94;
    --line: #33342f;
    --accent: #4fb596;
    --accent-ink: #0d1a15;
    --accent-soft: #1d3a31;
    --styrke: #4fb596;
    --gange: #e09a4f;
    --svomming: #6aa6e6;
    --annet: #8f8d86;
    --good: #5cc28b;
    --warn: #e8894f;
    --danger: #f2756b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; letter-spacing: -.02em; }
h2 { font-size: 19px; letter-spacing: -.01em; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

main { max-width: 720px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 20px) 16px 0; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.stack > * + * { margin-top: 12px; }
.section-title { margin: 24px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }

/* knapper og felter */
button, .btn {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-weight: 600; min-height: 44px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--accent); padding: 8px 4px; min-height: 0; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn-block { width: 100%; }
button:disabled { opacity: .5; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent;
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field + .field { margin-top: 12px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

/* innlogging */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: 4px; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 20px; }

/* hjem */
.week-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.tile .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .l { font-size: 12px; color: var(--muted); }
.next-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--accent); color: var(--accent-ink); border: 0; }
.next-card .big { font-size: 22px; font-weight: 700; }
.next-card button { background: var(--accent-ink); color: var(--accent); }
.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.quick button { display: flex; align-items: center; gap: 10px; justify-content: flex-start; background: var(--surface); border: 1px solid var(--line); padding: 14px; box-shadow: var(--shadow); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.styrke { background: var(--styrke); } .dot.gange { background: var(--gange); }
.dot.svomming { background: var(--svomming); } .dot.annet { background: var(--annet); }

/* styrkeøkt */
.ex { padding: 14px; }
.ex-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ex-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.ex-hint { font-size: 13px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); }
.set-grid { display: grid; grid-template-columns: 28px 1fr 1fr 48px; gap: 8px; align-items: center; margin-top: 10px; }
.set-grid .hdr { font-size: 12px; color: var(--muted); }
.set-grid .n { color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.set-grid input { text-align: center; font-variant-numeric: tabular-nums; padding: 8px; }
.check { width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line); background: transparent; }
.check.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check svg { width: 20px; height: 20px; }
.ex-actions { display: flex; gap: 12px; margin-top: 8px; }

.timer {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); border-radius: 999px; padding: 10px 10px 10px 18px;
  display: flex; align-items: center; gap: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 20;
  font-variant-numeric: tabular-nums;
}
.timer .t { font-size: 20px; font-weight: 700; min-width: 56px; }
.timer button { min-height: 36px; padding: 6px 12px; white-space: nowrap; background: rgba(127,127,127,.25); color: inherit; }
.timer.over { background: var(--accent); color: var(--accent-ink); }

/* historikk */
.week-group h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 0 8px; text-transform: uppercase; letter-spacing: .05em; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; width: 100%; text-align: left; font-weight: 400; box-shadow: var(--shadow); }
.item + .item { margin-top: 6px; }
.item .main { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; }
.item .t2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .day { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); margin-left: 6px; font-weight: 600; }

/* statistikk */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.insights { list-style: none; margin: 0; padding: 0; }
.insights li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.insights li:first-child { border-top: 0; padding-top: 0; }
.insights .mark { width: 6px; border-radius: 3px; flex: none; }
.insights .good .mark { background: var(--good); }
.insights .ok .mark { background: var(--annet); }
.insights .warn .mark { background: var(--warn); }
.chart-card h2 { font-size: 16px; }
.chart-card .sub { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.chart-wrap { position: relative; height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { min-height: 32px; padding: 4px 12px; background: transparent; font-size: 14px; border-radius: 8px; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); }

/* innstillinger */
.ex-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.ex-row:first-child { border-top: 0; }
.ex-row .main { flex: 1; min-width: 0; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-bg { align-items: center; } }
.modal { background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
table.sets { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 15px; }
table.sets td { padding: 6px 0; border-top: 1px solid var(--line); }
table.sets td:last-child { text-align: right; }

/* fanelinje */
nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center;
}
nav.tabbar .inner { display: flex; width: 100%; max-width: 720px; }
nav.tabbar button { flex: 1; background: transparent; border-radius: 0; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 500; }
nav.tabbar button svg { width: 24px; height: 24px; }
nav.tabbar button.on { color: var(--accent); }

.toast { position: fixed; top: calc(env(safe-area-inset-top) + 12px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; z-index: 60; font-size: 14px; font-weight: 600; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
body.has-timer { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px); }
