:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --sidebar: #2f2a24;
  --sidebar-active: #c98a4b;
  --text: #2b2722;
  --muted: #7d746a;
  --border: #e7dfd4;
  --primary: #8a5a33;
  --primary-hover: #6f4626;
  --danger: #b3382f;
  --danger-bg: #fdecea;
  --success: #3d7d4f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(47, 42, 36, 0.12);
}

* { 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);
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar);
  color: #f0e9df;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar .brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 4px 12px 16px;
  color: #fff;
}

.sidebar .brand span { color: var(--sidebar-active); }

.sidebar a {
  color: #d8cfc1;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  display: block;
}

.sidebar a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.sidebar a.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.sidebar .group-label {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
  color: #9a9082;
  padding: 16px 12px 4px;
}

.sidebar-account {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar .sidebar-account .btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
  color: #d8cfc1;
  justify-content: center;
}

.sidebar .sidebar-account .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.sidebar .sidebar-account .btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sidebar-user {
  font-size: 13px;
  color: #d8cfc1;
  padding: 0 2px;
  overflow-wrap: anywhere;
}

.sidebar-error {
  margin: 0;
  font-size: 12px;
  color: #f2b8b5;
  display: none;
}

.sidebar-error:empty { display: none; }

.sidebar-error:not(:empty) { display: block; }

/* Main area */
.main { padding: 28px 36px; max-width: 1100px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

/* Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stat-card .label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.search-group { width: min(100%, 520px); }

.search-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 600;
}

.toolbar .search { width: 100%; }

.search-help,
.search-results {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.search-results { min-height: 15px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  padding: 6px 10px;
}

.btn-danger:hover { background: var(--danger-bg); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Forms */
.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

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

tr:last-child td { border-bottom: none; }

tbody tr:hover { background: #fbf8f3; }

td.num, th.num { text-align: right; }

.muted { color: var(--muted); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 12px;
  font-size: 15px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-low { background: var(--danger-bg); color: var(--danger); }
.badge-ok { background: #e8f4ec; color: var(--success); }
.badge-neut { background: #f1ece4; color: var(--muted); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 26, 22, 0.45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  z-index: 50;
  overflow-y: auto;
}

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

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.modal h2 { margin: 0 0 18px; font-size: 19px; }

.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Ingredient rows (products) */
.ingredient-row {
  display: grid;
  grid-template-columns: 1fr 120px 120px 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.ingredient-formula { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.cost-output {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.cost-output strong {
  font-size: 16px;
  color: var(--primary);
}

/* Flash / toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #33302b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  z-index: 100;
}

.toast.show { opacity: 1; transform: none; }

.toast.error { background: var(--danger); }

.tag {
  display: inline-block;
  background: #f1ece4;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 12px;
  color: var(--muted);
  margin: 2px 2px 0 0;
}

/* Auth pages */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card .brand-block { text-align: center; margin-bottom: 18px; }

.auth-card h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.auth-card h1 span { color: var(--sidebar-active); }

.auth-tagline {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 20px;
}

.auth-tab {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--primary);
  color: #fff;
}

.auth-tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.form-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.form-error[hidden] { display: none; }

.field-hint {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.btn-block { width: 100%; justify-content: center; }

.btn-block:disabled { opacity: 0.6; cursor: not-allowed; }

.account-panel { max-width: 620px; }

@media (max-width: 480px) {
  .auth-card { padding: 20px; }
}
