/*
  AI Kalorietracker – roligt, neutralt look.
  Kølig kalkgrå baggrund, mørk blækfarve og én accent: rugbrødsbrun.
  Den ene markante ting er kalorieringen; alt omkring den holdes stille.
*/

@font-face {
  font-family: "Schibsted Grotesk";
  src: url("fonts/schibsted-grotesk.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #eff1ee;
  --surface: #ffffff;
  --surface-2: #e6e9e5;
  --ink: #1d2321;
  --muted: #646e69;
  --line: #d8ddd9;
  --accent: #4f3a28;
  --accent-ink: #ffffff;
  --accent-soft: #e9e1d8;
  --track: #dfe3df;
  --protein: #2d6a65;
  --carbs: #a87b26;
  --fat: #7b5e86;
  --focus: #2d6a65;
  --danger-ink: #7a3b2e;
  --shadow: 0 1px 2px rgb(29 35 33 / 6%), 0 8px 24px rgb(29 35 33 / 6%);

  --font: "Schibsted Grotesk", ui-sans-serif, -apple-system, "Segoe UI", sans-serif;
  --fs-xs: 0.8125rem;
  --fs-s: 0.9375rem;
  --fs-m: 1.0625rem;
  --fs-l: 1.375rem;
  --fs-xl: 1.875rem;
  --fs-hero: 3.5rem;
  --r-s: 10px;
  --r-m: 16px;
  --r-l: 24px;
  --nav-h: 64px;
  --pad: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131715;
    --surface: #1b201e;
    --surface-2: #232927;
    --ink: #e6eae7;
    --muted: #98a29d;
    --line: #2c3330;
    --accent: #c9a27a;
    --accent-ink: #1b1510;
    --accent-soft: #33291f;
    --track: #2a312e;
    --protein: #72b5ad;
    --carbs: #d8af5c;
    --fat: #b799c3;
    --focus: #72b5ad;
    --danger-ink: #e3a08f;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131715;
  --surface: #1b201e;
  --surface-2: #232927;
  --ink: #e6eae7;
  --muted: #98a29d;
  --line: #2c3330;
  --accent: #c9a27a;
  --accent-ink: #1b1510;
  --accent-soft: #33291f;
  --track: #2a312e;
  --protein: #72b5ad;
  --carbs: #d8af5c;
  --fat: #b799c3;
  --focus: #72b5ad;
  --danger-ink: #e3a08f;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-m);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top, 0px);
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  background: var(--bg);
  z-index: 30;
}

img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

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

#app {
  max-width: 34rem;
  margin: 0 auto;
  padding: 8px var(--pad) calc(var(--nav-h) + 40px + env(safe-area-inset-bottom, 0px));
}

body.no-nav #app { padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }

.screen { animation: screen-in 180ms ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(4px); } }

.topbar {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; margin: 0 -8px 8px;
}
.topbar h1 { flex: 1; margin: 0; font-size: var(--fs-l); font-weight: 650; letter-spacing: -0.01em; }

h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
h2 { font-size: var(--fs-l); font-weight: 650; letter-spacing: -0.01em; margin: 32px 0 12px; }
h3 { font-size: var(--fs-m); font-weight: 650; margin: 0; }
p { margin: 0 0 12px; text-wrap: pretty; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-s); }
.xsmall { font-size: var(--fs-xs); }
.num, .macro-val, .item-controls output, .kv dd, .chart text {
  font-variant-numeric: tabular-nums;
}

.panel {
  background: var(--surface);
  border-radius: var(--r-m);
  padding: 16px;
}

.stack > * + * { margin-top: 12px; }

/* ---------- Knapper ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--ink);
  font-weight: 600; font-size: var(--fs-m);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 80ms ease, background-color 120ms ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-block { width: 100%; }
.btn-quiet { background: transparent; padding: 0 12px; }
.btn-danger { background: transparent; color: var(--danger-ink); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: var(--fs-s); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }

.link-btn {
  border: 0; background: none; padding: 6px 0; cursor: pointer;
  color: var(--accent); font-weight: 600; font-size: var(--fs-s);
}
:root[data-theme="dark"] .link-btn { color: var(--accent); }

/* ---------- Bundnavigation ---------- */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav-inner {
  max-width: 34rem; margin: 0 auto; height: var(--nav-h);
  display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr; align-items: center;
}
.nav a, .nav button.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.6875rem; font-weight: 600; color: var(--muted);
  text-decoration: none; border: 0; background: none; padding: 6px 0; cursor: pointer;
}
.nav a svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: var(--ink); }
.camera-btn {
  justify-self: center; margin-top: -28px;
  width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--bg);
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow);
}
.camera-btn svg { width: 28px; height: 28px; }
.camera-btn:active { transform: scale(0.96); }
body.no-nav .nav { display: none; }

/* ---------- Dagsoverblik ---------- */

.daybar { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px; }
.daybar-title { text-align: center; border: 0; background: none; cursor: pointer; padding: 6px 12px; border-radius: 12px; }
.daybar-title strong { display: block; font-size: var(--fs-l); font-weight: 650; letter-spacing: -0.01em; }
.daybar-title span { display: block; font-size: var(--fs-s); color: var(--muted); }

.hero { display: grid; justify-items: center; margin: 16px 0 8px; }
.ring { position: relative; width: min(232px, 64vw); aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { stroke: var(--track); }
.ring-value { stroke: var(--accent); transition: stroke-dashoffset 600ms cubic-bezier(.2,.7,.2,1); }
.ring-over { stroke: var(--accent); opacity: .35; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-number { font-size: var(--fs-hero); font-weight: 650; letter-spacing: -0.035em; line-height: 1; }
.ring-label { margin-top: 6px; font-size: var(--fs-s); color: var(--muted); }

.hero-stats { display: flex; gap: 28px; margin-top: 14px; font-size: var(--fs-s); color: var(--muted); }
.hero-stats b { color: var(--ink); font-weight: 650; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 24px 0 8px; }
.macro-name { font-size: var(--fs-s); font-weight: 600; }
.macro-val { font-size: var(--fs-xs); color: var(--muted); margin-bottom: 6px; }
.bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: currentColor; transition: width 500ms ease; }
.c-protein { color: var(--protein); }
.c-carbs { color: var(--carbs); }
.c-fat { color: var(--fat); }

.banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--accent-soft); border-radius: var(--r-m); padding: 12px 14px; margin: 8px 0;
  font-size: var(--fs-s);
}

/* ---------- Måltider og lister ---------- */

.meal { margin-top: 28px; }
.meal-head { display: flex; align-items: baseline; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.meal-head h3 { font-size: var(--fs-m); }
.meal-head .kcal { color: var(--muted); font-size: var(--fs-s); flex: 1; }
.meal-head .icon-btn { width: 36px; height: 36px; margin: -8px -8px -8px 0; align-self: center; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 0; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title, .row-sub { display: block; }
.row-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: var(--fs-xs); color: var(--muted); }
.row-end { font-size: var(--fs-s); color: var(--ink); white-space: nowrap; }
.row-end small { color: var(--muted); }
.meal-empty { padding: 10px 0; font-size: var(--fs-s); color: var(--muted); }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 0.6875rem; font-weight: 650; vertical-align: 1px;
  background: var(--surface-2); color: var(--muted);
}
.tag-ai { background: var(--accent-soft); color: var(--accent); }

/* ---------- Formularer ---------- */

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: var(--fs-s); font-weight: 600; margin-bottom: 6px; }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: var(--fs-xs); }
.field .error { color: var(--danger-ink); }

.input, select.input, textarea.input {
  width: 100%; min-height: 50px; padding: 12px 14px;
  font-size: 1.0625rem; /* ≥16px undgår zoom på iOS */
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink);
  appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.input[aria-invalid="true"] { border-color: var(--danger-ink); }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px;
}
.input-unit { position: relative; }
.input-unit .input { padding-right: 52px; }
.input-unit > em { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); pointer-events: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.segmented { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.segmented button {
  flex: 1; min-height: 40px; border: 0; border-radius: 999px; background: transparent;
  font-weight: 600; font-size: var(--fs-s); cursor: pointer; color: var(--muted);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 8%); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-size: var(--fs-s); font-weight: 550;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.choice-list { display: grid; gap: 10px; }
.choice {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 16px; border-radius: var(--r-m);
  border: 1.5px solid var(--line); background: var(--surface);
}
.choice strong { display: block; font-weight: 650; }
.choice span { display: block; font-size: var(--fs-s); color: var(--muted); margin-top: 2px; }
.choice[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice[disabled] { opacity: 0.45; cursor: not-allowed; }

.note {
  border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin: 12px 0;
  font-size: var(--fs-s); color: var(--muted);
}

.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom, 0px));
  margin-top: 24px; z-index: 5;
}
body.no-nav .sticky-actions { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }

/* ---------- Onboarding og login ---------- */

.steps { height: 4px; background: var(--track); border-radius: 2px; overflow: hidden; margin: 8px 0 28px; }
.steps > i { display: block; height: 100%; background: var(--accent); transition: width 300ms ease; }
.onb h1, .auth h1 { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.02em; margin: 8px 0 12px; }
.lead { font-size: var(--fs-m); color: var(--muted); margin-bottom: 24px; }

.auth { padding-top: 12vh; }
.auth .mark { width: 56px; height: 56px; margin-bottom: 20px; }

.result-hero { margin: 8px 0 24px; }
.result-hero .big { font-size: var(--fs-hero); font-weight: 650; letter-spacing: -0.035em; line-height: 1; }
.result-hero .unit { font-size: var(--fs-l); color: var(--muted); margin-left: 6px; font-weight: 500; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: var(--fs-s); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-size: var(--fs-s); }

/* ---------- Foto ---------- */

.photo-frame {
  position: relative; border-radius: var(--r-l); overflow: hidden;
  background: var(--surface-2); aspect-ratio: 4 / 3;
}
.photo-frame img { width: 100%; height: 100%; object-fit: cover; }
.photo-frame.is-busy img { filter: saturate(0.6) brightness(0.75); }
.photo-status {
  position: absolute; inset: auto 12px 12px; padding: 10px 14px; border-radius: 12px;
  background: rgb(20 24 22 / 72%); color: #fff; font-size: var(--fs-s);
  display: flex; align-items: center; gap: 10px;
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgb(255 255 255 / 30%); border-top-color: #fff;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.guide { display: grid; gap: 8px; margin: 16px 0; font-size: var(--fs-s); color: var(--muted); padding-left: 18px; }

.item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item-head { display: flex; gap: 12px; align-items: flex-start; }
.item-head .row-main { flex: 1; }
.item-kcal { font-weight: 650; white-space: nowrap; }
.item-controls { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.item-controls output { min-width: 64px; text-align: right; font-size: var(--fs-s); font-weight: 600; }
.item-actions { display: flex; gap: 16px; margin-top: 4px; }

input[type="range"] {
  flex: 1; height: 32px; background: transparent; -webkit-appearance: none; appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--track); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--track); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent);
}

.total-line { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; margin: 8px 0 4px; }
.total-line strong { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.02em; }

.question { background: var(--surface); border-radius: var(--r-m); padding: 18px; margin-top: 16px; }
.question p { font-size: var(--fs-m); font-weight: 600; }

/* ---------- Søgning ---------- */

.searchbox { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 6; background: var(--bg); padding: 8px 0 12px; }
.searchbox .input { padding-left: 44px; border-radius: 999px; }
.searchbox svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.searchbox > div { position: relative; }
.result-actions { display: grid; gap: 8px; margin-top: 16px; }

/* ---------- Grafer ---------- */

.chart { width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .dot { fill: var(--muted); opacity: 0.55; }
.chart .avg { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .target { stroke: var(--protein); stroke-width: 1.5; stroke-dasharray: 5 5; }
.chart .bar-rect { fill: var(--accent); opacity: 0.85; }
.chart .bar-empty { fill: var(--track); }
.chart .today-label { fill: var(--ink); font-weight: 650; }

.stat-big { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 4px 0 16px; }

/* ---------- Ark (bottom sheet) ---------- */

dialog.sheet {
  width: 100%; max-width: 34rem; max-height: 92vh; margin: auto auto 0;
  padding: 0; border: 0; border-radius: var(--r-l) var(--r-l) 0 0;
  background: var(--bg); color: var(--ink);
  box-shadow: 0 -8px 40px rgb(0 0 0 / 20%);
}
dialog.sheet::backdrop { background: rgb(15 18 17 / 45%); }
dialog.sheet[open] { animation: sheet-in 220ms cubic-bezier(.2,.8,.2,1); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0.4; } }
.sheet-inner { padding: 8px var(--pad) calc(24px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; max-height: 92vh; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: var(--fs-l); }

.menu { display: grid; gap: 2px; }
.menu button {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; font-weight: 550;
}
.menu button:last-child { border-bottom: 0; }
.menu svg { width: 22px; height: 22px; color: var(--muted); }

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

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px); opacity: 0; z-index: 50;
  width: max-content; max-width: calc(100% - 40px); padding: 12px 18px; border-radius: 14px; text-align: center;
  background: var(--ink); color: var(--bg); font-size: var(--fs-s); font-weight: 550;
  transition: opacity 200ms ease, transform 200ms ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.no-nav .toast { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }

.offline-pill {
  display: inline-block; margin: 4px 0; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: var(--fs-xs); color: var(--muted);
}

.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.loading { padding: 48px 0; display: grid; place-items: center; }
.loading .spinner { border-color: var(--track); border-top-color: var(--accent); width: 28px; height: 28px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 640px) {
  #app { padding-top: 24px; }
}
