:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --surface-2: #fbf8f4;
  --surface-hover: #f3ece4;
  --border: #e6dcd1;
  --border-strong: #d4c4b2;
  --text: #251912;
  --text-muted: #6f5d51;
  --brand: #5c331e;
  --brand-dark: #3e2315;
  --brand-light: #8a5538;
  --brand-soft: #f5ebe2;
  --accent: #c97a2b;
  --good: #16794c;
  --good-bg: #e7f6ee;
  --warn: #b4690e;
  --warn-bg: #fef3dc;
  --danger: #c4322b;
  --danger-bg: #fdeae8;
  --info: #1d5fa7;
  --info-bg: #e8f1fb;
  --shadow-sm: 0 1px 2px rgba(45, 25, 14, 0.06);
  --shadow: 0 6px 20px rgba(45, 25, 14, 0.08);
  --shadow-lg: 0 18px 44px rgba(32, 16, 8, 0.18);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: #15110e;
  --surface: #1f1915;
  --surface-2: #27201b;
  --surface-hover: #302721;
  --border: #3a2f28;
  --border-strong: #4e3f35;
  --text: #f3ece4;
  --text-muted: #b19f91;
  --brand: #d4945c;
  --brand-dark: #2b1a10;
  --brand-light: #e5ad77;
  --brand-soft: rgba(212, 148, 92, 0.14);
  --accent: #e5a04d;
  --good: #4ade80;
  --good-bg: rgba(34, 197, 94, 0.15);
  --warn: #fbbf24;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --danger: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.16);
  --info: #60a5fa;
  --info-bg: rgba(59, 130, 246, 0.16);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.65);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==================== LOGIN PAGE ==================== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at top right, rgba(201, 122, 43, 0.16), transparent 48%),
              radial-gradient(circle at bottom left, rgba(92, 51, 30, 0.16), transparent 52%),
              var(--bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px 28px;
  position: relative;
}
.login-brand {
  text-align: center;
  margin-bottom: 24px;
}
.login-brand img {
  height: 76px;
  width: auto;
  object-fit: contain;
  margin-bottom: 10px;
}
.login-brand h1 {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
}
.login-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}
.login-theme-btn {
  position: absolute;
  top: 16px;
  right: 16px;
}

/* ==================== LAYOUT SHELL ==================== */
.topbar {
  background: linear-gradient(135deg, #3e2315 0%, #5c331e 55%, #7c4a2e 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 3px 14px rgba(34, 17, 8, 0.22);
}
.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  height: 44px;
  width: auto;
  object-fit: contain;
}
.brand-title {
  font-weight: 800;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.waste-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.24);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #fff;
}
.waste-pill strong { color: #ffe08a; }
.waste-pill button {
  background: rgba(255, 255, 255, 0.18);
  border: 0;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  cursor: pointer;
}
.waste-pill button:hover { background: rgba(255, 255, 255, 0.3); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12.5px;
}
.role-tag {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 224, 138, 0.22);
  color: #ffe08a;
}

/* ==================== NAV TABS ==================== */
.nav-wrap {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 64px;
  z-index: 30;
}
.nav-tabs {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 18px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 12px 15px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .15s, border-color .15s, background .15s;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.nav-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
}

/* ==================== MAIN CONTAINER ==================== */
.main {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 18px 56px;
}

/* ==================== KPI GRID ==================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
@media (max-width: 960px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .kpi-grid { grid-template-columns: 1fr; } }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}
.kpi-card.clickable { cursor: pointer; transition: transform .12s, border-color .15s; }
.kpi-card.clickable:hover { transform: translateY(-1px); border-color: var(--brand); }
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.kpi-value {
  font-size: 24px;
  font-weight: 800;
  margin: 4px 0 2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==================== CARDS & TOOLBAR ==================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
}
.card-body { padding: 16px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==================== INPUTS & BUTTONS ==================== */
.input, .select, .textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.input-sm { padding: 5px 8px; font-size: 13px; }
.input-num { text-align: right; font-variant-numeric: tabular-nums; }
.search-input { min-width: 220px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-light); border-color: var(--brand-light); }
[data-theme="dark"] .btn-primary { color: #1b120c; }
.btn-danger {
  background: var(--danger-bg);
  border-color: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: inherit;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }
.btn-soft {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand);
}
.btn-soft:hover { filter: brightness(0.95); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-xs { padding: 3px 7px; font-size: 11.5px; }

.seg-group {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.seg-btn {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}

/* ==================== TABLES ==================== */
.table-wrap {
  overflow-x: auto;
  width: 100%;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.center { text-align: center; }

.inline-price-input {
  width: 98px;
  text-align: right;
  padding: 4px 7px;
  border: 1px solid transparent;
  background: var(--surface-2);
  border-radius: 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.inline-price-input:hover { border-color: var(--border-strong); }
.inline-price-input:focus {
  border-color: var(--brand);
  background: var(--surface);
  outline: none;
}

/* ==================== BADGES & PILLS ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-high { background: var(--danger-bg); color: var(--danger); }
.badge-pending { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.ing-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 420px;
}
.ing-tag {
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.ing-tag b { color: var(--text); font-weight: 600; }

/* ==================== RECIPE CARDS VIEW ==================== */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}
.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}
.recipe-card-head {
  padding: 13px 15px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.recipe-card-title { font-weight: 800; font-size: 15px; margin: 0 0 3px; }
.recipe-card-body { padding: 12px 15px; flex: 1; }
.recipe-mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.recipe-mini-table td { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.recipe-mini-table tr:last-child td { border-bottom: 0; }
.recipe-card-foot {
  padding: 11px 15px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==================== ANALYTICS BARS ==================== */
.bar-row {
  display: grid;
  grid-template-columns: 180px 1fr 115px;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
}
@media (max-width: 640px) {
  .bar-row { grid-template-columns: 120px 1fr 85px; font-size: 12.5px; }
}
.bar-track {
  height: 18px;
  background: var(--surface-2);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .25s ease;
}
.bar-fill.good { background: var(--good); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.high { background: var(--danger); }
.bar-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--text-muted);
  opacity: 0.45;
}

/* ==================== MODAL ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 10, 5, 0.56);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 780px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.modal-sm { max-width: 480px; }
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h3 { margin: 0; font-size: 16.5px; font-weight: 800; }
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-foot {
  padding: 13px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field-full { grid-column: 1 / -1; }

.live-summary-box {
  background: var(--brand-soft);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}
@media (max-width: 640px) { .live-summary-box { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.live-stat-lbl { font-size: 11px; text-transform: uppercase; font-weight: 700; color: var(--text-muted); }
.live-stat-val { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }

.suggest-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.item-editor-row {
  display: grid;
  grid-template-columns: 1fr 100px 100px 64px 34px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
@media (max-width: 640px) {
  .item-editor-row { grid-template-columns: 1fr 78px 80px 34px; }
  .item-editor-row .hide-sm { display: none; }
}

/* ==================== TOAST & ALERTS ==================== */
.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}
.toast {
  background: #251912;
  color: #fff;
  padding: 11px 15px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 600;
  border-left: 4px solid var(--accent);
}
.toast.ok { border-left-color: #22c55e; }
.toast.err { border-left-color: #ef4444; }

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-err { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(196, 50, 43, 0.25); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(29, 95, 167, 0.22); }
.alert-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid rgba(180, 105, 14, 0.25); }

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.fw-700 { font-weight: 700; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-0 { margin-bottom: 0; }
.flex-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
}

@media print {
  .topbar, .nav-wrap, .toolbar, .btn, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
