:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #e3e1da;
  --accent: #1f6f4a;
  --accent-soft: #e3f1ea;
  --warn: #9a5b00;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1b211e;
    --ink: #e8ece9;
    --muted: #9aa49f;
    --line: #2b332f;
    --accent: #5fc795;
    --accent-soft: #1f3a2d;
    --warn: #e0a447;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.brand h1 { font-size: 1.35rem; }
.brand p { margin: 0; font-size: .85rem; }

.stores { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.stores button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: .9rem;
}
.stores button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.stores .tag { font-size: .72rem; opacity: .85; margin-left: 4px; }

main { padding: 12px 16px; max-width: 640px; margin: 0 auto; }

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.summary div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.summary b { display: block; font-size: 1.15rem; }
.summary span { font-size: .78rem; color: var(--muted); }

.card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.card .day { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); font-weight: 600; }
.card h3 { font-size: 1.08rem; margin: 2px 0 4px; }
.card p { margin: 0; font-size: .9rem; color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: .75rem; background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 2px 8px; }

.notice {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: .92rem;
}
.notice.warn { border-color: var(--warn); }

h2.section { font-size: .95rem; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.list li + li { border-top: 1px solid var(--line); }
.list label { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer; }
.list input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: 0 0 auto; }
.list .what { display: block; font-weight: 600; }
.list .how { display: block; font-size: .85rem; color: var(--muted); }
.list input:checked + span { opacity: .45; text-decoration: line-through; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 8px 12px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
th, td { padding: 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
tr.best td:first-child { font-weight: 700; color: var(--accent); }

dialog {
  border: 0;
  padding: 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  margin: auto auto 0;
  border-radius: 18px 18px 0 0;
  background: var(--bg);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog article { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.close { font-size: 1.6rem; line-height: 1; border: 0; background: none; color: var(--ink); padding: 0 4px; }
dialog ol { padding-left: 1.3em; }
dialog ol li { margin-bottom: 8px; }
dialog ul.plain { padding-left: 1.1em; margin: 4px 0; }

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 3;
}
.tabs button { font: inherit; font-size: .78rem; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button span { font-size: 1.25rem; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

.status { text-align: center; color: var(--muted); font-size: .85rem; }

.ingredients { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.ingredients li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; }
.ingredients li + li { border-top: 1px solid var(--line); }
.ingredients .amount { color: var(--muted); white-space: nowrap; }
.ingredients .src { font-size: .72rem; margin-left: 6px; color: var(--accent); }
.ingredients li.out .name { color: var(--warn); }

.pantry li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 14px; }
.toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: 0 0 auto; }
.toggle button { font: inherit; font-size: .82rem; border: 0; background: var(--card); color: var(--muted); padding: 6px 12px; }
.toggle button[aria-pressed="true"].have { background: var(--accent); color: #fff; }
.toggle button[aria-pressed="true"].out { background: var(--warn); color: #fff; }

.section-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper b { min-width: 6.5em; text-align: center; font-size: .9rem; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line, #ccc); background: var(--card, #fff); color: var(--ink); font-size: 1.2rem; line-height: 1; }
.stepper button:disabled { opacity: .35; }
.badge.tag-storkok, .badge.tag-grundkok { background: #e3eefc; }
.badge.tag-proteinrik { background: #e4f4e6; }
.badge.tag-lyx { background: #fbeccf; }
.badge.tag-storkok, .badge.tag-grundkok, .badge.tag-proteinrik, .badge.tag-lyx { color: #1d2320; }

.import-row { display: flex; gap: 8px; margin-top: 8px; }
.import-row input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.source-link { color: var(--accent); }
.btn.danger { color: #b3261e; }
.ica-links a.btn { display: inline-block; text-decoration: none; margin: 4px 0; }
.tag.pending { background: transparent; border: 1px dashed currentColor; opacity: .75; }
.card-row { position: relative; }
.card-row .card { width: 100%; }
.card-row .swap { position: absolute; top: 10px; right: 10px; z-index: 1; font: inherit; font-size: .8rem; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 4px 10px; }
.options { display: grid; gap: 8px; margin: 12px 0; }
.option { font: inherit; text-align: left; display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); }
.option .muted { font-size: .85rem; }

/* Login */
.logout { margin: 0 0 0 auto; }
.logout button { font: inherit; font-size: .8rem; background: none; border: 0; color: var(--muted); padding: 4px 0; text-decoration: underline; }
.login { max-width: 360px; margin: 12vh auto 0; padding: 24px 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.login h1 { font-size: 1.5rem; margin-bottom: 16px; }
.login form { display: grid; gap: 14px; }
.login label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.login input { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.login .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 10px 12px; }
.login-note { margin: 0 0 12px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); font-size: .9rem; }
body:has(.login) { padding-bottom: 0; }
