/* Home Bakery core app. Warm Ledger palette from the accepted v3.2 prototype, as tokens with light/dark themes. */
:root {
  --ink: #2B2321; --paper: #FAF7F2; --surface: #ffffff; --surface-2: #f8f2eb; --line: #e9e0d8; --line-2: #bfb3a8;
  --muted: #625b54; --brand: #1F5F66; --brand-ink: #ffffff; --accent: #C46A2B; --danger: #9b3c2b;
  --notice: #fff4e7; --warn-bg: #fdecea; --chip: #f4e3d2; --chip-ink: #75411e; --head: #2B2321; --head-ink: #ffffff;
  --ok: #1F5F66; --under: #8a5a00; --loss: #9b3c2b; --highlight: #fff1c2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1ebe5; --paper: #1b1715; --surface: #26201d; --surface-2: #2f2824; --line: #40372f; --line-2: #6b5f55;
    --muted: #b8aca2; --brand: #5fb3bb; --brand-ink: #10201f; --accent: #e39a5f; --danger: #e07b69;
    --notice: #3a2c1f; --warn-bg: #3d2420; --chip: #4a3626; --chip-ink: #f4d4b9; --head: #120f0e; --head-ink: #f1ebe5;
    --ok: #5fb3bb; --under: #e0b45a; --loss: #e07b69; --highlight: #4d4220;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #f1ebe5; --paper: #1b1715; --surface: #26201d; --surface-2: #2f2824; --line: #40372f; --line-2: #6b5f55;
  --muted: #b8aca2; --brand: #5fb3bb; --brand-ink: #10201f; --accent: #e39a5f; --danger: #e07b69;
  --notice: #3a2c1f; --warn-bg: #3d2420; --chip: #4a3626; --chip-ink: #f4d4b9; --head: #120f0e; --head-ink: #f1ebe5;
  --ok: #5fb3bb; --under: #e0b45a; --loss: #e07b69; --highlight: #4d4220;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--paper); }
body { margin: 0; background: var(--paper); color: var(--ink); }
a { color: var(--brand); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 50; background: var(--surface); padding: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar { background: var(--head); color: var(--head-ink); padding: 14px 5%; display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.topbar small { color: #f4d4b9; margin-left: 6px; }
.lang-selector { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; margin: 0 8px; }
.lang-btn { background: transparent; border: 1px solid transparent; color: var(--head-ink); opacity: 0.82; cursor: pointer; padding: 4px 8px; font-size: 13px; border-radius: 4px; font-weight: 500; font-family: inherit; transition: opacity 0.15s, background 0.15s, border-color 0.15s; }
.lang-btn:hover { opacity: 1; background: rgba(255, 255, 255, 0.14); }
.lang-btn[aria-current="true"], .lang-btn.active { opacity: 1; font-weight: 700; background: rgba(255, 255, 255, 0.22); border-color: rgba(255, 255, 255, 0.35); text-decoration: underline; text-underline-offset: 3px; }
.lang-sep { opacity: 0.35; color: var(--head-ink); user-select: none; font-size: 11px; }
.save-status { font-size: 14px; }
.save-status.offline, .save-status.error { color: #ffd2a8; font-weight: 600; }
.save-status.read_only { color: #ffd2a8; }

.workflow-nav { position: sticky; top: 0; z-index: 10; background: var(--paper); border-bottom: 1px solid var(--line); padding: 8px 5%;
  display: flex; gap: 4px 14px; flex-wrap: wrap; }
.workflow-nav a { text-decoration: none; padding: 8px 4px; font-weight: 600; color: var(--ink); }
.workflow-nav a[aria-current] { color: var(--brand); border-bottom: 3px solid var(--brand); }
#globalNotices { max-width: 1100px; margin: 0 auto; padding: 0 18px; }

main { max-width: 1100px; margin: auto; padding: 20px 18px 70px; }
main:focus { outline: none; }
h1 { font-size: clamp(24px, 4vw, 34px); margin: 0 0 8px; }
h1:focus { outline: none; }
h2 { font-size: 20px; margin: 0 0 8px; }
p { line-height: 1.5; }
.lead { color: var(--muted); margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 3px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 16px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.card .big { font-size: 26px; font-weight: 700; margin: 4px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

button, .button { border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 9px; padding: 10px 15px; cursor: pointer;
  font: inherit; font-weight: 600; text-decoration: none; display: inline-block; min-height: 44px; }
button.secondary, .button.secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
button.danger { background: var(--danger); color: #fff; }
button.secondary.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.link { background: none; color: var(--brand); padding: 0; min-height: 0; text-decoration: underline; font-weight: 600; }
button.link.subtle { color: var(--muted); font-weight: 400; }
button.icon { background: none; color: var(--muted); padding: 6px 10px; }
button.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select, textarea { border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 10px; font: inherit; width: 100%;
  background: var(--surface); color: var(--ink); min-height: 42px; }
textarea { min-height: 80px; }
input.narrow { max-width: 80px; }
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 1px var(--danger); }
.field { display: block; font-weight: 600; font-size: 14px; }
.field > span:first-child { display: block; margin-bottom: 4px; }
.field-error { display: block; color: var(--danger); font-size: 13px; font-weight: 600; margin-top: 3px; }
.field-error:empty { display: none; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }
.check input { width: 22px; min-height: 22px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* --- recipe editor: compact controls, then the summary line, then the table (spec §2) --- */
.editor-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.editor-head h1 { margin: 0; }
.editor .about { margin-top: 18px; }   /* reference text sits after the cost result, outside the editing flow */
details > summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 6px 0; min-height: 32px; }
.about-body { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px; font-size: 14px; }
.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 14px; margin-top: 12px; }
.controls .wide { grid-column: span 2; }
@media (max-width: 420px) { .controls { grid-template-columns: 1fr 1fr; } .controls .wide { grid-column: 1 / -1; } }
.prod-summary { margin: 10px 0 6px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.4; }
.prod-summary.attention { color: var(--danger); }
.table-head { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin-top: 8px; }
.table-head h2 { margin: 0; }
.reuse-line { margin: 0; font-size: 14px; }
.reuse-line:empty { display: none; }
[hidden] { display: none !important; }   /* component display rules must never override the hidden attribute */
.chip, .badge { display: inline-block; background: var(--chip); color: var(--chip-ink); border-radius: 20px; padding: 3px 9px; font-size: 12px; font-weight: 600; }
.chip.mine { background: var(--surface-2); color: var(--muted); }
.chip-btn { background: var(--chip); color: var(--chip-ink); min-height: 30px; padding: 3px 10px; border-radius: 20px; font-size: 12px; }
.badge.reused { margin-left: 4px; }

.ingredient-scroll { overflow-x: auto; position: relative; }   /* containing block for .sr-only cells, or they widen the page */
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); }
td.num, .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
table.ingredients td input { min-width: 72px; }
table.ingredients .ing-cell { min-width: 180px; }
table.ingredients .ing-cell select { margin-top: 4px; font-size: 13px; min-height: 34px; }
.pack { display: flex; gap: 4px; align-items: center; min-width: 290px; }
.pack input { width: 76px; }
.pack select { width: 96px; }
.component-heading th { background: var(--surface-2); color: var(--brand); }
.component-heading .comp-name { display: inline-block; width: auto; min-width: 160px; font-weight: 700; min-height: 34px; }
.row-issue { margin: 4px 0 0; color: var(--danger); font-size: 13px; font-weight: 600; }
.row-issue:empty { display: none; }
tr.highlight td { background: var(--highlight); transition: background .3s; }
.scroll-hint { display: none; color: var(--muted); font-size: 13px; margin: 4px 0; }
@media (max-width: 700px) { .scroll-hint { display: block; } }
.table-head .scroll-hint { margin: 0; font-size: 13px; }
.th-hint { font-size: 12px; margin-top: 2px; }

.notice { background: var(--notice); border-left: 4px solid var(--accent); padding: 10px 12px; margin: 12px 0; border-radius: 4px; }
.notice.warn { background: var(--warn-bg); border-left-color: var(--danger); }
.issue-list { margin: 6px 0 0; padding-left: 20px; }
.cost-result .totals, .totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; margin: 10px 0; }
.totals div { display: flex; flex-direction: column; }
.totals dt { font-size: 13px; color: var(--muted); }
.totals dd { margin: 0; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.component-breakdown { margin: 8px 0; }
.component-cost { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.status { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.status.on_target, .status.price_meets_target { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.status.underpriced, .status.raise_price_reduce_cost { background: color-mix(in srgb, var(--under) 18%, transparent); color: var(--under); }
.status.loss { background: color-mix(in srgb, var(--loss) 18%, transparent); color: var(--loss); }
.status-line { margin: 4px 0; }
.attention { color: var(--danger); font-weight: 600; }

.list { list-style: none; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.shopping-checklist { display: grid; gap: 8px; }
.shop-item { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); flex-wrap: wrap; }
.shop-item input { width: 22px; min-height: 22px; accent-color: var(--brand); }
.shop-item.done .shop-name { text-decoration: line-through; opacity: .6; }
.shop-name { flex: 1; font-weight: 600; }
.shop-qty { font-weight: 650; white-space: nowrap; }
.shop-progress { color: var(--brand); }
.auth { max-width: 440px; margin: 30px auto; }
.auth form { display: grid; gap: 12px; }
.auth-links { font-size: 14px; }
.danger-zone { border-color: var(--danger); }
.loading { color: var(--muted); }

@media (max-width: 600px) {
  main { padding: 14px 16px 60px; }
  .panel { padding: 14px; }
  th, td { padding: 6px 4px; font-size: 13px; }
  .topbar { padding: 10px 16px; }
  .workflow-nav { padding: 6px 16px; gap: 2px 10px; }
}
@media print {
  .topbar, .workflow-nav, #globalNotices, .shopping-tools, .notice, .lead { display: none !important; }
  html, body { background: #fff !important; color: #000; }
  .shop-item { break-inside: avoid; border: 0; border-bottom: 1px solid #ddd; border-radius: 0; }
}
.small-heading { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }

/* --- rc3 customer UX correction (HOME_BAKERY_RC2_CUSTOMER_UX_CORRECTION_BRIEF_v1.0) --- */
/* home: five equal journey steps dominate; KPIs are a compact, subordinate grid */
.home h1 { font-size: clamp(22px, 3vw, 28px); }
.journey { list-style: none; padding: 0; margin: 16px 0 26px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.journey li { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.journey .step-main { flex: 1; display: flex; gap: 10px; align-items: flex-start; padding: 14px; text-decoration: none; color: var(--ink); border-radius: 12px; }
.journey .step-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.journey strong { font-size: 15px; line-height: 1.3; }
.journey .step-sub { font-size: 13px; color: var(--muted); line-height: 1.35; }
.journey .step-extra { padding: 0 14px 12px 50px; font-size: 13px; font-weight: 600; }
.journey .n { flex: none; background: var(--surface-2); border-radius: 50%; width: 26px; height: 26px; display: inline-grid; place-items: center; font-size: 13px; font-weight: 700; }
.journey li.done .n { background: var(--brand); color: var(--brand-ink); }
@media (max-width: 900px) { .journey { grid-template-columns: 1fr; gap: 8px; } .journey .step-main { padding: 12px; } }
.kpi-title { font-size: 15px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-value { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-name { display: block; font-size: 17px; overflow-wrap: anywhere; }
.kpi-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.kpi .attention { margin: 4px 0 0; }
.kpi-statuses { list-style: none; padding: 0; margin: 2px 0 0; display: grid; gap: 4px; }
.kpi-statuses li { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-variant-numeric: tabular-nums; }

/* forms: label / control / helper / error share rows (subgrid), so helper text never pushes neighbours out of line */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); column-gap: 16px; row-gap: 0; align-items: start; }
.form-grid > .field { display: grid; grid-template-rows: subgrid; grid-row: span 4; align-content: start; padding-bottom: 14px; min-width: 0; }
.form-grid > .field > span:first-child { align-self: end; }
.form-grid > .field.wide { grid-column: 1 / -1; max-width: 520px; }
@media (max-width: 420px) { .form-grid { grid-template-columns: 1fr 1fr; column-gap: 12px; } }
.settings-groups { display: grid; gap: 12px; max-width: 900px; margin-top: 8px; }
fieldset.group { border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px 0; background: var(--surface); }
fieldset.group legend { font-weight: 700; font-size: 15px; padding: 0 6px; }
.editor-controls { margin-top: 12px; }
.control-groups { display: grid; grid-template-columns: 4fr 3fr; gap: 12px; }
.control-groups .group { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 0; background: var(--surface); min-width: 0; }
.control-groups .form-grid { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); column-gap: 12px; }
.settings-groups .form-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.group-title { font-size: 14px; margin: 0 0 8px; }
.hint.inline { display: inline; margin: 0 0 0 6px; }
.control-groups .order-grid { grid-template-columns: minmax(0, 1fr) minmax(150px, 1.4fr) minmax(0, 1fr); }
@media (max-width: 760px) { .control-groups { grid-template-columns: 1fr; } .control-groups .form-grid { grid-template-columns: 1fr 1fr; } }

/* recipe list: name left, status right */
.recipe-list li { justify-content: space-between; gap: 6px 16px; }
.recipe-list li > a { font-weight: 600; }

/* ingredient rows: totals line up with the inputs; stacked cards at phone width */
table.ingredients td.total-cell, table.ingredients td.remove-cell { line-height: 42px; padding-top: 8px; }
@media (max-width: 600px) {
  .editor .ingredient-scroll { overflow: visible; }
  .editor .scroll-hint { display: none; }
  table.ingredients, table.ingredients tbody { display: block; }
  table.ingredients thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.ingredients tr[data-line] { display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: row dense; gap: 8px 10px; padding: 12px 0;
    border-bottom: 1px solid var(--line); position: relative; }
  table.ingredients tr[data-line] td { display: block; border: 0; padding: 0; min-width: 0; }
  table.ingredients td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
  table.ingredients tr[data-line] td.ing-cell { grid-column: 1 / -1; min-width: 0; padding-right: 48px; }
  table.ingredients .price-cell { grid-column: 1 / -1; }
  table.ingredients td input { min-width: 0; }
  table.ingredients .pack { min-width: 0; }
  table.ingredients .pack input { flex: 1; width: auto; min-width: 0; }
  table.ingredients .pack select { flex: 1.3; width: auto; min-width: 0; }
  table.ingredients td.total-cell { text-align: left; line-height: 1.4; padding-top: 0; }
  table.ingredients td.remove-cell { position: absolute; top: 28px; right: 0; padding: 0; line-height: normal; }
  table.ingredients tr.component-heading, table.ingredients tr.component-heading th { display: block; }
}

/* prices & profit: one task-first table, an explicit incomplete state, secondary tools in disclosures */
.prod-table th, .prod-table td { vertical-align: middle; }
.incomplete-cell .incomplete-msg { display: block; font-weight: 600; }
.incomplete-cell .small { display: block; }
details.more { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 4px; }
details.more .panel { margin-top: 6px; }
@media (max-width: 600px) {
  table.stack-mobile, table.stack-mobile tbody, table.stack-mobile tr { display: block; }
  table.stack-mobile thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack-mobile tr { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
  table.stack-mobile th[scope="row"] { display: block; background: none; border: 0; padding: 0 0 6px; font-size: 15px; }
  table.stack-mobile td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 3px 0; text-align: right; white-space: normal; }
  table.stack-mobile td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  table.stack-mobile td.incomplete-cell { display: block; text-align: left; }
  table.stack-mobile td.incomplete-cell::before { display: none; }
}

/* Search component (per approved v3.2 prototype, themed) */
.search-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0 18px;
}
.search-panel label {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}
.search-panel input[type="search"] {
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  color: var(--ink);
  border: 2px solid var(--brand);
  border-radius: 9px;
  outline: none;
  font-family: inherit;
}
.search-panel input[type="search"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 95, 102, 0.25);
}
.search-panel p.search-hint {
  margin: 4px 0 10px;
  font-size: 13px;
  color: var(--muted);
}
.search-results {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  margin-top: 10px;
}
.search-result {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  gap: 12px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.search-result:hover, .search-result:focus-visible {
  background: var(--notice);
  border-color: var(--brand);
  outline: none;
}
.search-result strong {
  display: block;
  font-size: 15px;
  color: var(--ink);
}
.search-result small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}
.search-result span:last-child {
  font-weight: 600;
  font-size: 13px;
  color: var(--brand);
  white-space: nowrap;
}
@media (max-width: 600px) {
  .search-result {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
}
