:root {
  --ink: #20321d;
  --muted: #70806b;
  --line: #dce5d5;
  --paper: #f3f7ed;
  --white: #ffffff;
  --green: #4b8b25;
  --green-dark: #34722c;
  --lime: #66a91e;
  --mint: #e8f3de;
  --orange: #ef543c;
  --orange-dark: #d94330;
  --orange-soft: #fff0e7;
  --yellow: #ffad18;
  --shadow: 0 18px 50px rgba(54, 111, 43, 0.13);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  padding-bottom: 112px;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(255, 173, 24, 0.5);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  z-index: 40;
  top: 0;
  height: 72px;
  padding: 0 max(24px, calc((100vw - 1460px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 850;
  letter-spacing: -0.04em;
}
.brand > span:last-child span { color: var(--orange); }
.brand-mark {
  width: 40px;
  height: 40px;
  display: block;
  overflow: hidden;
  border-radius: 11px;
  background: var(--green);
  box-shadow: 0 4px 12px rgba(52, 114, 44, 0.18);
}
.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center 24%;
}
nav { display: flex; align-items: center; gap: 8px; }
nav a, nav span {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 750;
}
nav a { color: var(--muted); text-decoration: none; }
nav a:hover { background: var(--paper); color: var(--green-dark); }
nav span { background: var(--mint); color: var(--green-dark); }

main { max-width: 1460px; margin: 0 auto; padding: 24px 24px 36px; }
.intro {
  min-height: 174px;
  padding: 30px 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  overflow: hidden;
  position: relative;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(118deg, var(--lime) 0%, var(--green) 48%, var(--green-dark) 100%);
  box-shadow: var(--shadow);
}
.intro::after {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  right: -90px;
  top: -150px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 50%;
  box-shadow: 0 0 0 30px rgba(255,255,255,.03), 0 0 0 60px rgba(255,255,255,.02);
}
.intro > * { position: relative; z-index: 1; }
.eyebrow, .section-kicker {
  margin: 0 0 7px;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .13em;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  font: 500 clamp(38px, 4vw, 56px) / 1 Georgia, "Times New Roman", serif;
  letter-spacing: -.045em;
}
.intro > div:first-child > p:last-child {
  margin: 13px 0 0;
  color: rgba(255,255,255,.82);
  font-size: 15px;
}
.intro-controls { display: flex; align-items: stretch; gap: 12px; }
.intro-controls label {
  min-width: 190px;
  padding: 13px 16px;
  display: grid;
  gap: 5px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 14px;
  background: rgba(255,255,255,.11);
}
.intro-controls label span, .norm-chip small {
  color: rgba(255,255,255,.7);
  font-size: 11px;
  font-weight: 750;
}
.intro-controls input {
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  color-scheme: dark;
  font-weight: 750;
}
.norm-chip {
  min-width: 142px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 5px;
  align-items: end;
  border-radius: 14px;
  background: rgba(31,70,26,.28);
}
.norm-chip small { grid-column: 1 / -1; }
.norm-chip strong { font: 500 28px Georgia, serif; }
.norm-chip span { padding-bottom: 4px; color: rgba(255,255,255,.72); font-size: 11px; }

.stats {
  margin: 18px 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--white);
}
.stats > div {
  min-height: 78px;
  padding: 15px 18px;
  display: grid;
  align-content: center;
  gap: 4px;
  border-right: 1px solid var(--line);
}
.stats > div:last-child { border-right: 0; }
.stats span { color: var(--muted); font-size: 11px; font-weight: 700; }
.stats strong { font: 500 25px Georgia, serif; }
.stats .holiday-stat strong { color: var(--orange); }
.stats .accent-stat { background: var(--mint); }
.stats .accent-stat strong { color: var(--green-dark); }

.workspace {
  display: grid;
  grid-template-columns: minmax(650px, 1fr) 560px;
  gap: 18px;
  align-items: start;
}
.products-card, .calendar-card {
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--white);
  box-shadow: 0 10px 34px rgba(40,75,34,.06);
}
.products-card { min-width: 0; overflow: hidden; }
.section-head, .calendar-head {
  padding: 21px 22px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.section-kicker { margin-bottom: 4px; color: var(--green); font-size: 10px; }
.section-head h2, .calendar-head h2 { margin: 0; font: 500 25px Georgia, serif; letter-spacing: -.025em; }
.inventory-status {
  margin: 6px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.inventory-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #aab3aa; }
.inventory-status[data-status="saved"]::before { background: var(--green); }
.inventory-status[data-status="loading"]::before { background: var(--yellow); }
.inventory-status[data-status="error"] { color: var(--orange-dark); }
.inventory-status[data-status="error"]::before { background: var(--orange); }
.search-field {
  width: min(310px, 45%);
  height: 44px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}
.search-field:focus-within { border-color: #82b662; box-shadow: 0 0 0 4px rgba(75,139,37,.1); }
.search-field > span { color: var(--green); font-size: 22px; transform: rotate(-15deg); }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }

.table-wrap { border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
th {
  position: sticky;
  z-index: 10;
  top: 72px;
  padding: 11px 10px;
  background: #3d762e;
  color: #fff;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}
th:first-child { width: 43%; padding-left: 18px; text-align: left; }
th:nth-child(2) { width: 7%; }
th:nth-child(3), th:nth-child(4), th:nth-child(5) { width: 16.66%; }
td {
  height: 60px;
  padding: 9px 10px;
  border-bottom: 1px solid #e8ece8;
  text-align: center;
  font-size: 13px;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbf7; }
tbody tr.has-order { background: #f3faed; box-shadow: inset 3px 0 0 var(--lime); }
td:first-child { padding-left: 18px; text-align: left; font-weight: 650; line-height: 1.35; }
.unit-badge {
  display: inline-grid;
  min-width: 30px;
  min-height: 27px;
  padding: 4px 6px;
  place-items: center;
  border-radius: 7px;
  background: #eff2ee;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}
.balance-input, .buy-input {
  width: 100%;
  min-width: 58px;
  height: 39px;
  padding: 0 8px;
  border: 1px solid #e7c9bf;
  border-radius: 9px;
  outline: 0;
  background: #fff6f2;
  color: var(--ink);
  text-align: center;
  font-weight: 750;
  appearance: textfield;
}
.balance-input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(239,84,60,.1); }
.balance-input:disabled { color: #aab3aa; background: #f3f4f2; border-color: #e2e5e1; cursor: wait; }
.balance-input::-webkit-outer-spin-button, .balance-input::-webkit-inner-spin-button,
.buy-input::-webkit-outer-spin-button, .buy-input::-webkit-inner-spin-button { appearance: none; }
.norm-value { font-weight: 800; font-variant-numeric: tabular-nums; }
.norm-value { color: var(--green-dark); }
.buy-control { display: flex; align-items: center; gap: 4px; }
.buy-input { border-color: #bfd9b1; background: #f6fbf2; color: var(--orange-dark); }
.buy-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(75,139,37,.12); }
.buy-input.zero { color: #aab3aa; font-weight: 650; }
.buy-input.manual { border-color: var(--yellow); background: #fff8e7; color: var(--ink); }
.reset-buy {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: #ffe8b8;
  color: #906000;
  font-size: 16px;
  font-weight: 850;
  cursor: pointer;
}
.reset-buy:hover { background: #ffd989; }
tbody tr.manual-order { box-shadow: inset 3px 0 0 var(--yellow); }
.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 14px; }

.calendar-card { position: sticky; top: 90px; padding-bottom: 20px; }
.text-button { border: 0; background: transparent; color: var(--green); font-size: 12px; font-weight: 750; cursor: pointer; }
.text-button:disabled { color: #aab3aa; cursor: default; }
.legend { padding: 0 22px 12px; display: flex; flex-wrap: wrap; gap: 8px 15px; color: var(--muted); font-size: 10px; font-weight: 700; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; display: block; border-radius: 3px; }
.legend-workday { border: 1px solid #d9e0da; background: #fff; }
.legend-holiday { background: var(--orange-soft); box-shadow: inset 0 0 0 1px #f7c8bb; }
.legend-quadruple { background: var(--orange); box-shadow: inset 0 0 0 1px var(--orange-dark); }
.legend-selected { background: var(--green); }
.legend-past { background: #eef0ed; box-shadow: inset 0 0 0 1px #dfe3df; }
.calendar-hint { margin: 0 22px 14px; color: var(--muted); font-size: 11px; }
.calendar-grid { padding: 0 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px 12px; }
.month { min-width: 0; }
.month h3 {
  margin: 0 0 6px;
  padding: 6px 4px;
  border-radius: 6px;
  background: #b9edc9;
  text-align: center;
  font-size: 13px;
  line-height: 1;
}
.weekdays, .days { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { padding: 2px 0 4px; text-align: center; color: var(--muted); font-size: 8px; font-weight: 800; }
.day {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  display: grid;
  place-items: center;
  position: relative;
  border: 1px solid #e1e6e0;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
  cursor: pointer;
}
.day:hover { z-index: 2; border-color: var(--green); }
.day.outside { visibility: hidden; }
.day.non-working { background: var(--orange-soft); color: var(--orange); font-weight: 850; }
.day.special-holiday { box-shadow: inset 0 -3px 0 var(--orange); }
.day.short-day::after { content: "*"; position: absolute; top: 0; right: 2px; color: var(--orange); font-size: 7px; }
.day.past, .day.past:hover {
  border-color: #e5e8e4;
  background: #f0f2ef;
  color: #b5bcb6;
  box-shadow: none;
  font-weight: 600;
  cursor: not-allowed;
  opacity: 1;
}
.day.past::after { color: #c7ccc7; }
.day.selected { z-index: 3; border-color: var(--green-dark); background: var(--green); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); font-weight: 850; }
.day.selected.non-working::after { content: "×2"; position: absolute; right: 1px; bottom: 0; color: #ffd0c7; font-size: 6px; }
.day.selected.quadruple::after { content: "×4"; color: #fff4b8; }

.action-bar {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 14px;
  width: min(920px, calc(100vw - 28px));
  min-height: 74px;
  padding: 10px 11px 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 19px;
  background: linear-gradient(120deg, #4f9228, #32702c);
  color: #fff;
  box-shadow: 0 14px 38px rgba(38,83,31,.3);
}
.action-bar > div:first-child { display: grid; gap: 3px; }
.action-bar strong { font: 500 20px Georgia, serif; }
.action-bar span { color: #bed1c4; font-size: 11px; }
.action-buttons { display: flex; gap: 8px; }
.secondary-button, .download-button { height: 52px; border: 0; border-radius: 13px; font-size: 13px; font-weight: 800; cursor: pointer; }
.secondary-button { padding: 0 17px; background: rgba(255,255,255,.1); color: #dce9e1; }
.secondary-button:hover { background: rgba(255,255,255,.16); }
.download-button { min-width: 178px; padding: 0 21px; background: var(--orange); color: #fff; box-shadow: 0 8px 22px rgba(239,84,60,.3); }
.download-button > span { margin-right: 8px; color: #fff; font-size: 18px; }
.download-button:hover:not(:disabled) { background: var(--orange-dark); }
.download-button:disabled { background: #789177; box-shadow: none; cursor: not-allowed; opacity: .72; }
.download-button.loading { cursor: wait; }
.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 102px;
  padding: 11px 16px;
  transform: translate(-50%, 16px);
  border-radius: 10px;
  background: #21351d;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.receipt-dialog {
  width: min(520px, calc(100vw - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 26px 80px rgba(25, 55, 22, .32);
}
.receipt-dialog::backdrop { background: rgba(25, 45, 22, .58); backdrop-filter: blur(3px); }
.receipt-dialog form { padding: 30px; }
.receipt-icon {
  width: 44px;
  height: 44px;
  margin-bottom: 18px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--mint);
  color: var(--green-dark);
  font-size: 24px;
  font-weight: 850;
}
.receipt-dialog h2 { margin: 0; font: 500 30px/1.1 Georgia, serif; letter-spacing: -.025em; }
.receipt-summary { margin: 16px 0 5px; color: var(--green-dark); font-size: 14px; font-weight: 800; }
.receipt-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.receipt-actions { margin-top: 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.dialog-secondary, .dialog-primary { min-height: 48px; padding: 0 14px; border-radius: 12px; font-size: 13px; font-weight: 800; cursor: pointer; }
.dialog-secondary { border: 1px solid var(--line); background: var(--white); color: var(--muted); }
.dialog-primary { border: 0; background: var(--green); color: #fff; }
.dialog-primary:hover { background: var(--green-dark); }
.dialog-secondary:hover { background: var(--paper); }
.dialog-secondary:disabled, .dialog-primary:disabled { opacity: .6; cursor: wait; }

@media (max-width: 1240px) {
  .workspace { grid-template-columns: minmax(560px, 1fr) 470px; }
  .calendar-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 980px) {
  main { padding-left: 18px; padding-right: 18px; }
  .workspace { grid-template-columns: 1fr; }
  .calendar-card { position: static; order: -1; }
  .calendar-grid { grid-template-columns: repeat(4, 1fr); }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stats > div:nth-child(3) { border-right: 0; }
  .stats > div:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 720px) {
  body { padding-bottom: 126px; }
  .topbar { height: 64px; padding: 0 14px; }
  nav a, nav span { padding: 8px; font-size: 11px; }
  nav a { display: none; }
  main { padding: 14px 12px 28px; }
  .intro { padding: 25px 22px; display: grid; }
  .intro-controls { width: 100%; }
  .intro-controls label { flex: 1; min-width: 0; }
  .norm-chip { min-width: 126px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats > div { min-height: 70px; border-top: 1px solid var(--line); }
  .stats > div:nth-child(1), .stats > div:nth-child(2) { border-top: 0; }
  .stats > div:nth-child(2n) { border-right: 0; }
  .stats > div:nth-child(3) { border-right: 1px solid var(--line); }
  .stats > div:last-child { grid-column: 1 / -1; }
  .calendar-grid { grid-template-columns: repeat(2, 1fr); }
  .calendar-card, .products-card { border-radius: 16px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .search-field { width: 100%; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 680px; }
  th { top: 64px; }
  .action-bar { min-height: 96px; padding: 12px; align-items: stretch; }
  .action-bar > div:first-child { display: none; }
  .action-buttons { width: 100%; }
  .secondary-button { width: 34%; }
  .download-button { min-width: 0; width: 66%; }
  .toast { bottom: 120px; }
  .receipt-dialog form { padding: 24px 20px 20px; }
  .receipt-dialog h2 { font-size: 26px; }
  .receipt-actions { grid-template-columns: 1fr; }
  .dialog-primary { grid-row: 1; }
}
@media (max-width: 430px) {
  .brand { font-size: 16px; }
  .brand-mark { width: 35px; height: 35px; }
  h1 { font-size: 38px; }
  .intro > div:first-child > p:last-child { font-size: 13px; }
  .calendar-grid { gap: 14px 8px; padding: 0 12px; }
  .legend { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
