:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1d2421;
  --ink-2: #5a665f;
  --line: #e3dfd3;
  --line-strong: #cfc9b8;
  --accent: #2f6b57;
  --accent-hover: #265746;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe8;
  --warn: #8a4f05;
  --warn-bg: #fff2d6;
  --warn-line: #ecd29a;
  --danger: #b0301d;
  --danger-bg: #fde8e3;
  --ok: #23703f;
  --ok-bg: #dff3e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 6px 18px rgba(30, 30, 20, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131715;
    --surface: #1b211e;
    --surface-2: #202723;
    --ink: #e8ece9;
    --ink-2: #9aa8a0;
    --line: #2b342f;
    --line-strong: #3a453f;
    --accent: #5fb596;
    --accent-hover: #74c6a8;
    --accent-ink: #0d1d17;
    --accent-soft: #1f3a30;
    --warn: #f0c36a;
    --warn-bg: #3a2e12;
    --warn-line: #5d4a1c;
    --danger: #ff8d79;
    --danger-bg: #3d1d17;
    --ok: #7fd49c;
    --ok-bg: #173324;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--font); font-variant-numeric: tabular-nums;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ app frame */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 16px; min-height: 56px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; font-size: 17px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; stroke: #fff; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 8px 14px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 600;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 10px; }
.who .name { font-weight: 600; }
.role-badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent);
}
.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 24px; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; }

/* ------------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); cursor: pointer; font-weight: 600; line-height: 1.2; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: 20px; line-height: 1;
  width: 30px; height: 30px; border-radius: 6px; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.del:hover { color: var(--danger); background: var(--danger-bg); }

input[type=text], input[type=number], input[type=search], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); min-height: 38px;
}
textarea { resize: vertical; min-height: 70px; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--ink-2); }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .fixed { flex: 0 0 auto; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 16px; }
.card h2 { font-size: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

.banner { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn); }
.banner.error { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.banner strong { font-weight: 700; }
.banner ul { margin: 6px 0 0 18px; padding: 0; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

/* ------------------------------------------------------------------ toasts */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast {
  padding: 10px 14px; border-radius: 8px; background: #1d2421; color: #fff; box-shadow: var(--shadow);
  font-weight: 600; transition: opacity .3s, transform .3s;
}
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ------------------------------------------------------------------ modal */
dialog.modal {
  border: 0; border-radius: 14px; padding: 0; width: min(94vw, 460px); background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog.modal.wide { width: min(96vw, 640px); }
dialog.modal::backdrop { background: rgba(15, 20, 17, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 8px 16px 16px; }
.modal-msg { margin: 4px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-error { color: var(--danger); font-weight: 600; min-height: 1.2em; margin-top: 8px; }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: calc(100vh - 75px); display: grid; place-items: center; padding: 20px; }
.login-card { width: min(100%, 380px); padding: 28px; }
.login-card .brand { justify-content: center; margin-bottom: 4px; font-size: 20px; }
.login-card p.sub { text-align: center; margin: 0 0 20px; color: var(--ink-2); }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--ink); }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tr.warn td { background: var(--warn-bg); }
table.grid tfoot td { font-weight: 700; border-top: 2px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }

/* inline-editable cells look like text until you touch them */
input.cell, select.cell, textarea.cell {
  border: 1px solid transparent; background: transparent; padding: 6px 8px; min-height: 34px; border-radius: 6px; width: 100%;
}
input.cell:hover, select.cell:hover, textarea.cell:hover { border-color: var(--line-strong); }
input.cell:focus, select.cell:focus, textarea.cell:focus { border-color: var(--accent); background: var(--surface); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input.cell.num { text-align: right; }
textarea.cell { resize: none; overflow: hidden; line-height: 1.35; display: block; min-width: 200px; font-weight: 600; }
input.cell.saved, textarea.cell.saved { background: var(--ok-bg); border-color: var(--ok); }
input.cell.err, textarea.cell.err { background: var(--danger-bg); border-color: var(--danger); }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

/* ------------------------------------------------------------------ calculator */
.calc-layout { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; align-items: start; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 700; }
.stat .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.stat.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stat.primary .label { color: inherit; opacity: .85; }
.picker-list { max-height: 62vh; overflow: auto; border-top: 1px solid var(--line); margin-top: 12px; }
details.cat > summary {
  cursor: pointer; padding: 10px 4px; font-weight: 700; list-style: none; display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line);
}
details.cat > summary::-webkit-details-marker { display: none; }
details.cat > summary::before { content: "▸"; margin-right: 6px; color: var(--ink-2); display: inline-block; transition: transform .15s; }
details.cat[open] > summary::before { transform: rotate(90deg); }
details.cat > summary .grow { flex: 1; }
.dish { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px 7px 22px; cursor: pointer; border-bottom: 1px solid var(--line); }
.dish:hover { background: var(--surface-2); }
.dish input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }
.chip button { border: 0; background: transparent; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; color: inherit; font-size: 16px; line-height: 1; }
.chip button:hover { background: rgba(0, 0, 0, .1); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.type-row td { background: var(--surface-2); font-weight: 700; color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.sticky-side { position: sticky; top: 72px; }

/* ------------------------------------------------------------------ recipes */
.split { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 20px; align-items: start; }
.recipe-list { max-height: 74vh; overflow: auto; }
.recipe-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; cursor: pointer; }
.recipe-item:hover { background: var(--surface-2); }
.recipe-item[aria-current="true"] { background: var(--accent-soft); }
.recipe-item .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.recipe-item .sub { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-2); }
.cat-head { padding: 6px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--ink-2); background: var(--surface-2); position: sticky; top: 0; border-bottom: 1px solid var(--line); }
.servings-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); }
.servings-box input { width: 90px; font-weight: 700; }
.line-warn { color: var(--warn); font-size: 12px; font-weight: 600; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 700; cursor: pointer; text-decoration: underline; }
.cost-box { display: flex; gap: 24px; flex-wrap: wrap; padding: 12px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.cost-box .big { font-size: 22px; font-weight: 800; }

/* ------------------------------------------------------------------ misc */
.empty { padding: 30px; text-align: center; color: var(--ink-2); }
.spinner { padding: 30px; text-align: center; color: var(--ink-2); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 220px; }
.checkline { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; color: var(--ink-2); }
.checkline input { width: 16px; height: 16px; accent-color: var(--accent); }
.quick-add td { background: var(--accent-soft); }
.quick-add input, .quick-add select { background: var(--surface); }

@media (max-width: 900px) {
  .calc-layout, .split { grid-template-columns: 1fr; }
  .sticky-side { position: static; }
  .picker-list, .recipe-list { max-height: 50vh; }
  .form-grid.two { grid-template-columns: 1fr; }
  .who .name { display: none; }
}
@media (max-width: 560px) {
  .page { padding: 14px 12px 60px; }
  .stat .value { font-size: 22px; }
  .nav a { padding: 8px 10px; }
}

/* ------------------------------------------------------------------ print: shopping list on A4 */
#print-root { display: none; }
@page { size: A4; margin: 14mm 12mm; }
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  .print-sheet { color: #000; font-family: var(--font); }
  .print-sheet h1 { font-size: 20pt; margin: 0 0 4mm; }
  .print-meta { display: flex; flex-wrap: wrap; gap: 2mm 8mm; margin-bottom: 3mm; font-size: 11pt; }
  .print-meta b { font-weight: 700; }
  .print-menu { font-size: 9.5pt; color: #333; margin-bottom: 5mm; line-height: 1.35; }
  table.print-table { width: 100%; border-collapse: collapse; font-size: 11pt; }
  table.print-table thead { display: table-header-group; }
  table.print-table th { text-align: left; font-size: 9pt; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1.5px solid #000; padding: 2mm 2mm; }
  table.print-table td { padding: 2.2mm 2mm; border-bottom: .5px solid #999; vertical-align: middle; }
  table.print-table tr { break-inside: avoid; page-break-inside: avoid; }
  table.print-table td.n, table.print-table th.n { text-align: right; white-space: nowrap; }
  table.print-table tr.grp td { background: #eee !important; font-weight: 700; font-size: 9.5pt; text-transform: uppercase; letter-spacing: .06em; padding: 1.5mm 2mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.print-table tr.grp { break-after: avoid; page-break-after: avoid; }
  .tick { display: inline-block; width: 4.2mm; height: 4.2mm; border: 1.2px solid #000; border-radius: 1mm; vertical-align: middle; }
  .print-sub { font-size: 8.5pt; color: #555; margin-top: .5mm; }
  table.print-table tfoot td { border-bottom: .5px solid #999; padding: 2.2mm 2mm; }
  table.print-table tr.sum td { background: #f4f4f4 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.print-table tr.start td { border-top: 1.5px solid #000; }
  table.print-table tr.total td { font-weight: 700; font-size: 13pt; border-top: 1.5px solid #000; border-bottom: 1.5px solid #000; background: #fff !important; }
  table.print-table tfoot { break-inside: avoid; page-break-inside: avoid; }
  .print-foot { margin-top: 6mm; font-size: 8.5pt; color: #555; }
}

/* ------------------------------------------------------------------ small helpers */
.gap { height: 16px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
code { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; }
details summary { cursor: pointer; }

/* activity log */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 200px; min-width: 160px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.filters input, .filters select { width: auto; }
.filters input[type=search] { width: auto; flex: 1 1 220px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* footer on every page */
.site-footer { text-align: center; color: var(--ink-2); font-size: 13px; padding: 18px 16px 28px; border-top: 1px solid var(--line); margin-top: 8px; }

/* ------------------------------------------------------------------ phones */
.nav { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { white-space: nowrap; }
@media (max-width: 700px) {
  .topbar-inner { gap: 8px 12px; padding: 6px 12px; }
  .nav { order: 3; flex: 1 0 100%; }
  .who { margin-left: auto; }
  input[type=text], input[type=number], input[type=search], input[type=password], input[type=date], select, textarea, input.cell, textarea.cell { font-size: 16px; }
  .btn { min-height: 40px; }
  .page-head h1 { font-size: 21px; }
  .toolbar > * { flex: 1 1 100%; }
  .toolbar .checkline { flex: 1 1 auto; }
  .calc-layout .card-pad .row > * { flex: 1 1 100%; }
  dialog.modal { width: 96vw; }

  /* Items & prices: every item becomes a card, nothing is cut off */
  table.stack, table.stack tbody { display: block; }
  table.stack thead { display: none; }
  table.stack tbody tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; position: relative;
    padding: 10px 12px; border-bottom: 8px solid var(--bg);
  }
  table.stack tbody tr:hover { background: transparent; }
  table.stack td { border: 0; padding: 0; min-width: 0; }
  table.stack td.c-name { grid-column: 1 / -1; padding-right: 36px; }
  table.stack td.c-name textarea { min-width: 0; font-size: 16px; }
  table.stack td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--ink-2); padding: 4px 8px 0;
  }
  table.stack td.c-type { grid-column: 1 / -1; }
  table.stack td.nowrap, table.stack td.num:not(:has(input)), table.stack td:not(:has(input, textarea)):not(:last-child):not(.empty) { padding: 0 8px 6px; text-align: left; }
  table.stack td:not(:has(input, textarea))::before { padding-left: 0; }
  table.stack td.num { text-align: left; }
  table.stack td:last-child { position: absolute; top: 6px; right: 6px; }
  table.stack td:last-child::before { display: none; }
  table.stack td.empty { grid-column: 1 / -1; }
  table.stack tr.warn { background: var(--warn-bg); }
  table.stack tr.warn td { background: transparent; }
  input.cell, textarea.cell { border-color: var(--line); background: var(--surface); }
  input.cell.num { text-align: left; }
}

.add-summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.add-summary::-webkit-details-marker { display: none; }
details.add-card[open] > .add-summary { margin-bottom: 8px; }
details.add-card[open] > .add-summary .muted { display: none; }
