:root {
  --bg: #f2e5cc;
  --bg-2: #e7d3ae;
  --panel: #fff9ec;
  --panel-2: #fbf1dc;
  --ink: #302317;
  --muted: #7d6b53;
  --line: #d9c39b;
  --line-strong: #c6aa78;
  --green: #4f7d3a;
  --green-2: #6f9e4f;
  --green-3: #dce8c9;
  --gold: #cf9526;
  --gold-2: #f1c766;
  --gold-3: #f8e9bd;
  --soil: #8a5a3b;
  --red: #b34a3a;
  --red-2: #f3d3ca;
  --blue: #3f6f8f;
  --shadow: 0 2px 0 rgba(80, 50, 20, .08), 0 14px 34px rgba(80, 50, 20, .09);
  --radius: 16px;
  --mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  --sans: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, .45), transparent 28rem),
    radial-gradient(circle at 90% 0%, rgba(255, 244, 209, .7), transparent 24rem),
    repeating-linear-gradient(0deg, rgba(138, 90, 59, .035) 0 1px, transparent 1px 7px),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
a:hover { color: var(--soil); }

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

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 4px 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  font-size: 30px;
  background: linear-gradient(145deg, #fff8e6, #f3d9a2);
  border: 2px solid var(--line-strong);
  border-radius: 18px 18px 18px 6px;
  box-shadow: inset 0 -4px 0 rgba(138, 90, 59, .14), var(--shadow);
  transform: rotate(-2deg);
}

.brand h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
  letter-spacing: -.5px;
  line-height: 1.05;
  text-shadow: 0 1px 0 #fff8e7;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .3px;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.data-badge {
  padding: 7px 11px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  background: rgba(255, 249, 236, .7);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 13px;
  color: var(--ink);
  background: linear-gradient(#fffdf6, #f3e4c8);
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 2px 0 rgba(80, 50, 20, .12);
  font-weight: 700;
  font-size: 13px;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.btn:hover { background: #fffdf6; transform: translateY(-1px); box-shadow: 0 3px 0 rgba(80, 50, 20, .14); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(80, 50, 20, .14); }
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--line-strong); }
.btn-ghost:hover { background: rgba(255, 249, 236, .7); }

.btn-small {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 8px;
}

.btn-green {
  color: #fffdf3;
  background: linear-gradient(var(--green-2), var(--green));
  border-color: #3f662e;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .2);
}
.btn-green:hover { background: linear-gradient(#7cac58, #568741); }

.btn-danger { color: var(--red); border-color: #d8a99d; background: #fff4ef; }
.btn-danger:hover { background: #ffe9e2; }

/* ---------- season tabs ---------- */
.season-tabs {
  display: flex;
  gap: 8px;
  padding: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  background: rgba(255, 249, 236, .6);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.season-tab {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 132px;
  padding: 10px 16px;
  color: var(--muted);
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 10px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: .2px;
  transition: background .15s ease, color .15s ease, transform .12s ease;
}

.season-tab:hover { color: var(--ink); background: rgba(255, 253, 246, .8); }
.season-tab[aria-selected="true"] {
  color: #fffdf3;
  background: linear-gradient(160deg, var(--green-2), var(--green));
  border-color: #3d632d;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12), 0 2px 0 rgba(80, 50, 20, .14);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .18);
}

.season-tab .season-emoji { font-size: 17px; }
.season-tab .count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  background: rgba(0, 0, 0, .13);
}
.season-tab[aria-selected="true"] .count { background: rgba(255, 255, 255, .22); }

/* ---------- summary ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-card {
  position: relative;
  padding: 13px 14px 12px;
  overflow: hidden;
  background: linear-gradient(160deg, #fffdf6, var(--panel-2));
  border: 1.5px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow);
}

.summary-card::after {
  content: "";
  position: absolute;
  right: -18px;
  bottom: -24px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(207, 149, 38, .09);
}

.summary-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .9px;
  text-transform: uppercase;
}

.summary-value {
  display: block;
  font-family: var(--mono);
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 800;
  letter-spacing: -.5px;
  white-space: nowrap;
}

.summary-sub { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.summary-value.positive { color: var(--green); }
.summary-value.negative { color: var(--red); }

/* ---------- panels ---------- */
.panel {
  margin-bottom: 16px;
  padding: 16px;
  background: rgba(255, 249, 236, .92);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -.2px;
}

.panel-sub { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.season-label { color: var(--green); font-size: 13px; font-weight: 700; }

.legend { display: flex; gap: 12px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; }
.dot-green { background: var(--green-2); }
.dot-gold { background: var(--gold); }

.search {
  width: min(240px, 100%);
  min-height: 38px;
  padding: 7px 12px;
  color: var(--ink);
  background: #fffdf7;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
}
.search:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(79, 125, 58, .16); }

/* ---------- crop picker ---------- */
.crop-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 8px;
  max-height: 294px;
  overflow: auto;
  padding: 2px 4px 4px 2px;
}

.crop-card {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 62px;
  padding: 8px 9px;
  text-align: left;
  color: var(--ink);
  background: linear-gradient(160deg, #fffdf7, #f8ecd4);
  border: 1.5px solid var(--line);
  border-radius: 11px;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.crop-card:hover {
  transform: translateY(-2px);
  border-color: var(--green-2);
  box-shadow: 0 5px 14px rgba(80, 50, 20, .12);
}
.crop-card:focus-visible { outline: 3px solid rgba(79, 125, 58, .35); outline-offset: 2px; }

.crop-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 1px rgba(80, 50, 20, .18));
}

.crop-icon.small { width: 30px; height: 30px; }
.crop-icon.tiny { width: 22px; height: 22px; }
.crop-icon-fallback {
  display: grid;
  place-items: center;
  background: var(--green-3);
  border: 1px solid #c2d5a8;
  border-radius: 10px;
  color: #3d632d;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 800;
}

[hidden] { display: none !important; }
.plan-table tbody tr.row-warn td { background: #fff7f4; }

.crop-card-body { min-width: 0; }
.crop-card-name { display: block; overflow: hidden; font-weight: 800; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.crop-card-meta { display: block; color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.crop-card-price { display: block; color: var(--green); font-family: var(--mono); font-size: 10.5px; font-weight: 700; }

/* ---------- tables ---------- */
.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
}

table { width: 100%; border-collapse: separate; border-spacing: 0; }

.plan-table { min-width: 1160px; }

.plan-table th,
.plan-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid rgba(217, 195, 155, .55);
  vertical-align: middle;
  text-align: right;
  white-space: nowrap;
}

.plan-table th:last-child,
.plan-table td:last-child { border-right: 0; }

.plan-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  color: var(--muted);
  background: #f7ead0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}
.plan-table thead tr:nth-child(2) th { top: 33px; }

.plan-table th.group { text-align: center; background: #f2e2c3; }
.plan-table th.col-crop { text-align: left; }
.plan-table th.col-actions { width: 96px; }

.plan-table tbody tr:not(.detail-row):hover td { background: #fffaf0; }
.plan-table tbody tr.detail-row td { background: #f9efdb; }

.plan-table td.col-crop {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 174px;
  text-align: left;
  background: #fffdf7;
  box-shadow: 1px 0 0 var(--line);
}
.plan-table tbody tr:hover td.col-crop { background: #fffaf0; }
.plan-table thead th.col-crop { z-index: 5; background: #f7ead0; }

.crop-cell { display: flex; align-items: center; gap: 8px; }
.crop-cell-text { min-width: 0; }
.crop-cell-name { display: block; font-weight: 800; font-size: 13px; }
.crop-cell-meta { display: flex; gap: 4px; margin-top: 2px; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .2px;
  text-transform: uppercase;
  background: var(--green-3);
  color: #3d632d;
  border: 1px solid #c2d5a8;
}
.badge-gold { background: var(--gold-3); color: #8a5c08; border-color: #e5c77c; }
.badge-blue { background: #dceaf2; color: #2f5b78; border-color: #b4cfe0; }
.badge-red { background: var(--red-2); color: #8d3023; border-color: #e0b4a9; }
.badge-muted { background: #eee5d2; color: var(--muted); border-color: var(--line); }

.num-input {
  width: 62px;
  min-height: 30px;
  padding: 4px 6px;
  color: var(--ink);
  text-align: right;
  background: #fffdf7;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
}
.num-input:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(79, 125, 58, .14); }
.num-input.day { width: 54px; }

.money { font-family: var(--mono); font-size: 12px; font-weight: 700; }
.money.muted { color: var(--muted); font-weight: 400; }
.money.positive { color: var(--green); }
.money.negative { color: var(--red); }

.harvest-count { font-family: var(--mono); font-size: 12px; font-weight: 700; }
.harvest-count.zero { color: var(--red); }

.artisan-select {
  width: 158px;
  min-height: 30px;
  padding: 4px 7px;
  color: var(--ink);
  background: #fffdf7;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  font-size: 11px;
  outline: none;
}
.artisan-select:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(79, 125, 58, .14); }
.artisan-mini { margin-top: 2px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.artisan-mini strong { color: var(--green); font-family: var(--mono); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 7px;
  font-size: 13px;
  line-height: 1;
}
.icon-btn:hover { color: var(--ink); background: #f5e8cf; border-color: var(--line); }
.icon-btn.danger:hover { color: var(--red); background: #fff0ea; border-color: #e0b4a9; }
.icon-btn.expand.open { color: var(--green); background: var(--green-3); border-color: #c2d5a8; }

/* ---------- detail ---------- */
.detail-row td { padding: 0 !important; text-align: left !important; white-space: normal !important; }
.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, .85fr) minmax(420px, 1.15fr);
  gap: 18px;
  padding: 16px 18px 18px;
}
.detail-grid h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.harvest-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.harvest-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 9px;
  background: #fffdf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11.5px;
}
.harvest-list .day { color: var(--muted); font-family: var(--mono); font-size: 10.5px; }
.harvest-list .val { color: var(--green); font-family: var(--mono); font-weight: 700; }
.detail-note { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.seed-override { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.seed-override label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .8px;
  text-transform: uppercase;
}
.seed-override-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.seed-override-row .detail-note { margin: 0; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.mini-table th, .mini-table td { padding: 5px 7px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.mini-table th { color: var(--muted); font-size: 9px; letter-spacing: .5px; text-transform: uppercase; }
.mini-table th:first-child, .mini-table td:first-child { text-align: left; }
.mini-table tr.selected td { background: #eef5e4; }
.mini-table .product-cell { display: flex; align-items: center; gap: 5px; }

/* ---------- weekly ---------- */
.weekly-bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  align-items: end;
  min-height: 150px;
  padding: 14px 12px 8px;
  margin-bottom: 12px;
  background:
    repeating-linear-gradient(0deg, rgba(138, 90, 59, .06) 0 1px, transparent 1px 30px),
    linear-gradient(#fffdf7, #f9eeda);
  border: 1.5px solid var(--line);
  border-radius: 12px;
}
.week-bar { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-track {
  display: flex;
  align-items: flex-end;
  width: min(86px, 100%);
  height: 96px;
  overflow: hidden;
  background: rgba(79, 125, 58, .08);
  border: 1px solid rgba(79, 125, 58, .18);
  border-radius: 8px 8px 4px 4px;
}
.bar-fill {
  width: 100%;
  min-height: 3px;
  background: linear-gradient(180deg, var(--green-2), var(--green));
  border-radius: 6px 6px 2px 2px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .22);
  transition: height .3s ease;
}
.bar-fill.zero { background: var(--line); }
.bar-label { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; }
.bar-value { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--green); }
.bar-sub { color: var(--muted); font-size: 9.5px; }

/* ---------- simple table ---------- */
.simple-table { min-width: 640px; }
.simple-table th,
.simple-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-size: 12px;
}
.simple-table th {
  color: var(--muted);
  background: #f7ead0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}
.simple-table th:first-child,
.simple-table td:first-child { text-align: left; }
.simple-table tbody tr:hover td { background: #fffaf0; }
.simple-table tr.total-row td {
  background: #f2e2c3;
  border-top: 2px solid var(--line-strong);
  font-weight: 800;
  font-family: var(--mono);
  font-size: 11.5px;
}
.simple-table tr.total-row td:first-child { font-family: var(--sans); }

.artisan-table { min-width: 980px; }
.artisan-table .product-cell { display: inline-flex; align-items: center; gap: 6px; }
.artisan-icon { width: 24px; height: 24px; object-fit: contain; image-rendering: pixelated; }
.method-pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eee5d2;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .2px;
  text-transform: uppercase;
}
.summary-grid-small { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 12px; }
.summary-grid-small .summary-card { padding: 11px 12px; }
.summary-grid-small .summary-value { font-size: 19px; }

/* ---------- empty / footer / toast ---------- */
.empty-state {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
  background: #fffdf7;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
}
.empty-state[hidden] { display: none; }
.empty-icon { font-size: 34px; margin-bottom: 6px; }
.empty-state h3 { margin: 0 0 4px; color: var(--ink); font-size: 16px; }
.empty-state p { margin: 0; font-size: 12px; }

.footnote { margin: 10px 2px 0; color: var(--muted); font-size: 10.5px; }

.footer {
  margin-top: 22px;
  padding: 16px 6px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}
.footer p { margin: 3px 0; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  padding: 10px 14px;
  color: #fffdf3;
  background: var(--ink);
  border: 1px solid #1f170f;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  font-size: 12px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app { width: min(100% - 18px, 1460px); padding-top: 12px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .brand-mark { width: 48px; height: 48px; font-size: 25px; }
  .brand h1 { font-size: 23px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-grid-small { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 12px; }
  .panel-head { flex-direction: column; gap: 8px; }
  .search { width: 100%; }
  .crop-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 260px; }
  .crop-card { min-height: 56px; }
  .crop-icon { width: 34px; height: 34px; }
  .season-tab { min-width: 112px; padding: 9px 12px; font-size: 12.5px; }
  .weekly-bars { gap: 6px; padding: 10px 6px 6px; }
  .bar-track { width: 100%; height: 76px; }
  .legend { display: none; }
  .detail-grid { padding: 12px; gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; }
  .topbar-actions, .add-panel, .season-tabs, .icon-btn, .artisan-select, .toast { display: none !important; }
  .panel { break-inside: avoid; box-shadow: none; }
}
