/* Layout: a plant-floor logbook. Dark smokehouse header band, concrete page, stamped mono lot codes; tabs for Batches / Lots / Trace / Recipes. */
:root {
  --bg: #EFEFEB;
  --surface: #FFFFFF;
  --surface-2: #F6F6F3;
  --ink: #17191B;
  --muted: #5C6064;
  --line: #D5D5CF;
  --band: #1E1C1A;
  --band-ink: #F3EFE8;
  --band-muted: #A9A398;
  --accent: #9A1D1D;
  --accent-ink: #FFFFFF;
  --accent-soft: #F5E3E1;
  --ok: #2E6A3A;
  --ok-soft: #E2EFE4;
  --warn: #8F5600;
  --warn-soft: #F8ECD6;
  --bad: #B42318;
  --bad-soft: #FBE4E1;
  --scrim: rgba(20, 18, 16, 0.55);
  --focus: #1F5FBF;
  --display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --body: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131415; --surface: #1C1E20; --surface-2: #232528; --ink: #ECEBE6; --muted: #A2A5A8; --line: #34373B;
    --band: #0C0B0A; --band-ink: #F3EFE8; --band-muted: #9C968B;
    --accent: #E2655C; --accent-ink: #1A0D0C; --accent-soft: #3A1E1C;
    --ok: #78C487; --ok-soft: #1D3123; --warn: #E8AE4E; --warn-soft: #3A2D15; --bad: #F2796D; --bad-soft: #3D1C19;
    --scrim: rgba(0, 0, 0, 0.65); --focus: #7FB0FF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131415; --surface: #1C1E20; --surface-2: #232528; --ink: #ECEBE6; --muted: #A2A5A8; --line: #34373B;
  --band: #0C0B0A; --band-ink: #F3EFE8; --band-muted: #9C968B;
  --accent: #E2655C; --accent-ink: #1A0D0C; --accent-soft: #3A1E1C;
  --ok: #78C487; --ok-soft: #1D3123; --warn: #E8AE4E; --warn-soft: #3A2D15; --bad: #F2796D; --bad-soft: #3D1C19;
  --scrim: rgba(0, 0, 0, 0.65); --focus: #7FB0FF;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.45; }
.wrap { max-width: 1040px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: 0.01em; text-wrap: balance; margin: 0; line-height: 1.1; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Header band */
.top { background: var(--band); color: var(--band-ink); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 18px 14px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; gap: 2px; }
.mark { font-family: var(--display); font-weight: 700; font-size: 30px; letter-spacing: 0.06em; line-height: 1; }
.mark b { color: var(--accent); font-weight: 700; }
.sub { font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--band-muted); }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-block: 0; }
.tab { background: none; border: 0; color: var(--band-muted); padding: 10px 14px 12px; font-family: var(--display); font-size: 18px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--band-ink); border-bottom-color: var(--accent); }
.tab:hover { color: var(--band-ink); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 14px; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.top .btn.primary { min-height: 44px; padding-inline: 18px; font-size: 16px; }

main { padding-block: 22px 60px; display: flex; flex-direction: column; gap: 20px; }
.banner { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 12px 14px; font-size: 15px; }
.banner.warn { background: var(--warn-soft); border-color: transparent; color: var(--ink); }
.banner.info { background: var(--accent-soft); border-color: transparent; }

/* Summary strip */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stat { background: var(--surface); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .n { font-family: var(--display); font-size: 30px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat.warn .n { color: var(--warn); }
.stat.bad .n { color: var(--bad); }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 26px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; font-weight: 500; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.void td { color: var(--muted); }
tr.void .code { text-decoration: line-through; }
td.code, .code { font-family: var(--mono); font-weight: 500; letter-spacing: 0.02em; white-space: nowrap; }
.detail td { background: var(--surface-2); padding: 14px 16px 18px; }
.detail-grid { display: flex; flex-direction: column; gap: 12px; }
.kv { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 14px; }
.kv span b { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-right: 6px; }
.inner { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); overflow-x: auto; }
.inner table { font-size: 14px; }
.row-acts { display: flex; gap: 8px; flex-wrap: wrap; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.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); }

.empty { border: 1px dashed var(--line); border-radius: 8px; padding: 28px 20px; text-align: center; color: var(--muted); background: var(--surface); }
.empty h3 { color: var(--ink); font-size: 22px; margin-bottom: 6px; }

/* Forms */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; min-width: 0; }
.input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); text-transform: none; letter-spacing: normal; font-weight: 400; font-size: 16px; }
textarea.input { min-height: 80px; resize: vertical; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .grid3, .grid2 { grid-template-columns: minmax(0, 1fr); } }
.hint { font-size: 13px; color: var(--muted); text-transform: none; letter-spacing: normal; font-weight: 400; }
.err { color: var(--bad); font-size: 14px; font-weight: 500; }
.err:empty { display: none; }

/* Overlay sheets */
.overlay { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; z-index: 50; padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }
#layer2 { z-index: 60; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 100%; overflow-y: auto; border-radius: 10px; display: flex; flex-direction: column; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; background: var(--band); color: var(--band-ink); position: sticky; top: 0; z-index: 2; }
.sheet-head h2 { font-size: 24px; }
.sheet-head .x { background: none; border: 0; color: var(--band-muted); font-size: 15px; cursor: pointer; padding: 6px; }
.sheet-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface); position: sticky; bottom: 0; flex-wrap: wrap; }
@media (max-width: 640px) { .overlay { align-items: flex-end; padding-inline: 0; padding-bottom: 0; } .sheet { border-radius: 12px 12px 0 0; max-height: 94%; } .sheet-foot { padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)); } }

/* Ingredient rows in batch form */
.irows { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.irow { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.6fr) auto; gap: 8px 12px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.irow:last-child { border-bottom: 0; }
.irow.missing { box-shadow: inset 3px 0 0 var(--warn); }
.iname { font-weight: 600; min-width: 0; }
.iacts { display: flex; gap: 6px; }
.imeta { grid-column: 2 / -1; font-size: 13px; }
@media (max-width: 640px) { .irow { grid-template-columns: minmax(0, 1fr); } .imeta { grid-column: 1; } }
.label-h { font-family: var(--display); font-size: 18px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }

/* Scan panel */
.scan { border: 2px dashed var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); }
.scan-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.scan .btn.primary { min-height: 48px; font-size: 16px; padding-inline: 18px; }
.scan-status { font-size: 14px; }
.scan-status.ok { color: var(--ok); }
.scan-status.bad { color: var(--bad); }
.preview { max-height: 220px; width: auto; max-width: 100%; border-radius: 6px; border: 1px solid var(--line); align-self: flex-start; }
.vis-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Recipes */
.flav { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface); display: flex; flex-direction: column; gap: 12px; margin: 0; }
.flav-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.flavs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 800px) { .flavs { grid-template-columns: minmax(0, 1fr); } }
.foot-acts { display: flex; gap: 10px; flex-wrap: wrap; }

.trace-q { max-width: 520px; }
.trace-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.trace-card h3 { font-size: 20px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.trace-list { display: flex; flex-direction: column; gap: 12px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 12px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 500; z-index: 80; max-width: calc(100% - 32px); }
@media (prefers-reduced-motion: no-preference) { #toast:not([hidden]) { animation: rise 0.2s ease-out; } @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } } }

/* Standalone page additions */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.top { margin-top: calc(-1 * env(safe-area-inset-top, 0px)); padding-top: env(safe-area-inset-top, 0px); }
.top-acts { display: flex; gap: 8px; align-items: center; }
.btn.on-dark { color: var(--band-muted); border-color: transparent; }
.btn.on-dark:hover { color: var(--band-ink); }
.auth { max-width: 420px; margin: 24px auto; display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 22px; }
.auth h2 { font-size: 28px; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
.scanner { width: 100%; max-width: 480px; border-radius: 8px; overflow: hidden; background: #000; align-self: center; }
.scanner video { width: 100% !important; height: auto !important; display: block; }
.tip { font-size: 13px; color: var(--muted); }
.tip b { color: var(--ink); }
#layer3 { z-index: 70; }
.label-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.recipe-text { font-family: var(--body); line-height: 1.5; min-height: 220px; }
.recipe-view { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; line-height: 1.55; font-size: 16px; overflow-wrap: anywhere; }
.ing-ul { margin: 6px 0 0; padding-left: 20px; columns: 2; column-gap: 24px; }
@media (max-width: 640px) { .ing-ul { columns: 1; } }
label.f .linkish { align-self: flex-start; text-transform: none; letter-spacing: normal; font-size: 14px; margin-top: 2px; }
.label-text { font-size: 20px; font-weight: 500; letter-spacing: 0.04em; }

.ocr-text { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin: 6px 0 0; max-height: 200px; overflow: auto; }
.scan-btns label.btn { cursor: pointer; }

.paused-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.auth.paused { max-width: 520px; }
