:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f0ede5;
  --text: #1f2421;
  --muted: #646b66;
  --line: #e2ded4;
  --accent: #2f6b4f;
  --accent-soft: #e3efe8;
  --accent-text: #ffffff;
  --warn-soft: #fbf1dc;
  --warn-text: #7a5311;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1d211f;
    --surface-2: #252a27;
    --text: #e9ece9;
    --muted: #a1a8a3;
    --line: #313733;
    --accent: #7cc39c;
    --accent-soft: #23372c;
    --accent-text: #0f1a14;
    --warn-soft: #3a2f1a;
    --warn-text: #f0cf8e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.75rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 56px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.main-nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: auto;
}
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  font-size: .95rem;
}
.main-nav a:hover { color: var(--text); }
.main-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

@media (max-width: 640px) {
  .header-inner { padding-top: 10px; gap: 6px; }
  .main-nav { margin: 0 -16px; padding: 0 16px 8px; width: calc(100% + 32px); }
}

main { padding-top: 24px; padding-bottom: 32px; outline: none; }

.site-footer { color: var(--muted); font-size: .85rem; padding-bottom: 32px; }

/* ---------- Byggstenar ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.stack > * + * { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
}
.badge.fiber { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); font-weight: 600; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }

.page-head { margin-bottom: 20px; }
.page-head p { margin-top: 6px; color: var(--muted); max-width: 65ch; }

.note {
  background: var(--warn-soft);
  color: var(--warn-text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .925rem;
}

/* ---------- Veckonavigering ---------- */
.week-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.week-nav .btn { text-decoration: none; }

.week-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; margin-bottom: 20px; }
.week-head .titles { flex: 1 1 320px; }
.week-head .titles p { color: var(--muted); margin-top: 6px; }
.stats { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.stat strong { display: block; font-size: 1.4rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }

.week-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 800px) { .week-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Inköpslista ---------- */
.list-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.list-head h2 { margin-right: auto; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }

.shop-group + .shop-group { margin-top: 18px; }
.shop-group h3 {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li + li { border-top: 1px solid var(--line); }
.checklist label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 9px 2px;
  cursor: pointer;
}
.checklist input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}
.checklist input:checked + span { text-decoration: line-through; color: var(--muted); }

/* ---------- Veckans rätter ---------- */
.meals { list-style: none; margin: 0; padding: 0; }
.meals li + li { border-top: 1px solid var(--line); }
.meal-row { display: flex; align-items: center; gap: 8px; }
.meal-row .meal { flex: 1; min-width: 0; }
.btn-small { padding: 5px 10px; font-size: .85rem; flex: none; }
.btn:disabled { opacity: .6; cursor: default; }
.pantry-head {
  margin: 16px 0 6px;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.meal {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  color: var(--text);
  text-decoration: none;
}
.meal .num {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  font-size: .85rem;
  font-weight: 600;
}
.meal .body { flex: 1; min-width: 0; }
.meal .body strong { display: block; }
.meal:hover strong { color: var(--accent); }
.meal .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.tips { margin: 0; padding-left: 18px; }
.tips li + li { margin-top: 6px; }

/* ---------- Receptlista ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; align-items: center; }
.search {
  flex: 1 1 220px;
  font: inherit;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none;
  font: inherit;
  font-size: .875rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.recipe-section + .recipe-section { margin-top: 28px; }
.recipe-section > h2 { margin-bottom: 10px; }
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.recipe-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  padding: 16px;
}
.recipe-card:hover { border-color: var(--accent); }
.recipe-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.empty { color: var(--muted); padding: 24px 0; }

/* ---------- Receptsida ---------- */
.back { display: inline-block; margin-bottom: 16px; text-decoration: none; font-size: .95rem; }
.recipe-head .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.recipe-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}
@media (max-width: 760px) { .recipe-body { grid-template-columns: minmax(0, 1fr); } }
.recipe-body h2 { margin-bottom: 10px; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; display: flex; gap: 12px; }
.steps li + li { margin-top: 14px; }
.steps li::before {
  content: counter(step);
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: .85rem;
  display: grid;
  place-items: center;
}

/* ---------- Tabeller ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; align-items: start; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-edit { padding-right: 2px; }
.tag-edit button {
  appearance: none;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
  border-radius: 999px;
}
.tag-edit button:hover { background: var(--line); color: var(--text); }
.inline-form, .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.inline-form input {
  flex: 1 1 180px;
  min-width: 0;
  font: inherit;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.plain-list { margin: 0; padding-left: 18px; }
.plain-list li + li { margin-top: 6px; }

/* ---------- Utskrift ---------- */
@media print {
  .site-header, .site-footer, .week-nav, .no-print, .back { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .week-grid, .recipe-body { grid-template-columns: 1fr 1fr; }
  .checklist label { padding: 3px 0; }
  .checklist input:checked + span { text-decoration: none; color: inherit; }
  .progress { display: none; }
  main { padding: 0; }
}

/* ---------- Inloggning ---------- */
.login-wrap { max-width: 440px; padding-top: 12vh; }
