:root {
  --bg: #f6f8f5;
  --card: #ffffff;
  --text: #1d2a22;
  --muted: #6b7a70;
  --line: #e2e8e3;
  --green: #2f9e5b;
  --green-soft: #e3f4e9;
  --danger: #c2413a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --card: #1b221d;
    --text: #e6ede8;
    --muted: #93a398;
    --line: #2b352e;
    --green: #45b872;
    --green-soft: #1e3527;
    --danger: #e0675f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.2rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { font-size: 1.8rem; line-height: 1; background: none; border: 0; color: var(--green); padding: 0 6px 4px 0; cursor: pointer; }
.sync { font-size: .8rem; color: var(--muted); }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: .9rem; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.hidden, [hidden] { display: none !important; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center; min-height: 120px; padding: 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 1.1rem;
}
.tile .emoji { font-size: 2rem; }
.tile.primary { grid-column: 1 / -1; min-height: 80px; background: var(--green); color: #fff; border-color: var(--green); flex-direction: row; align-items: center; justify-content: center; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 10px 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn-danger { color: var(--danger); }
.btn-small { padding: 6px 10px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--green); padding: 4px; }

input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.amount { width: 84px; flex: none; }
.unit { width: 120px; flex: none; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.item { flex: 1; color: inherit; text-decoration: none; min-width: 0; }
.list .name { font-weight: 600; }
.list li:has(.left-row) { flex-wrap: wrap; }
.left-row { flex-basis: 100%; display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); padding-left: 2px; }
.left-row input { padding: 6px 10px; }

/* Søk */
.search-wrap { position: relative; }
.results { list-style: none; margin: 4px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); max-height: 300px; overflow-y: auto; }
.results li { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.results li:last-child { border-bottom: 0; }
.results li:hover, .results li:focus { background: var(--green-soft); }
.tag { display: inline-block; font-size: .72rem; padding: 1px 6px; border-radius: 6px; background: var(--green-soft); color: var(--green); margin-right: 6px; vertical-align: 1px; font-weight: 600; }

/* Næring */
.nutr { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.nutr > div {
  display: flex; flex-direction: column; justify-content: space-between; gap: 4px;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg);
}
.nutr > div > span:first-child { font-size: .78rem; color: var(--muted); line-height: 1.2; }
.nutr > div > span:last-child { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.02rem; }
.nutr > div > input { padding: 6px 8px; }
.big-kcal { font-size: 1.8rem; font-weight: 700; color: var(--green); }

/* Kalender */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { margin: 0; font-size: 1.1rem; text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: .75rem; color: var(--muted); padding: 4px 0; }
.cal a {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 10px; text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; position: relative; font-size: .95rem;
}
.cal a.other { opacity: .35; }
.cal a.today { background: var(--green); color: #fff; border-color: var(--green); font-weight: 700; }
.cal a .kc { font-size: .62rem; color: var(--muted); line-height: 1; margin-top: 2px; }
.cal a.today .kc { color: #e8fff0; }
.cal a.has::after { content: ""; position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.cal a.today.has::after { background: #fff; }

.meal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meal-items { margin: 6px 0 0; padding-left: 18px; font-size: .95rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 20;
}
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.footer-note { font-size: .78rem; color: var(--muted); text-align: center; margin-top: 24px; }
.footer-note a { color: inherit; }
