:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee8;
  --ink: #1d201d;
  --ink-2: #555b55;
  --ink-3: #8a8f88;
  --line: #e2e1da;
  --accent: #2f7d5b;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe2;
  --trend: #2f7d5b;
  --dot: #9aa59d;
  --goal: #b8721d;
  --over: #b8461d;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161816;
    --surface: #202320;
    --surface-2: #2a2e2a;
    --ink: #eceee9;
    --ink-2: #b2b8b0;
    --ink-3: #7f867d;
    --line: #343834;
    --accent: #5fbf8f;
    --accent-ink: #0f1a14;
    --accent-soft: #23382c;
    --trend: #5fbf8f;
    --dot: #6b746c;
    --goal: #e3a457;
    --over: #ec8a62;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 24px;
}
h1 { font-size: 26px; margin: 4px 0 14px; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
}

/* ---- knappar ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px;
  background: var(--surface-2); font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 10px; min-height: 0; }
.btn.danger { background: transparent; color: var(--over); }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 14px; }

/* ---- datumrad ---- */
.datebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.datebar h1 { margin: 0; }
.datebar .nav { display: flex; gap: 4px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--surface); display: grid; place-items: center;
}
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- kaloriring ---- */
.ring-card { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring .bar.over { stroke: var(--over); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.ring .lbl { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.stats { display: grid; gap: 8px; flex: 1; }
.stat { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.stat b { font-weight: 600; }

.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini .card { margin: 0; padding: 14px; border: 0; text-align: left; width: 100%; }
.mini .v { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.mini .k { font-size: 13px; color: var(--ink-2); }
.delta { font-size: 13px; font-weight: 600; }
.delta.down { color: var(--accent); }
.delta.up { color: var(--over); }

/* ---- måltider ---- */
.meal { padding: 14px 16px 6px; }
.meal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.meal-head h2 { margin: 0; text-transform: capitalize; }
.entry {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 0; border: 0; border-top: 1px solid var(--line);
  background: none; text-align: left;
}
.entry:first-of-type { border-top: 0; }
.entry img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; flex: none; }
.entry .name { flex: 1; min-width: 0; }
.entry .name div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .kcal { font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { color: var(--ink-3); font-size: 14px; padding: 6px 0 10px; }

/* ---- grafer ---- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 11px; }
.chart .trend { fill: none; stroke: var(--trend); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .raw { fill: var(--dot); }
.chart .goal { stroke: var(--goal); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .goal-lbl { fill: var(--goal); font-size: 11px; font-weight: 600; }
.chart .cross { stroke: var(--ink-3); stroke-width: 1; }
.chart .hl { fill: var(--trend); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--bg);
  font-size: 12px; padding: 6px 8px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -100%);
}
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }
.legend i.dot { width: 7px; height: 7px; border: 0; border-radius: 50%; background: var(--dot); }

.headline { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.headline .v { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: color-mix(in srgb, var(--goal) 18%, transparent); color: var(--goal); }

.list .item { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.list button.item { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }

/* ---- formulär ---- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px; min-height: 46px; font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bignum { font-size: 34px; font-weight: 700; text-align: center; letter-spacing: -0.02em; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 10px; align-items: center; margin: 6px 0 14px; }
.stepper button { height: 56px; border-radius: 14px; border: 0; background: var(--surface-2); font-size: 24px; font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---- bottenflikar ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  border: 0; background: none; display: grid; justify-items: center; gap: 2px;
  font-size: 11px; color: var(--ink-3); padding: 4px 0;
}
.tabs button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); font-weight: 600; }

/* ---- bottenark ---- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.photo-preview { width: 100%; max-height: 240px; object-fit: cover; border-radius: 14px; margin-bottom: 12px; }
.plate-item { background: var(--surface); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.plate-item.off { opacity: .45; }
.plate-item .top { display: flex; gap: 10px; align-items: flex-start; }
.plate-item .top input[type=checkbox] { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.plate-item .food { flex: 1; min-width: 0; }
.plate-item .food button { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; text-align: left; }
.plate-item .kc { font-weight: 700; font-variant-numeric: tabular-nums; }
.plate-item .grams { display: grid; grid-template-columns: 1fr 86px; gap: 10px; align-items: center; margin-top: 8px; }
.plate-item .grams input[type=number] { min-height: 38px; padding: 6px 8px; text-align: right; }
.total-bar {
  position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--bg);
  padding: 10px 0 calc(16px + env(safe-area-inset-bottom)); margin-bottom: calc(-16px - env(safe-area-inset-bottom));
}
.spinner { width: 34px; height: 34px; border: 3px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.results { margin-top: 8px; }
.results button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; padding: 11px 2px; }
.results button:first-child { border-top: 0; }
.results .sub { font-size: 12px; color: var(--ink-3); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 14px; }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30;
  max-width: calc(100% - 32px);
}
.login { max-width: 340px; margin: 18vh auto 0; text-align: center; }
.note { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }

/* ---- aktivitet ---- */
.steps-card { display: block; width: 100%; border: 0; text-align: left; }
.steps-card .k { font-size: 13px; color: var(--ink-2); }
.steps-card .v { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; border-radius: 4px; background: var(--accent); opacity: .65; transition: width .5s ease; }
.progress > div.hit { opacity: 1; }
.step-row { display: grid !important; grid-template-columns: 110px 1fr 64px; gap: 10px; align-items: center; }
.step-row .lbl { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-row .num { text-align: right; }
.step-row .bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.step-row .bar i { display: block; height: 100%; background: var(--accent); opacity: .55; border-radius: 4px; }
.step-row .bar i.hit { opacity: 1; }
