:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --ink: #1e2321;
  --muted: #66706a;
  --line: #d7d0c5;
  --panel: #fffdf8;
  --accent: #2d6a5f;
  --accent-dark: #214f47;
  --gold: #c9822a;
  --blue: #4f6f98;
  --danger: #9d3f32;
  --shadow: 0 18px 45px rgba(56, 45, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(79, 111, 152, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(201, 130, 42, 0.13), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body.portal-locked {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(79, 111, 152, 0.16), transparent 38%),
    linear-gradient(315deg, rgba(201, 130, 42, 0.16), transparent 34%),
    var(--bg);
}

.portal-locked .access-gate {
  display: grid;
}

.portal-locked .app {
  filter: blur(8px);
  pointer-events: none;
  user-select: none;
}

.access-card {
  width: min(470px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.97);
  box-shadow: var(--shadow);
  padding: 28px;
}

.access-logo {
  display: block;
  width: 150px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}

.access-card h1 {
  font-size: clamp(2.2rem, 8vw, 4rem);
}

.access-copy {
  margin-top: 14px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

.access-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-logo {
  width: clamp(82px, 10vw, 118px);
  aspect-ratio: 1.33;
  object-fit: contain;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 5px;
  box-shadow: 0 8px 18px rgba(56, 45, 30, 0.08);
}

.brand-logo[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 1.02rem;
  letter-spacing: 0;
}

.client-line {
  margin-top: 10px;
  color: var(--muted);
  font-weight: 700;
}

.summary-pill {
  flex: 0 0 auto;
  min-width: 142px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  text-align: right;
  box-shadow: var(--shadow);
}

.summary-pill span {
  display: block;
  color: var(--accent-dark);
  font-size: 1.8rem;
  font-weight: 850;
  line-height: 1;
}

.summary-pill small {
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  grid-template-areas:
    "controls formula"
    "preferment formula"
    "roadmap production"
    "process process";
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.controls {
  grid-area: controls;
  padding: 18px;
}

.formula {
  grid-area: formula;
  overflow: hidden;
}

.preferment {
  grid-area: preferment;
  padding: 18px;
}

.production {
  grid-area: production;
  padding: 18px;
}

.process {
  grid-area: process;
  padding: 18px;
}

.roadmap {
  grid-area: roadmap;
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.formula-heading {
  padding: 18px 18px 0;
}

.title-field {
  min-width: min(420px, 100%);
}

.formula-name-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 1.06rem;
  font-weight: 850;
}

.formula-name-input:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(45, 106, 95, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee9df;
}

.segmented label {
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 38px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: center;
}

.segmented input:checked + span {
  background: var(--panel);
  color: var(--accent-dark);
  box-shadow: 0 4px 12px rgba(35, 31, 23, 0.12);
}

.control-grid,
.preferment-grid {
  display: grid;
  gap: 12px;
}

.recipe-picker {
  display: block;
  margin-bottom: 12px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.input-row,
.mini-input {
  display: flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.input-row input,
.mini-input input,
.ingredient-name {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.input-row input {
  padding: 10px 12px;
  font-weight: 760;
}

.input-row b,
.mini-input span {
  flex: 0 0 42px;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none;
}

.metric-stack {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.metric-stack div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 7px;
  background: #f0ece4;
}

.metric-stack span {
  color: var(--muted);
  font-weight: 750;
}

.metric-stack strong {
  color: var(--accent-dark);
  font-size: 1.1rem;
}

.button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 850;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-dark);
}

.danger-button {
  border: 1px solid rgba(157, 63, 50, 0.28);
  background: #fff;
  color: var(--danger);
}

.full-button {
  width: 100%;
  margin: 2px 0 10px;
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.backup-actions .save-status {
  grid-column: 1 / -1;
  min-height: 18px;
  margin-top: 0;
  font-size: 0.82rem;
}

.backup-actions .full-span {
  grid-column: 1 / -1;
}

.backup-note {
  margin-top: 2px;
}

.backup-note textarea {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.backup-note textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(45, 106, 95, 0.16);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

th:nth-child(1) {
  width: 32%;
}

th:nth-child(2) {
  width: 18%;
}

th:nth-child(3),
th:nth-child(4) {
  width: 23%;
}

th:nth-child(5) {
  width: 62px;
}

.ingredient-name,
.ingredient-type {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-weight: 760;
}

.ingredient-name:focus,
.ingredient-type:focus,
.mini-input:focus-within,
.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 95, 0.14);
}

.ingredient-type {
  width: 100%;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

#recipeSelect,
#blockSelect,
#unitSelect,
.search-input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 760;
}

.search-input {
  outline: 0;
}

.mini-input input {
  padding: 10px 0 10px 12px;
  font-weight: 760;
}

.weight-input {
  max-width: 130px;
  margin-left: auto;
}

.ingredient-weight {
  color: var(--accent-dark);
  text-align: right;
  font-size: 1.02rem;
  font-weight: 850;
}

.weight-cell {
  color: var(--accent-dark);
  font-size: 1.05rem;
  font-weight: 850;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 900;
}

.icon-button:disabled {
  color: #b9b1a5;
  cursor: not-allowed;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 850;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.preferment-results {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.preferment-results div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.preferment-results span {
  color: var(--muted);
  font-weight: 750;
}

.preferment-results strong {
  color: var(--blue);
}

.production-sheet {
  display: grid;
  gap: 16px;
}

.print-body {
  display: grid;
  gap: 16px;
}

.print-body h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.print-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--accent);
}

.print-header span,
.production-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.print-header h3 {
  margin: 3px 0 0;
  font-size: 1.35rem;
}

.print-logo {
  display: block;
  width: 104px;
  height: auto;
  margin-bottom: 8px;
}

.print-header strong {
  color: var(--accent-dark);
}

.production-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.production-meta div {
  padding: 11px;
  border-radius: 7px;
  background: #f0ece4;
}

.production-meta strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
}

.production-table th:nth-child(1),
.production-table th:nth-child(2),
.production-table th:nth-child(3) {
  width: auto;
}

.process-steps {
  overflow-x: auto;
}

.process-table th,
.process-table td {
  font-size: 0.9rem;
}

.process-table th:nth-child(1),
.process-table th:nth-child(2),
.process-table th:nth-child(3),
.process-table th:nth-child(4) {
  width: 25%;
}

.process-table td:first-child {
  color: var(--accent-dark);
  font-weight: 850;
}

.method-block {
  padding-top: 4px;
}

.method-block h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.method-block ol {
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
}

.method-block li + li {
  margin-top: 5px;
}

.muted-note {
  color: var(--muted);
  font-weight: 650;
}

.roadmap-grid {
  display: grid;
  gap: 10px;
}

.roadmap-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: #f0ece4;
}

.roadmap-grid strong {
  color: var(--accent-dark);
}

.roadmap-grid span {
  color: var(--muted);
  line-height: 1.35;
}

.formula-dialog {
  width: min(920px, calc(100% - 28px));
  max-height: min(860px, calc(100vh - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(35, 31, 23, 0.28);
}

.formula-dialog::backdrop {
  background: rgba(30, 35, 33, 0.45);
}

.formula-dialog form {
  display: grid;
  gap: 16px;
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-heading p {
  margin-top: 4px;
  color: var(--muted);
}

.dialog-grid {
  display: grid;
  grid-template-columns: 1.5fr 0.7fr 0.8fr;
  gap: 12px;
}

.builder-section {
  display: grid;
  gap: 10px;
}

.compact-heading {
  align-items: center;
  margin-bottom: 0;
}

.builder-table th:nth-child(1) {
  width: 42%;
}

.builder-table th:nth-child(2) {
  width: 24%;
}

.builder-table th:nth-child(3) {
  width: 24%;
}

.builder-table th:nth-child(4) {
  width: 56px;
}

.process-builder-table th:nth-child(1),
.process-builder-table th:nth-child(2),
.process-builder-table th:nth-child(3),
.process-builder-table th:nth-child(4) {
  width: 23%;
}

.process-builder-table th:nth-child(5) {
  width: 56px;
}

.builder-name,
.builder-type,
.builder-percent,
.process-section-input,
.process-step-input,
.process-detail-input,
.process-value-input,
.method-input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 760;
}

.builder-name,
.builder-type,
.process-section-input,
.process-step-input,
.process-detail-input,
.process-value-input {
  min-height: 42px;
  padding: 0 12px;
}

.builder-percent {
  border: 0;
  padding: 10px 0 10px 12px;
}

.method-input {
  padding: 10px 12px;
  line-height: 1.35;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.save-status {
  margin-right: auto;
  color: var(--muted);
  font-weight: 750;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .summary-pill {
    text-align: left;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "formula"
      "preferment"
      "production"
      "process"
      "roadmap";
  }

  .production-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dialog-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1180px);
    padding: 14px 0;
  }

  h1 {
    font-size: 2.45rem;
  }

  .brand-lockup {
    flex-direction: column;
  }

  .brand-logo {
    width: 112px;
  }

  .formula-heading,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  .button-row {
    width: 100%;
  }

  .dialog-actions .button,
  .compact-heading .button {
    width: 100%;
  }

  .production-meta {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 9px 8px;
  }

  th:nth-child(1) {
    width: 30%;
  }

  th:nth-child(5) {
    width: 44px;
  }

  .icon-button {
    width: 32px;
  }
}

@media print {
  @page {
    size: letter portrait;
    margin: 0.38in;
  }

  body {
    background: #fff;
    color: #111;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .topbar,
  .controls,
  .formula,
  .preferment,
  .process,
  .roadmap {
    display: none;
  }

  .app {
    width: 100%;
    padding: 0;
  }

  .workspace {
    display: block;
  }

  .production {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .production .section-heading {
    display: none;
  }

  .production-meta {
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
  }

  .print-logo {
    width: 78px;
    margin-bottom: 4px;
  }

  .production-sheet {
    gap: 10px;
  }

  .print-header {
    align-items: start;
    padding-bottom: 8px;
  }

  .print-header h3 {
    margin-top: 2px;
    font-size: 1.25rem;
    line-height: 1.05;
  }

  .print-header span,
  .print-header strong,
  .production-meta span {
    font-size: 0.7rem;
  }

  .production-meta div {
    padding: 6px 8px;
    border-radius: 3px;
  }

  .production-meta strong {
    margin-top: 2px;
    font-size: 0.84rem;
  }

  .print-body {
    display: block;
  }

  .print-page {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .process-print-page {
    break-before: page;
    page-break-before: always;
  }

  .recipe-print-page {
    margin-top: 8px;
  }

  .process-print-page {
    padding-top: 0;
  }

  .print-body {
    align-items: start;
  }

  .print-body h3,
  .method-block h3 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    line-height: 1.1;
  }

  .process-table th,
  .process-table td,
  .production-table th,
  .production-table td {
    font-size: 0.78rem;
    line-height: 1.15;
  }

  .process-table th,
  .production-table th {
    font-size: 0.68rem;
  }

  .process-table th:nth-child(1),
  .process-table td:nth-child(1) {
    width: 18%;
  }

  .process-table th:nth-child(2),
  .process-table td:nth-child(2) {
    width: 18%;
  }

  .process-table th:nth-child(3),
  .process-table td:nth-child(3) {
    width: 31%;
  }

  .process-table th:nth-child(4),
  .process-table td:nth-child(4) {
    width: 33%;
  }

  th,
  td {
    padding: 4px 6px;
  }
}
