:root {
  --ink: #161616;
  --paper: #f3efe6;
  --paper-2: #fbfaf6;
  --muted: #6f6c65;
  --line: #d8d2c7;
  --green: #345f50;
  --orange: #d76b2d;
  --red: #9f3f37;
  --yellow: #b78620;
  --shadow: 0 18px 55px rgba(24, 20, 12, 0.08);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Arial, Helvetica, sans-serif; line-height: 1.45; }
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
.login-card { width: min(100%, 440px); padding: 32px; background: var(--paper-2); border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-card h1 { font-size: 42px; }
.login-icon { border-radius: 14px; margin-bottom: 28px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin: 28px 0 20px; }
.login-form input { min-height: 48px; font-size: 16px; }
.login-form button { margin-top: 12px; min-height: 48px; }
.login-error { color: var(--red); margin: 4px 0; }
.install-help { font-size: 14px; border-top: 1px solid var(--line); padding-top: 18px; margin-top: 20px; }
.install-help summary { cursor: pointer; }
.install-help p { margin: 12px 0 0; }
.logout-form { margin: 0; }
.logout-form button { padding: 0; border: 0; background: transparent; color: var(--green); cursor: pointer; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 76px;
  padding: 16px clamp(18px, 4vw, 60px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
  background: rgba(243, 239, 230, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand { text-decoration: none; display: flex; flex-direction: column; font-weight: 800; letter-spacing: 0.24em; line-height: 1.15; font-size: 13px; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 20px; font-size: 14px; }
.site-header nav a { text-decoration: none; border-bottom: 1px solid transparent; }
.site-header nav a:hover { border-bottom-color: var(--ink); }

.page-shell { width: min(1480px, calc(100% - 36px)); margin: 0 auto; padding: 48px 0 80px; }
.site-footer { padding: 30px; text-align: center; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; border-top: 1px solid var(--line); }

h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 880px; margin-bottom: 14px; font-size: clamp(34px, 5vw, 68px); line-height: 0.98; letter-spacing: -0.045em; }
h2 { margin-bottom: 4px; font-size: clamp(24px, 3vw, 36px); line-height: 1.05; letter-spacing: -0.03em; }
h3 { letter-spacing: -0.02em; }
.lede { max-width: 780px; margin-bottom: 0; color: var(--muted); font-size: 18px; }
.eyebrow { margin-bottom: 10px; font-size: 11px; font-weight: 800; letter-spacing: 0.2em; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.9em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.small-text { font-size: 12px; overflow-wrap: anywhere; }

.hero-row, .batch-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 30px; margin-bottom: 34px; }
.hero-row.compact h1 { font-size: clamp(34px, 4vw, 56px); }

.button {
  appearance: none;
  border: 1px solid var(--ink);
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  transition: transform 120ms ease, background 120ms ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--ink); color: white; }
.button.secondary { background: transparent; color: var(--ink); }
.button.success { background: var(--green); border-color: var(--green); color: white; }
.button.warning { background: var(--yellow); border-color: var(--yellow); color: white; }
.button.danger { background: var(--red); border-color: var(--red); color: white; }
.button.full { width: 100%; margin-top: 10px; }
.link-button { border: 0; background: transparent; text-decoration: underline; cursor: pointer; color: var(--red); padding: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 24px 0; }
.metric-grid.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.metric { min-height: 118px; padding: 20px; background: var(--paper-2); border: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between; }
.metric span { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.metric strong { font-size: clamp(24px, 3vw, 38px); letter-spacing: -0.04em; }

.notice { margin: 18px 0 30px; padding: 15px 18px; border-left: 4px solid var(--green); background: #e8eee8; font-size: 14px; }
.warning-note { border-left-color: var(--orange); background: #f7eadc; }

.section-card, .side-card, .form-card { background: var(--paper-2); border: 1px solid var(--line); box-shadow: var(--shadow); }
.section-card { margin-bottom: 22px; padding: clamp(18px, 3vw, 30px); }
.side-card { margin-bottom: 18px; padding: 22px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 20px; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 10px; text-align: left; color: var(--muted); font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase; border-bottom: 1px solid var(--ink); white-space: nowrap; }
td { padding: 13px 10px; vertical-align: top; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: rgba(0, 0, 0, 0.025); }
.product-number { font-size: 18px; font-weight: 800; }

.status { display: inline-block; padding: 4px 8px; background: #e8e5df; font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }
.status-drying { background: #f7dfc5; color: #70400f; }
.status-cooling { background: #dce9ee; color: #245264; }
.status-qa-hold { background: #efe5bd; color: #6d5810; }
.status-released { background: #dbe8dd; color: #285137; }
.status-rework, .status-rejected { background: #f1d6d3; color: #772f29; }

.empty-state { padding: 45px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); }
.empty-state.small { padding: 24px 15px; }

.form-shell { width: min(960px, 100%); margin: 0 auto; }
.form-shell > div:first-child { margin-bottom: 28px; }
.form-shell h1 { font-size: clamp(34px, 5vw, 58px); }
.form-card { padding: clamp(20px, 4vw, 38px); }
.menu-ingredients { min-width: 16rem; max-width: 32rem; white-space: normal; overflow-wrap: anywhere; }
.form-grid { display: grid; gap: 18px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid .span-two { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }
label small { font-weight: 400; letter-spacing: 0; }
.checkbox-label { flex-direction: row; align-items: center; min-height: 44px; margin-bottom: 20px; font-size: 14px; letter-spacing: 0; }
.checkbox-label input[type="checkbox"] { flex: 0 0 22px; width: 22px; height: 22px; padding: 0; accent-color: var(--red); }
input, select, textarea { width: 100%; border: 1px solid #b9b3a8; background: white; color: var(--ink); border-radius: 0; padding: 12px 13px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 2px rgba(22, 22, 22, 0.08); }
textarea { resize: vertical; }
.form-actions { margin-top: 26px; display: flex; justify-content: flex-end; gap: 10px; }
.form-subhead { margin: 28px 0 14px; }
.score-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }

.batch-header h1 { font-size: clamp(34px, 5vw, 62px); }
.batch-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 13px; color: var(--muted); }
.qr-card { flex: 0 0 170px; padding: 13px; text-align: center; background: white; border: 1px solid var(--line); }
.qr-card img { width: 140px; height: 140px; display: block; margin: auto; }
.qr-card a { font-size: 12px; }
.action-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.action-strip form { margin: 0; }

.two-column-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 22px; align-items: start; }
.two-column-layout aside { position: sticky; top: 98px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin: 0; border-top: 1px solid var(--line); }
.detail-grid > div { padding: 16px 8px; border-bottom: 1px solid var(--line); }
.detail-grid dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.detail-grid dd { margin: 5px 0 0; font-weight: 700; }
.note-block { margin-top: 18px; padding: 16px; background: var(--paper); }
.note-block p { margin: 6px 0 0; white-space: pre-wrap; }
.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 20px; }
.photo-grid figure { margin: 0; }
.photo-grid img, .qa-photo { width: 100%; max-height: 330px; object-fit: cover; display: block; }
.photo-grid figcaption { margin-top: 6px; color: var(--muted); font-size: 11px; }
.qa-list { display: grid; gap: 12px; }
.qa-entry { display: grid; grid-template-columns: 70px 1fr; gap: 16px; padding: 17px; background: var(--paper); border: 1px solid var(--line); }
.qa-score { display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line); }
.qa-score strong { font-size: 30px; }
.qa-score span { color: var(--muted); font-size: 11px; }
.qa-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.qa-entry p { margin-bottom: 6px; }
.qa-photo { margin-top: 12px; max-width: 320px; }

@media (max-width: 1050px) {
  .metric-grid.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .score-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-column-layout { grid-template-columns: 1fr; }
  .two-column-layout aside { position: static; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
}

@media (max-width: 760px) {
  .site-header { position: static; flex-direction: column; align-items: flex-start; gap: 14px; }
  .site-header nav { gap: 14px; }
  .page-shell { width: min(100% - 24px, 1480px); padding-top: 30px; }
  .hero-row, .batch-header { flex-direction: column; }
  .qr-card { width: 100%; flex-basis: auto; }
  .metric-grid, .metric-grid.six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 102px; }
  .form-grid.two, .detail-grid, .photo-grid { grid-template-columns: 1fr; }
  .form-grid .span-two { grid-column: span 1; }
  .score-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading { flex-direction: column; }
  .two-column-layout aside { grid-template-columns: 1fr; }
  .action-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-strip form .button { width: 100%; }
  .qa-entry { grid-template-columns: 1fr; }
  .qa-score { border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
}

/* Generic QR registry */
.qr-chip { display: inline-block; margin: 4px 4px 4px 0; padding: 7px 9px; text-decoration: none; background: var(--ink); color: white; font-size: 12px; }
.small-metric { font-size: 12px !important; overflow-wrap: anywhere; letter-spacing: 0 !important; }
.qr-tools { display: flex; flex-wrap: wrap; gap: 18px; align-items: end; }
.compact-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.compact-form label { min-width: 150px; }
.claim-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.claim-row { margin: 0 0 8px; }
.claim-row button { width: 100%; min-height: 64px; padding: 10px 12px; border: 1px solid var(--line); background: var(--paper); text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.claim-row button:hover { border-color: var(--ink); background: white; }
.claim-row span { color: var(--muted); font-size: 12px; }
.large-gap { gap: 12px; margin-top: 20px; }
.wide-shell { width: min(1280px, 100%); }

@media (max-width: 900px) {
  .claim-columns { grid-template-columns: 1fr; }
}

/* Batch intake calculated fields */
.calculated-field { display: flex; flex-direction: column; justify-content: center; gap: 7px; padding: 12px 13px; border: 1px solid #b9b3a8; background: #f7f5ef; min-height: 72px; }
.calculated-field .calculated-label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }
.calculated-field strong { font-size: 20px; letter-spacing: -0.02em; }
.calculated-field small { color: var(--muted); font-size: 11px; }
.compact-calculated { margin-top: 14px; }
.form-grid.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 760px) { .form-grid.three { grid-template-columns: 1fr; } }

/* Recipe and ERP entry forms */
.material-section { margin-top: 24px; }
.material-group { min-width: 0; margin: 18px 0; padding: 16px; border: 1px solid var(--line); }
.material-group legend { font-weight: 700; padding: 0 8px; }
.material-allocation { padding: 16px 0; border-top: 1px solid var(--line); margin-bottom: 16px; }
.material-config { align-items: end; margin: 16px 0; }
.material-allocation [hidden] { display: none; }
.repeater-list { display: grid; gap: 12px; margin: 12px 0 18px; }
.repeater-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; gap: 12px; padding: 14px; border: 1px solid var(--line); background: var(--paper); align-items: end; }
.repeater-row.step-row { grid-template-columns: minmax(0, 1fr) repeat(3, minmax(0, 1fr)) auto; }
.repeater-row .span-two { grid-column: span 2; }
@media (max-width: 760px) {
  .repeater-row, .repeater-row.step-row { grid-template-columns: 1fr; }
  .repeater-row .span-two { grid-column: span 1; }
}
