/* Middagskollen — design system.
 *
 * STYLE GUIDE (use these classes; avoid one-off styles). Page-specific CSS goes in its own
 * file static/css/<area>.css, included from the page with
 *   {{define "head"}}<link rel="stylesheet" href="{{asset "css/<area>.css"}}">{{end}}
 *
 * Layout   .container .stack(.stack-sm/.stack-lg) .row(.row-wrap .row-between .row-end) .grow .spacer
 *          .page-head (h1 + .actions)  .section (+ .section-title)  .grid-2  .hide-mobile .only-mobile
 * Cards    .cards (responsive recipe grid) > a.card > .card-img(img) .card-body .card-title .card-meta
 *          .card-badge (top-left badge on image)   .panel (generic white box)
 * Buttons  .btn  .btn-primary .btn-accent .btn-ghost .btn-danger .btn-sm .btn-lg .btn-block .btn-icon
 * Forms    .field > label + input/select/textarea + .hint ;  .check (checkbox/radio label)
 *          .input-row (input + button inline) ; .search (big rounded search field)
 * Chips    .chips (horizontal scroll row) > .chip (.chip-on, .chip-x for removable, .chip-soon)
 * Text     .muted .small .tiny .strong .ellipsis .center .nowrap
 * Status   .badge (.badge-ok .badge-warn .badge-accent .badge-muted)  .flash(.flash-ok .flash-error)
 *          .meter > span (width = %) for match level ; .empty (empty-state box)
 * Lists    .list > .list-item (.list-item-main .list-item-actions) ; .checklist (shopping)
 * Misc     .tabs > a(.on) ; dialog.sheet ; .sticky-bottom ; .divider ; .avatar
 * Icons    {{template "icon" "name"}} renders an inline SVG (see partials/icons.html), size 1.25em,
 *          class .ico; inside .btn they align automatically.
 */

:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --surface-2: #f4efe6;
  --ink: #1d1b16;
  --muted: #6b655a;
  --line: #e7dfd1;
  --primary: #1f5135;
  --primary-2: #2a6a46;
  --primary-ink: #ffffff;
  --primary-soft: #e3efe7;
  --accent: #d9502f;
  --accent-soft: #fbe5de;
  --ok: #2e7d4f;
  --ok-soft: #e1f2e7;
  --warn: #a8670d;
  --warn-soft: #fbf0d9;
  --danger: #b4321f;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 14px rgba(40, 30, 10, .06);
  --shadow-lg: 0 10px 30px rgba(40, 30, 10, .16);
  --tabbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141511;
    --surface: #1d1f1a;
    --surface-2: #262922;
    --ink: #f1ede4;
    --muted: #a9a394;
    --line: #34372e;
    --primary: #5fb07f;
    --primary-2: #77c394;
    --primary-ink: #0d1f14;
    --primary-soft: #1f3327;
    --accent: #f07a5c;
    --accent-soft: #3a2420;
    --ok: #6cc28f;
    --ok-soft: #1c3226;
    --warn: #e2a84a;
    --warn-soft: #3a2f1a;
    --danger: #f0735d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
hr, .divider { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.ico { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.25em; }

/* ---------- top bar & tab bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .5rem;
  padding: calc(env(safe-area-inset-top) + .5rem) 1rem .5rem; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 750; font-size: 1.1rem; color: var(--ink); }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand:hover { text-decoration: none; }
.topbar .spacer { flex: 1; }
.topnav { display: none; gap: .25rem; }
.topnav a { padding: .45rem .8rem; border-radius: 999px; color: var(--muted); font-weight: 600; }
.topnav a.on, .topnav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }

.wake-btn {
  display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); border-radius: 999px; padding: .4rem .7rem; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
}
.wake-btn[aria-pressed="true"] { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); }
.wake-btn[data-pending="true"] { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--warn) 25%, transparent); } }
.wake-label-short { display: none; }
@media (max-width: 380px) { .wake-label { display: none; } .wake-label-short { display: inline; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(0, 0, 0, .05);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tabbar a .ico { width: 24px; height: 24px; }
.tabbar a.on { color: var(--primary); }
.tabbar a:hover { text-decoration: none; }

@media (min-width: 900px) {
  body { padding-bottom: 2rem; }
  .tabbar { display: none; }
  .topnav { display: flex; }
}

/* ---------- layout ---------- */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 1rem; }
.container-narrow { max-width: 640px; }
.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: .5rem; }
.stack-lg > * + * { margin-top: 1.75rem; }
.row { display: flex; align-items: center; gap: .5rem; }
.row-wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; gap: 1rem; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } .hide-desktop { display: none !important; } }
@media (max-width: 759px) { .hide-mobile { display: none !important; } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin: .25rem 0 1rem; }
.page-head h1 { margin: 0; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.section { margin-top: 1.75rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.section-title h2 { margin: 0; }

/* ---------- panels & cards ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.panel-soft { background: var(--surface-2); border: 0; box-shadow: none; }
.cards { display: grid; gap: .9rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.card {
  position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card-img { aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-img .placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 2.2rem; }
.card-body { padding: .6rem .7rem .75rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.card-title { font-weight: 700; font-size: .95rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-sub { color: var(--muted); font-size: .8rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; flex-wrap: wrap; gap: .35rem .6rem; color: var(--muted); font-size: .78rem; margin-top: auto; padding-top: .2rem; }
.card-meta span { display: inline-flex; align-items: center; gap: .2rem; }
.card-badge { position: absolute; top: .5rem; left: .5rem; }
.card-fav { position: absolute; top: .45rem; right: .45rem; background: rgba(255, 255, 255, .92); color: var(--accent); border-radius: 999px; width: 30px; height: 30px; display: grid; place-items: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: .55rem 1rem;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-2); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .88rem; border-radius: 10px; }
.btn-lg { min-height: 54px; padding: .8rem 1.4rem; font-size: 1.08rem; border-radius: 14px; }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: 44px; }
.btn-icon.btn-sm { width: 34px; }
form.inline { display: inline; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > label, .label { font-weight: 650; font-size: .92rem; }
.hint { color: var(--muted); font-size: .82rem; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=url], input[type=number],
input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; /* 16px stops iOS zoom */
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[type=file] { font: inherit; max-width: 100%; }
.check { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; min-height: 36px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.input-row { display: flex; gap: .5rem; }
.input-row > input { flex: 1; min-width: 0; }
.search { position: relative; }
.search input { padding-left: 2.6rem; border-radius: 999px; min-height: 50px; box-shadow: var(--shadow); }
.search .ico { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.form-errors { background: var(--accent-soft); color: var(--danger); border-radius: var(--radius-sm); padding: .6rem .8rem; }

/* ---------- chips ---------- */
.chips { display: flex; gap: .45rem; overflow-x: auto; padding: .15rem .05rem .35rem; scrollbar-width: none; flex-wrap: nowrap; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; min-height: 34px; padding: .3rem .8rem;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: .88rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.chip:hover { text-decoration: none; background: var(--surface-2); }
.chip-on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip-on:hover { background: var(--primary-2); }
.chip-soon { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); }
.chip-x { padding-right: .35rem; }
.chip-x button { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0 .2rem; display: inline-flex; font-size: 1rem; line-height: 1; opacity: .7; }
.chip-x button:hover { opacity: 1; }

/* ---------- text & status ---------- */
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .76rem; }
.strong { font-weight: 700; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .12rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-primary { background: var(--primary); color: var(--primary-ink); }
.flash { border-radius: var(--radius-sm); padding: .7rem .9rem; margin-bottom: 1rem; font-weight: 600; display: flex; gap: .5rem; align-items: center; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--accent-soft); color: var(--danger); }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--warn), var(--ok)); }
.empty { text-align: center; padding: 2.2rem 1rem; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }
.empty .ico { width: 42px; height: 42px; margin: 0 auto .5rem; display: block; opacity: .7; }

/* ---------- lists ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-actions { display: flex; gap: .35rem; align-items: center; }
.checklist .list-item { min-height: 54px; }
.checklist input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--primary); flex: none; }
.checklist .done { text-decoration: line-through; color: var(--muted); }

/* ---------- tabs, sheet, misc ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--muted); font-weight: 650; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
dialog.sheet { border: 0; border-radius: 18px; padding: 1.25rem; width: min(560px, calc(100vw - 1.5rem)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.sheet::backdrop { background: rgba(20, 15, 5, .45); }
@media (max-width: 640px) {
  dialog.sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
}
.sticky-bottom { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + .5rem); z-index: 5; }
@media (min-width: 900px) { .sticky-bottom { bottom: 1rem; } }
.avatar { width: 34px; height: 34px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 750; font-size: .9rem; flex: none; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); transition: width .4s ease; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: .65rem 1rem; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 2rem);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 1rem; top: 1rem; z-index: 100; background: var(--surface); padding: .5rem 1rem; border-radius: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

