*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --border: #e5e2dc;
  --border-strong: #ccc9c0;
  --text: #1a1916;
  --text-muted: #6b6860;
  --accent: #8b5e3c;
  --accent-hover: #74502f;
  --accent-light: #f5ede5;
  --success: #2d6a4f;
  --success-bg: #d8f3dc;
  --danger: #9b2226;
  --danger-bg: #ffe3e3;
  --warning: #7f4f24;
  --warning-bg: #fff3cd;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.app-header h1 span {
  color: var(--accent);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Main content ── */
.tab-panel { display: none; padding: 24px 20px; max-width: 960px; margin: 0 auto; }
.tab-panel.active { display: block; }

/* ── Section header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.section-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
  margin-top: -8px;
}

/* ── Buttons ── */
button { font-family: inherit; cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  padding: 5px 8px;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
  padding: 5px 8px;
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 5px 7px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

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

thead th {
  background: var(--bg);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }

.td-actions { width: 80px; text-align: right; }
.td-number { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Forms ── */
.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

input[type="text"],
input[type="number"],
select {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="number"] { text-align: right; }

/* ── Waste settings grid ── */
.waste-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.waste-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.waste-card h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.waste-card h3 .badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--accent-light);
  color: var(--accent);
}

.waste-fields { display: flex; flex-direction: column; gap: 10px; }

/* ── Menu item cards ── */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.menu-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.menu-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.menu-card-header .item-name {
  font-weight: 600;
  font-size: 14px;
}

.menu-card-header .item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
}

.category-badge.espresso { background: #fde9d4; color: #7f4f24; }
.category-badge.filter   { background: #e8f4ea; color: #2d6a4f; }
.category-badge.cold_brew{ background: #dbeafe; color: #1e40af; }

.menu-card-body { padding: 14px; }

.size-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.size-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
}

.size-block-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }

.component-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.component-row select { flex: 2; }
.component-row input  { flex: 1; min-width: 70px; }

/* ── Analysis table ── */
.analysis-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.analysis-controls select { min-width: 160px; max-width: 200px; }

.margin-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.margin-good  { color: var(--success); }
.margin-ok    { color: var(--warning); }
.margin-poor  { color: var(--danger); }

.cogs-breakdown {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Shared cost total ── */
.overhead-total {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--accent-light);
  border-top: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Settings modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 10px;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.modal-field { display: flex; flex-direction: column; gap: 6px; }
.modal-field label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

.sync-row {
  display: flex;
  gap: 10px;
}

.sync-row .btn { flex: 1; justify-content: center; }

.sync-status {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  min-height: 18px;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  transition: transform 0.25s ease;
  white-space: nowrap;
  z-index: 300;
}

#toast.show { transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--success); }
#toast.error   { background: var(--danger); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state .icon { font-size: 32px; margin-bottom: 10px; }

/* ── Inline edit cell ── */
td input[type="text"],
td input[type="number"],
td select {
  border: 1px solid transparent;
  background: transparent;
  padding: 2px 4px;
  border-radius: 3px;
}

td input[type="text"]:focus,
td input[type="number"]:focus,
td select:focus {
  border-color: var(--accent);
  background: var(--surface);
}

/* ── Ingredient form card ── */
.ing-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.type-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  width: fit-content;
  margin-bottom: 14px;
}

.type-btn {
  background: transparent;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.type-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.ing-form-fields {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.cost-preview {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  padding-bottom: 8px;
}

.batch-recipe-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.batch-recipe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.batch-cost-preview {
  margin-top: 8px;
  text-align: right;
}

/* ── Type pills in ingredient table ── */
.type-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.type-purchased { background: var(--accent-light); color: var(--accent); }
.type-house { background: #e8f4ea; color: #2d6a4f; }

/* ── Utility ── */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.gap-8 { display: flex; gap: 8px; }

@media (max-width: 600px) {
  .menu-grid { grid-template-columns: 1fr; }
  .waste-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
}
