:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --border: #e0e4e2;
  --text: #1b2420;
  --text-muted: #6b756f;
  --primary: #2f7a4f;
  --primary-dark: #22603c;
  --primary-tint: #e6f2ea;
  --danger: #c0392b;
  --danger-tint: #fbe9e7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 25, 0.08), 0 1px 2px rgba(20, 30, 25, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --surface: #1c2124;
    --border: #2c3336;
    --text: #eaf0ec;
    --text-muted: #98a29c;
    --primary: #4caf7d;
    --primary-dark: #3d8f65;
    --primary-tint: #1c2b23;
    --danger: #e57368;
    --danger-tint: #2c1e1c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.brand h1 { font-size: 18px; margin: 0; }
.subtitle { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

.month-nav { display: flex; align-items: center; gap: 8px; }
.month-label { font-weight: 600; min-width: 150px; text-align: center; }

button { font-family: inherit; cursor: pointer; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  width: 32px; height: 32px;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }

.ghost-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
}
.ghost-btn:hover { background: var(--bg); }
.ghost-btn.small { padding: 5px 10px; font-size: 12px; }

.primary-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
}
.primary-btn:hover { background: var(--primary-dark); }

.danger-btn {
  border: 1px solid var(--danger);
  background: var(--danger-tint);
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
}

.weeks-container {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.week-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.week-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--primary-tint);
}
.week-header h2 { font-size: 15px; margin: 0; }
.week-header .week-range { font-size: 12px; color: var(--text-muted); }
.week-header .week-count { margin-left: auto; font-size: 12px; color: var(--text-muted); }

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

table.runs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 900px;
}

table.runs-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.runs-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}

table.runs-table tbody tr:hover { background: var(--bg); cursor: pointer; }
table.runs-table tbody tr:last-child td { border-bottom: none; }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-planned { background: #eceff1; color: #546e7a; }
.status-fermenting { background: #fff3cd; color: #8a6d1a; }
.status-harvested { background: #dcefff; color: #1b5faa; }
.status-freezedrying { background: #e3dcff; color: #5b3fb0; }
.status-freezedrycomplete { background: #d6f0e6; color: #1c6b4a; }
.status-labtesting { background: #ffe3d6; color: #b5501f; }
.status-resultsin { background: #d9f0ff; color: #1a6fa3; }
.status-shipped { background: var(--primary-tint); color: var(--primary-dark); }

@media (prefers-color-scheme: dark) {
  .status-planned { background: #2a2f31; color: #b7c0ba; }
  .status-fermenting { background: #3a331a; color: #e0c268; }
  .status-harvested { background: #1a2c3d; color: #7db3e8; }
  .status-freezedrying { background: #2b2440; color: #b39ff0; }
  .status-freezedrycomplete { background: #17332a; color: #6fd3a5; }
  .status-labtesting { background: #3a2618; color: #ef9c6d; }
  .status-resultsin { background: #17303d; color: #77c4ee; }
  .status-shipped { background: var(--primary-tint); color: #7fe0ac; }
}

.empty-state {
  max-width: 1400px;
  margin: 40px auto;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.hidden { display: none !important; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 12, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 17px; }

form { padding: 6px 22px 22px; }

fieldset {
  border: none;
  border-top: 1px solid var(--border);
  padding: 16px 0;
  margin: 0;
}
fieldset:first-of-type { border-top: none; }

legend {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  padding: 0;
  margin-bottom: 10px;
}

.grid {
  display: grid;
  gap: 14px;
}
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-day { grid-template-columns: repeat(3, 1fr); gap: 20px; }
.span-2 { grid-column: span 2; }

@media (max-width: 720px) {
  .grid-3, .grid-day { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

input, textarea, select {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.day-col { display: flex; flex-direction: column; gap: 10px; }
.day-col h4 { margin: 0 0 2px; font-size: 12px; color: var(--text); }

.ingredient-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.ingredient-row {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.ingredient-row input { width: 100%; }
.remove-ingredient {
  border: none;
  background: var(--danger-tint);
  color: var(--danger);
  border-radius: 7px;
  width: 32px;
  height: 32px;
  font-size: 15px;
}

textarea { width: 100%; resize: vertical; }

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.spacer { flex: 1; }

.detail-row td {
  background: var(--bg);
  white-space: normal;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 14px 4px;
}
.detail-item .k {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.detail-item .v { font-size: 13px; }
.detail-actions { display: flex; gap: 8px; padding: 6px 4px 12px; }
