/* Bakery Menu Costing. Tokens first, then layout, then components. No external fonts or images. */
:root {
  --bg: #f7f3ec; --surface: #ffffff; --surface-2: #f1ebe1; --ink: #1d1a16; --ink-2: #5d564c; --line: #e2d9cb;
  --accent: #a8481f; --accent-ink: #ffffff; --accent-soft: #f6e4d8;
  --ok: #1f7a4d; --ok-soft: #dcf0e4; --warn: #9a6408; --warn-soft: #f8ead0; --bad: #b3261e; --bad-soft: #f9dedb;
  --radius: 14px; --radius-s: 9px; --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 8px 24px rgb(60 40 20 / 6%);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f; --surface: #1f1b17; --surface-2: #2a251f; --ink: #f3ede4; --ink-2: #b3a999; --line: #3a332b;
    --accent: #e0834f; --accent-ink: #1a0f08; --accent-soft: #3a2418;
    --ok: #6fcf9a; --ok-soft: #173426; --warn: #e6b455; --warn-soft: #3a2c10; --bad: #f28b82; --bad-soft: #3d1b18;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.6rem, 1.1rem + 2vw, 2.25rem); line-height: 1.15; letter-spacing: -0.02em; font-weight: 750; }
h2 { font-size: 1.15rem; letter-spacing: -0.01em; }
h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); margin: 22px 0 10px; }
a { color: var(--accent); }
.muted { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.r { text-align: right; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 6px; }

/* ── top bar ── */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-in, main, .foot-in { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.top-in { display: flex; align-items: center; gap: 20px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -0.01em; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; left: 7px; right: 7px; bottom: 9px; height: 10px; border-radius: 10px 10px 2px 2px; background: var(--accent-ink); opacity: .92; }
.tabs { display: flex; gap: 2px; margin-left: auto; }
.tabs a { padding: 8px 14px; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .95rem; }
.tabs a:hover { color: var(--ink); background: var(--surface-2); }
.tabs a[aria-current] { background: var(--ink); color: var(--bg); }

main { padding-top: 28px; padding-bottom: 56px; min-height: 70vh; }
#view > * + * { margin-top: 20px; }

/* ── hero + KPIs ── */
.hero { padding: 6px 0 2px; }
.lede { color: var(--ink-2); margin-top: 8px; max-width: 62ch; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { font-size: .8rem; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 2rem; font-weight: 760; letter-spacing: -0.03em; line-height: 1.15; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-text { font-size: 1.25rem; letter-spacing: -0.01em; line-height: 1.3; min-height: 2.3rem; display: flex; align-items: center; }
.kpi-note { font-size: .85rem; color: var(--ink-2); margin-top: 2px; }
.is-bad { color: var(--bad); } .is-ok { color: var(--ok); }

/* ── cards, buttons ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 720px; }
.card > .muted { margin: 4px 0 14px; max-width: 70ch; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; align-items: center; } .actions.wrap { flex-wrap: wrap; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: .92rem;
  padding: 9px 14px; min-height: 40px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.icon-btn { appearance: none; border: 0; background: none; color: var(--ink-2); font-size: 1.35rem; line-height: 1; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }

/* ── tables ── */
.table-wrap { overflow-x: auto; margin: 0 -20px -8px; padding: 0 20px 8px; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 650; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th.r { text-align: right; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr[data-act] { cursor: pointer; }
.table tr[data-act]:hover td { background: var(--surface-2); }
.meter-cell { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.meter { position: relative; flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-bar { height: 100%; border-radius: 99px; }
.meter-ok { background: var(--ok); } .meter-warn { background: var(--warn); } .meter-bad { background: var(--bad); }
.meter-target { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .45; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 650; white-space: nowrap; }
.chip-ok { background: var(--ok-soft); color: var(--ok); } .chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-bad { background: var(--bad-soft); color: var(--bad); } .chip-muted { background: var(--surface-2); color: var(--ink-2); }

/* ── forms ── */
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 9px 11px; min-height: 40px; width: 100%; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--ink-2) 55%, var(--line)); }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.field small { font-weight: 400; }
.span2 { grid-column: span 2; }
.card.narrow .form-grid { grid-template-columns: repeat(2, 1fr); }
.table-edit input, .table-edit select { min-width: 84px; }
.table-edit input[type="number"] { max-width: 120px; }
.table-edit td { white-space: nowrap; }
.cell-price { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
.cell-price .delta { order: -1; margin: 0; }
.table-edit td:first-child input { min-width: 170px; font-weight: 600; }
.table-edit td { padding: 7px 8px; }
.delta { font-size: .78rem; font-weight: 700; margin-left: 4px; white-space: nowrap; }
.delta-up { color: var(--bad); } .delta-down { color: var(--ok); }

/* ── recipes ── */
.split { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 20px; align-items: start; }
.list { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 80px; }
.list-new { margin-bottom: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: .95rem; }
.list-item:hover { background: var(--surface-2); }
.list-item.is-current { background: var(--surface); box-shadow: var(--shadow); }
.list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-bad { background: var(--bad); } .dot-muted { background: var(--line); }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; align-items: start; }
.lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) 88px 88px 78px 36px; gap: 8px; align-items: center; }
.line-cost { text-align: right; font-weight: 600; }
.breakdown { position: sticky; top: 80px; }
.breakdown h2 { margin-bottom: 10px; }
.bd-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: .95rem; color: var(--ink-2); }
.bd-row .num { color: var(--ink); font-weight: 600; }
.bd-total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.bd-big { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; margin: 12px 0; }
.bd-big-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 650; }
.bd-big-value { font-size: 2.1rem; font-weight: 760; letter-spacing: -0.03em; line-height: 1.15; }
.bd-status { margin-top: 10px; }
.problem { color: var(--bad); font-size: .9rem; margin-top: 8px; }
.suggest { margin-top: 14px; padding: 14px 16px; border-radius: 12px; background: var(--accent-soft); display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
.suggest-value { font-size: 1.7rem; font-weight: 760; letter-spacing: -0.02em; color: var(--accent); line-height: 1.1; }

/* ── banners, empty states, toast, dialog ── */
.banner { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); border-radius: var(--radius); padding: 14px 18px; }
.banner-bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.banner-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.impact { margin: 8px 0 0; padding-left: 18px; font-size: .93rem; }
.empty { text-align: center; padding: 64px 20px; max-width: 560px; margin: 0 auto; }
.empty p { color: var(--ink-2); margin-top: 12px; }
.empty-inline { padding: 22px; text-align: center; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; }
#notice { position: fixed; left: 0; right: 0; bottom: 20px; display: flex; justify-content: center; z-index: 20; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; font-size: .93rem; max-width: 520px; }
.toast-bad { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--ink); max-width: min(440px, 92vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(20 14 8 / 45%); }
.dialog { padding: 22px; display: grid; gap: 18px; }
.dialog .actions { justify-content: flex-end; }

/* ── footer ── */
.foot { border-top: 1px solid var(--line); padding: 26px 0 40px; font-size: .9rem; color: var(--ink-2); }
.foot p + p { margin-top: 6px; }
.foot strong { color: var(--ink); }
.foot details { margin-top: 14px; }
.foot summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.bug-form { display: grid; gap: 6px; max-width: 460px; margin-top: 12px; }
.bug-form label { font-weight: 600; margin-top: 6px; }
.bug-form .check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.bug-form .btn { justify-self: start; margin-top: 8px; }

/* ── smaller screens ── */
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .editor { grid-template-columns: 1fr; }
  .breakdown { position: static; }
}
@media (max-width: 760px) {
  .top-in { padding-top: 10px; padding-bottom: 8px; gap: 8px; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; }
  .tabs a { padding: 8px 12px; white-space: nowrap; }
  main { padding-top: 18px; }
  .split { grid-template-columns: 1fr; }
  .list { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .list-item { flex: none; background: var(--surface); border: 1px solid var(--line); }
  .list-item .num { display: none; }
  .list-new { margin: 0; flex: none; }
  .form-grid, .card.narrow .form-grid { grid-template-columns: 1fr 1fr; }
  .line { grid-template-columns: 1fr 1fr auto 36px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .line:last-child { border-bottom: 0; }
  .line select[data-l="ingredientId"] { grid-column: 1 / -1; font-weight: 600; }
  .line-cost { min-width: 56px; }
  .card { padding: 16px; }
  /* tables become stacked cards */
  .table thead { position: absolute; left: -9999px; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; }
  .table td { border: 0; padding: 7px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 650; text-align: left; flex: none; }
  .table td:first-child { font-size: 1.05rem; }
  .table td:first-child::before, .table td:last-child:not([data-label])::before { content: none; }
  .table-edit td input, .table-edit td select { max-width: 55%; }
  .table-edit td { white-space: normal; }
  .table-edit td:first-child input { max-width: 100%; }
  .meter-cell { min-width: 0; flex: 1; justify-content: flex-end; }
  .meter { max-width: 120px; }
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
}
@media (max-width: 420px) {
  .kpis { gap: 10px; } .kpi { padding: 12px 14px; } .kpi-value { font-size: 1.6rem; }
  .brand-name { font-size: .98rem; }
  .card-head .actions { width: 100%; flex-wrap: wrap; }
}
@media print {
  .top, .foot, .banner, .actions, #notice { display: none !important; }
  body { background: #fff; } .card, .kpi { box-shadow: none; }
}
@media (prefers-reduced-motion: no-preference) { .btn, .tabs a, .list-item { transition: background-color .12s ease; } }
