@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,600;700&display=swap');

:root {
  --bg: #f4efe7;
  --bg-2: #f7f0e4;
  --ink: #1f2a24;
  --ink-soft: #4b5a50;
  --accent: #ea580c;
  --accent-2: #f59e0b;
  --accent-3: #fdba74;
  --card: #fffdf8;
  --line: rgba(31, 42, 36, 0.12);
  --size-tone-25: #fff9df;
  --size-tone-30: #f2fbef;
  --size-tone-35: #fff3f1;
  --size-tone-25-line: #e9ddb0;
  --size-tone-30-line: #cfe7cb;
  --size-tone-35-line: #e9cec8;
  --shadow: 0 24px 50px rgba(31, 42, 36, 0.12);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Fira Sans", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #fef3e2 0%, #f4efe7 50%, #efe7d9 100%);
  min-height: 100vh;
}

.app-shell {
  position: relative;
  overflow: hidden;
}

.app-shell::before,
.app-shell::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  filter: blur(0px);
  opacity: 0.5;
  z-index: 0;
}

.app-shell::before {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(14, 116, 144, 0.18), transparent 70%);
  top: -160px;
  right: -120px;
}

.app-shell::after {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, rgba(224, 122, 95, 0.16), transparent 70%);
  bottom: -200px;
  left: -180px;
}

header {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #fb923c);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  box-shadow: 0 18px 30px rgba(234, 88, 12, 0.22);
}

.brand h1 {
  font-family: "Fraunces", serif;
  font-size: 28px;
  margin: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.status-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #6b7280;
  display: inline-block;
}

.status-pill.connected span {
  background: #16a34a;
}

main {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.section {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: fadeUp 0.7s ease both;
  position: relative;
  z-index: 1;
}

.section.results {
  padding: 16px;
}

.section.results .section-title {
  margin-bottom: 8px;
}

.section.results .grid {
  gap: 8px;
}

.section.results .legend {
  margin-top: 4px;
}

.section.compact {
  padding: 18px 20px;
}

#unitSection {
  z-index: 1000;
}

#unitSection .grid {
  grid-template-columns: 1fr;
}

.unit-field {
  max-width: none;
}

#bufferSection .grid-3 {
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 180px);
  align-items: end;
}

.buffer-by-day-grid {
  margin-top: 12px;
  grid-template-columns: repeat(7, minmax(44px, 1fr));
  gap: 8px;
}

.buffer-by-day-grid label {
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  margin-bottom: 4px;
}

.buffer-by-day-grid .input-compact {
  width: 100%;
  max-width: none;
  min-width: 0;
  text-align: center;
  padding: 6px 4px;
}

.holiday-buffer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.holiday-buffer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.holiday-buffer-head label {
  margin: 0;
}

.holiday-rows {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.holiday-row {
  display: grid;
  grid-template-columns: minmax(120px, 168px) minmax(84px, 108px) auto;
  gap: 8px;
  align-items: center;
}

.holiday-row input {
  margin: 0;
}

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

.section-title h2 {
  margin: 0;
  font-size: 20px;
}

.section-title small {
  color: var(--ink-soft);
}

.subsection {
  margin-top: 6px;
}

.subsection + .subsection {
  margin-top: 16px;
}

.subsection-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid-7 {
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
}

label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  display: block;
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-size: 15px;
  background: #fff;
  color: var(--ink);
}

input.input-compact {
  width: 50px;
  max-width: 50px;
  padding: 6px 8px;
  text-align: center;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.18);
}

.field-error {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
}

.input-error {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.12);
}

.button {
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

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

.button.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(234, 88, 12, 0.22);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 8px 14px;
  cursor: pointer;
  background: #fff;
  font-weight: 500;
}

.chip.active {
  background: rgba(234, 88, 12, 0.15);
  border-color: rgba(234, 88, 12, 0.6);
}

.segment {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.segment button {
  border: none;
  padding: 8px 14px;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-soft);
}

.segment button.active {
  background: rgba(234, 88, 12, 0.16);
  color: var(--ink);
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.table th,
.table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.table td.left {
  text-align: left;
}

.result-table {
  min-width: 980px;
}

.result-table input[type="number"] {
  min-width: 68px;
  width: 68px;
  padding: 3px 6px;
}

.table-scroll {
  margin-top: 18px;
  max-height: 70vh;
  overflow: auto;
}

.result-table th,
.result-table td {
  padding: 5px 4px;
}

.result-table tr.day-separator td {
  border-top: 2px solid rgba(31, 42, 36, 0.22);
}

.result-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}

.combo {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: visible;
}

.combo.field-error {
  border-color: #dc2626;
}

.combo.open {
  z-index: 1000;
}

.combo input {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 8px 6px;
  width: 100%;
  flex: 1;
  min-width: 0;
}

.combo:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.18);
}

.combo input:focus {
  box-shadow: none;
}

.combo-toggle {
  font-size: 16px;
}

.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink-soft);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-button:hover,
.combo-toggle:hover {
  background: rgba(234, 88, 12, 0.1);
  color: var(--ink);
}

.icon-button:focus {
  outline: none;
}

.combo.open .combo-toggle {
  background: rgba(234, 88, 12, 0.1);
  color: var(--ink);
}

.combo-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 18px 30px rgba(31, 42, 36, 0.18);
  display: none;
  z-index: 1001;
}

.combo.open .combo-menu {
  display: block;
}

.combo-item {
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}

.combo-item:hover,
.combo-item:focus {
  background: rgba(234, 88, 12, 0.1);
  outline: none;
}

.combo-item.hidden {
  display: none;
}

.cell-zero {
  color: rgba(31, 42, 36, 0.45);
}

.input-zero {
  color: rgba(31, 42, 36, 0.45);
}

.date-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: center;
}

.date-stack .date-sub {
  font-size: 11px;
}

.date-stack .date-sub {
  font-size: 12px;
  color: var(--ink-soft);
}

.cell-alert {
  background: rgba(220, 38, 38, 0.14);
  color: #991b1b;
  font-weight: 600;
}

.cell-writeoff {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
  font-weight: 600;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--line);
  background: #fffaf2;
  font-size: 13px;
}

.legend-title {
  font-weight: 600;
  color: var(--ink-soft);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.legend-alert {
  background: rgba(220, 38, 38, 0.14);
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.6);
}

.legend-writeoff {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}

.size-filter {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.label-inline {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.inline-field select {
  width: auto;
  min-width: 90px;
  padding: 6px 8px;
}

.delivery-days {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.delivery-actions {
  margin-bottom: 10px;
}

.delivery-days.field-error {
  border: 1px dashed rgba(220, 38, 38, 0.6);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.chips.field-error {
  border: 1px solid rgba(220, 38, 38, 0.6);
  padding: 6px;
  border-radius: 999px;
}

.hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  margin-left: 6px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(234, 88, 12, 0.18);
  color: var(--ink);
  cursor: help;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(224, 122, 95, 0.15);
  color: var(--ink);
  font-size: 12px;
}

.badge.ok {
  background: rgba(249, 115, 22, 0.22);
}

.row-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.action-download-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 24px;
  align-items: start;
}

.action-group,
.template-download-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.action-group label,
.template-download-group label {
  margin-bottom: 6px;
  text-align: center;
}

.action-group-actions,
.template-download-actions {
  justify-content: center;
}

.muted {
  color: var(--ink-soft);
  font-size: 13px;
}

textarea.order-output {
  min-height: 140px;
  font-size: 14px;
  resize: vertical;
  background: #fefcf7;
}

.order-summary {
  margin-bottom: 12px;
}

.order-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.order-summary-head label {
  margin: 0;
}

.order-toggle-button {
  padding: 8px 14px;
}

.order-table {
  min-width: 520px;
}

.order-table th,
.order-table td {
  min-width: 72px;
}

.order-table th.size-col,
.order-table td.size-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  text-align: left;
  min-width: 94px;
}

.order-table thead th.size-col {
  z-index: 3;
}

.order-table .order-trays {
  font-weight: 700;
  font-size: 17px;
  line-height: 1.1;
}

.order-table .order-units {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
  user-select: text;
}

.order-table tr.size-tone-25,
.result-table tr.size-tone-25,
.retro-table tr.size-tone-25 {
  background: var(--size-tone-25);
}

.order-table tr.size-tone-30,
.result-table tr.size-tone-30,
.retro-table tr.size-tone-30 {
  background: var(--size-tone-30);
}

.order-table tr.size-tone-35,
.result-table tr.size-tone-35,
.retro-table tr.size-tone-35 {
  background: var(--size-tone-35);
}

.order-table tr.size-tone-25 td.size-col {
  background: var(--size-tone-25);
}

.order-table tr.size-tone-30 td.size-col {
  background: var(--size-tone-30);
}

.order-table tr.size-tone-35 td.size-col {
  background: var(--size-tone-35);
}

.summary-note {
  margin: 4px 0 8px;
}

.planning-mode {
  margin: 6px 0 10px;
  padding: 12px 14px;
  border: 1px solid rgba(234, 88, 12, 0.28);
  border-radius: 12px;
  background: rgba(255, 244, 230, 0.8);
}

.planning-mode-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.planning-mode-desc,
.planning-mode-dates {
  font-size: 13px;
  color: var(--ink-soft);
}

.planning-mode-dates {
  margin-top: 4px;
}

.monday-corrections {
  margin: 0 0 10px;
  padding: 12px 14px;
  border: 1px solid rgba(31, 42, 36, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.monday-corrections-title {
  font-size: 14px;
  font-weight: 700;
}

.monday-corrections-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}

.monday-corrections-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
}

.monday-correction-day {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(244, 239, 231, 0.35);
}

.monday-correction-day-head {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.monday-correction-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr) minmax(118px, auto);
  gap: 8px;
  font-size: 12px;
  line-height: 1.35;
  padding: 2px 0;
}

.monday-correction-row span:last-child {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.delta-pos {
  color: #15803d;
}

.delta-neg {
  color: #b91c1c;
}

.delta-zero {
  color: var(--ink-soft);
}

.retro-block {
  margin-top: 18px;
}

.retro-controls {
  align-items: end;
}

.retro-actions {
  display: flex;
  flex-direction: column;
}

.retro-buttons {
  display: flex;
  gap: 8px;
  width: 100%;
}

.retro-buttons .button {
  flex: 1 1 0;
}

.retro-actions .button {
  width: 100%;
}

.retro-toggle {
  display: flex;
  align-items: end;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  text-transform: none;
  letter-spacing: normal;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

.checkbox-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.retro-table {
  min-width: 920px;
}

.retro-table-scroll {
  max-height: 60vh;
}

.retro-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}

.retro-note {
  font-size: 15px;
  font-weight: 600;
}

.growth-pos {
  color: #15803d;
  font-weight: 600;
}

.growth-neg {
  color: #b91c1c;
  font-weight: 600;
}

.mobile-cards {
  display: none;
}

@media (min-width: 769px) and (max-width: 1366px) {
  body.retro-laptop-cards #retroCards {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
  }
  body.retro-laptop-cards #retroCards .mobile-card + .mobile-card {
    margin-top: 0;
  }
}

.mobile-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fffaf2;
  padding: 10px;
}

.mobile-card.size-tone-25 {
  background: var(--size-tone-25);
  border-color: var(--size-tone-25-line);
}

.mobile-card.size-tone-30 {
  background: var(--size-tone-30);
  border-color: var(--size-tone-30-line);
}

.mobile-card.size-tone-35 {
  background: var(--size-tone-35);
  border-color: var(--size-tone-35-line);
}

.mobile-size-col.size-tone-25 {
  background: var(--size-tone-25);
  border-color: var(--size-tone-25-line);
}

.mobile-size-col.size-tone-30 {
  background: var(--size-tone-30);
  border-color: var(--size-tone-30-line);
}

.mobile-size-col.size-tone-35 {
  background: var(--size-tone-35);
  border-color: var(--size-tone-35-line);
}

.mobile-card + .mobile-card {
  margin-top: 8px;
}

.mobile-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.mobile-card-head strong {
  font-size: 14px;
}

.mobile-card-head span {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}

.mobile-card-sub {
  margin-top: -4px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.mobile-day-card {
  padding: 10px;
}

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

.mobile-size-col {
  border: 1px dashed rgba(31, 42, 36, 0.25);
  border-radius: 10px;
  padding: 6px 5px;
  background: rgba(255, 255, 255, 0.6);
  min-width: 0;
}

.mobile-size-col-head {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  text-align: center;
}

.mobile-size-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-size-metric + .mobile-size-metric {
  margin-top: 5px;
}

.mobile-size-metric span {
  font-size: 10px;
  color: var(--ink-soft);
}

.mobile-size-metric b {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.1;
}

.mobile-size-metric input[type="number"] {
  width: 100%;
  margin: 0;
  padding: 4px 3px;
  font-size: 13px;
}

.mobile-day-summary {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.mobile-day-summary-item {
  border: 1px dashed rgba(31, 42, 36, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  padding: 6px 8px;
}

.mobile-day-summary-item span {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 2px;
}

.mobile-day-summary-item b {
  font-size: 15px;
  font-weight: 700;
}

.mobile-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mobile-metric {
  border: 1px dashed rgba(31, 42, 36, 0.2);
  border-radius: 10px;
  padding: 7px 8px;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}

.mobile-metric span {
  font-size: 11px;
  color: var(--ink-soft);
}

.mobile-metric b {
  font-size: 14px;
  font-weight: 600;
}

.mobile-metric-full {
  grid-column: 1 / -1;
}

.mobile-plan-input {
  width: 100%;
  margin: 0;
}

.mobile-metric b.cell-alert,
.mobile-metric b.cell-writeoff {
  display: inline-block;
  border-radius: 8px;
  padding: 2px 6px;
}

.hidden {
  display: none;
}

.week-grid {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.week-grid table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.week-grid th,
.week-grid td {
  border-bottom: 1px solid var(--line);
  padding: 10px 6px;
  text-align: center;
}

.week-grid th {
  background: #f7f1e8;
  font-weight: 600;
}

.week-grid input[type="number"] {
  width: 72px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  text-align: center;
  margin: 0 auto;
  display: block;
}

.week-grid input[type="date"] {
  width: 130px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin: 0 auto;
  display: block;
}

#deliveryTable th:last-child,
#deliveryTable td:last-child {
  min-width: 92px;
}

.delivery-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.table input[type="number"] {
  width: 72px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  text-align: center;
  margin: 0 auto;
  display: block;
}

.date-stepper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.date-stepper .stock-expiry {
  width: 130px;
  margin: 0;
}

.date-stepper .stock-expiry-step {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.table input[type="date"] {
  width: 130px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin: 0 auto;
  display: block;
}

.table input[type="date"]::-webkit-datetime-edit-year-field {
  display: none;
}

.table input[type="date"]::-webkit-datetime-edit-text {
  padding: 0 2px;
}

.table select {
  width: 86px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin: 0 auto;
  display: block;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px 14px 8px;
  }
  main {
    padding: 8px 14px 56px;
  }
  .brand h1 {
    font-size: 24px;
  }
  .status-pill {
    width: 100%;
  }
  .section-title {
    flex-direction: column;
    align-items: flex-start;
  }
  .section {
    padding: 16px;
    border-radius: 20px;
  }
  .setup-grid {
    grid-template-columns: 1fr;
  }
  #bufferSection .grid-3 {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .buffer-by-day-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }
  .holiday-buffer-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .holiday-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  }
  .grid-7 {
    grid-template-columns: repeat(3, minmax(60px, 1fr));
  }
  .chips {
    gap: 8px;
  }
  .chip {
    padding: 7px 12px;
  }
  .row-actions {
    gap: 8px;
  }
  .action-download-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .action-group,
  .template-download-group {
    width: 100%;
    align-items: stretch;
  }
  .action-group label,
  .template-download-group label {
    text-align: left;
  }
  .action-group-actions,
  .template-download-actions {
    justify-content: flex-start;
  }
  .delivery-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .delivery-actions .badge {
    width: 100%;
    justify-content: center;
  }
  .delivery-actions .inline-field,
  .delivery-actions .button {
    width: 100%;
  }
  .delivery-actions .inline-field {
    justify-content: space-between;
  }
  .delivery-actions #clearDeliveries {
    justify-self: start;
  }
  .retro-toggle {
    align-items: flex-start;
  }
  .checkbox-inline {
    font-size: 13px;
    line-height: 1.35;
  }
  .order-summary-head {
    align-items: flex-start;
  }
  .order-table-scroll {
    overflow: visible;
  }
  .order-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }
  .order-table th,
  .order-table td {
    min-width: 0;
    padding: 6px 2px;
    font-size: 12px;
  }
  .order-table th.size-col,
  .order-table td.size-col {
    min-width: 72px;
    width: 72px;
  }
  .order-table .order-trays {
    font-size: 14px;
  }
  .order-table .order-units {
    font-size: 10px;
  }
  .retro-controls {
    grid-template-columns: 1fr;
  }
  .retro-actions label {
    display: none;
  }
  .result-table,
  .retro-table {
    min-width: 640px;
  }
  .result-table-wrap,
  .retro-table-wrap {
    display: none;
  }
  #resultCards,
  #retroCards,
  .mobile-cards {
    display: block !important;
    margin-top: 10px;
  }
  .week-grid {
    border: none;
    overflow: visible;
  }
  #stockTable thead {
    display: none;
  }
  #stockTable,
  #stockTable tbody {
    display: block;
    width: 100%;
  }
  #stockTable tr {
    display: grid;
    grid-template-columns: minmax(62px, 0.85fr) minmax(68px, 0.9fr) minmax(56px, 0.72fr) minmax(124px, 1.35fr);
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 8px;
    margin-bottom: 10px;
    background: #fffaf2;
  }
  #stockTable td {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 0;
    border: none;
    text-align: left;
    min-width: 0;
  }
  #stockTable td::before {
    content: attr(data-label);
    font-size: 10px;
    color: var(--ink-soft);
    font-weight: 600;
  }
  #stockTable td[data-label="Действия"] {
    grid-column: 1 / -1;
    align-items: flex-end;
  }
  #stockTable td[data-label="Действия"] .icon-button {
    width: 26px;
    height: 26px;
    font-size: 15px;
  }
  #stockTable select,
  #stockTable input[type="number"],
  #stockTable input[type="date"] {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 7px 8px;
    font-size: 13px;
  }
  #stockTable input[type="date"] {
    letter-spacing: -0.01em;
  }
  #stockTable .date-stepper {
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
  }
  #stockTable .date-stepper .stock-expiry {
    width: 100%;
    min-width: 0;
  }
  #stockTable .date-stepper .stock-expiry-step {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 18px;
  }
  #deliveryTable {
    width: 100%;
  }
  #deliveryTable thead {
    display: none;
  }
  #deliveryTable,
  #deliveryTable tbody {
    display: block;
    width: 100%;
  }
  #deliveryTable tr {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fffaf2;
  }
  #deliveryTable td {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0;
    border: none;
    text-align: left;
    min-width: 0;
  }
  #deliveryTable td::before {
    content: attr(data-label);
    font-size: 11px;
    color: var(--ink-soft);
    font-weight: 600;
  }
  #deliveryTable td:nth-child(1) {
    grid-column: 1 / 2;
  }
  #deliveryTable td:nth-child(2) {
    grid-column: 2 / 5;
  }
  #deliveryTable td:nth-child(3),
  #deliveryTable td:nth-child(4),
  #deliveryTable td:nth-child(5),
  #deliveryTable td:nth-child(6) {
    grid-column: span 1;
  }
  #deliveryTable td[data-label="Действия"] {
    grid-column: 1 / -1;
  }
  #deliveryTable .delivery-row-actions {
    justify-content: flex-start;
  }
  #deliveryTable input[type="number"] {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 5px 6px;
  }
  #deliveryTable input[type="date"] {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 5px 6px;
  }
  .mobile-size-grid {
    gap: 6px;
  }
  .monday-corrections-grid {
    grid-template-columns: 1fr;
  }
  .monday-correction-row {
    grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1fr) minmax(108px, auto);
    gap: 6px;
  }
}

@media (max-width: 520px) {
  .section {
    padding: 14px;
    border-radius: 16px;
  }
  .grid-7 {
    grid-template-columns: repeat(2, minmax(60px, 1fr));
  }
  .buffer-by-day-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .holiday-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  }
  .table-scroll {
    margin-left: -6px;
    margin-right: -6px;
    padding-left: 6px;
    padding-right: 6px;
  }
  .retro-note {
    font-size: 13px;
  }
  .row-actions .button,
  .retro-actions .button {
    width: 100%;
  }
  .retro-buttons {
    flex-direction: column;
  }
  .order-table th,
  .order-table td {
    padding: 5px 1px;
    font-size: 11px;
  }
  .order-table th.size-col,
  .order-table td.size-col {
    min-width: 64px;
    width: 64px;
  }
  .order-table .order-trays {
    font-size: 13px;
  }
  .mobile-size-col {
    padding: 5px 4px;
  }
  .mobile-size-col-head {
    font-size: 11px;
  }
  .mobile-size-metric span {
    font-size: 9px;
  }
  .mobile-size-metric b {
    font-size: 12px;
  }
  .mobile-day-summary-item b {
    font-size: 14px;
  }
  .monday-correction-row {
    font-size: 11px;
    grid-template-columns: 38px minmax(0, 1fr) minmax(0, 1fr) minmax(100px, auto);
    gap: 5px;
  }
}
