@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: rgba(34,197,94,0.15);
  --sidebar-text: #94a3b8;
  --sidebar-active-text: #22c55e;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --purple: #8b5cf6;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand .brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand-icon {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.brand-name { color: #f8fafc; font-size: 15px; font-weight: 600; letter-spacing: -0.2px; }
.brand-sub { color: var(--sidebar-text); font-size: 10px; letter-spacing: 0.5px; }

.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-section {
  padding: 16px 16px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #475569;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: all 0.15s;
  border-radius: 0;
  margin: 1px 8px;
  border-radius: 8px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-active-text); font-weight: 500; }
.nav-item i { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: 8px;
  text-decoration: none;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}
.user-name { color: #e2e8f0; font-size: 13px; font-weight: 500; }
.user-role { color: var(--sidebar-text); font-size: 11px; }

/* ─── MAIN LAYOUT ─── */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.alert-bell {
  position: relative;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
  text-decoration: none;
}
.alert-bell:hover { background: var(--bg); color: var(--text); }
.alert-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

.page-content { padding: 24px; flex: 1; }

/* ─── CARDS ─── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }

/* ─── STAT CARDS ─── */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; line-height: 1; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.stat-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}
.stat-green { background: rgba(34,197,94,0.1); color: var(--accent-dark); }
.stat-red { background: rgba(239,68,68,0.1); color: var(--danger); }
.stat-blue { background: rgba(59,130,246,0.1); color: var(--info); }
.stat-amber { background: rgba(245,158,11,0.1); color: var(--warning); }
.stat-purple { background: rgba(139,92,246,0.1); color: var(--purple); }

/* ─── TABLES ─── */
.table-wrap { overflow-x: auto; }
table.rtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.rtable th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
table.rtable td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
  vertical-align: middle;
}
table.rtable tr:hover td { background: #f8fafc; }
table.rtable tr:last-child td { border-bottom: none; }
table.rtable td.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; }

/* ─── BADGES ─── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  gap: 4px;
}
.badge-green { background: rgba(34,197,94,0.12); color: #16a34a; }
.badge-red { background: rgba(239,68,68,0.12); color: #dc2626; }
.badge-amber { background: rgba(245,158,11,0.12); color: #b45309; }
.badge-blue { background: rgba(59,130,246,0.12); color: #1d4ed8; }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }
.badge-purple { background: rgba(139,92,246,0.12); color: #7c3aed; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-outline { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; justify-content: center; }

/* ─── FORMS ─── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,0.12); }
.form-control::placeholder { color: #cbd5e1; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; visibility: hidden;
  transition: all 0.2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(10px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-lg { max-width: 760px; }
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: none;
  background: var(--bg);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ─── AUTOCOMPLETE ─── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13.5px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #f1f5f9;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg); }
.autocomplete-item .ac-sub { font-size: 11px; color: var(--text-muted); }

/* ─── SUGGESTION BOX ─── */
.suggestion-box {
  background: rgba(34,197,94,0.06);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #166534;
  display: none;
  margin-top: 8px;
}
.suggestion-box.show { display: block; }
.suggestion-box strong { font-weight: 600; }

/* ─── ALERTS / TOAST ─── */
.flash-msg {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid;
}
.flash-success { background: rgba(34,197,94,0.08); border-color: rgba(34,197,94,0.3); color: #166534; }
.flash-error { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.3); color: #991b1b; }

/* ─── PAGE HEADER ─── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ─── CALCULATOR ─── */
.calc-ingredient-row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.2fr 1fr auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
}
.calc-result {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-radius: 12px;
  padding: 24px;
  color: #f8fafc;
  margin-top: 20px;
}
.calc-result .result-label { font-size: 12px; color: #94a3b8; font-weight: 500; margin-bottom: 4px; }
.calc-result .result-value { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.calc-result .result-suggestion { font-size: 22px; font-weight: 700; color: var(--accent); }

/* ─── INVENTORY ─── */
.inv-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 80px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.inv-item-row:last-child { border-bottom: none; }
.inv-item-row .inv-name { font-weight: 500; }
.inv-item-row .inv-prev { color: var(--text-muted); }
.inv-item-row input { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; }
.inv-item-row input:focus { outline: none; border-color: var(--accent); }
.inv-diff { font-weight: 600; text-align: center; }
.inv-diff.neg { color: var(--danger); }
.inv-diff.pos { color: var(--accent-dark); }

/* ─── CHARTS ─── */
.chart-wrap { position: relative; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-grid.single { grid-template-columns: 1fr; }

/* ─── DRE ─── */
.dre-table { width: 100%; }
.dre-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #f1f5f9; font-size: 13.5px; }
.dre-row:last-child { border-bottom: none; }
.dre-section { background: var(--bg); margin: 0 -20px; padding: 8px 20px; font-size: 11px; font-weight: 700; color: var(--text-muted); letter-spacing: 0.08em; text-transform: uppercase; }
.dre-total { font-weight: 700; font-size: 15px; padding: 14px 0; }
.dre-positive { color: var(--accent-dark); }
.dre-negative { color: var(--danger); }

/* ─── ALERT ITEMS ─── */
.alert-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f1f5f9; }
.alert-item:last-child { border-bottom: none; }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.alert-dot-red { background: var(--danger); }
.alert-dot-amber { background: var(--warning); }
.alert-desc { font-size: 13.5px; font-weight: 500; flex: 1; }
.alert-due { font-size: 12px; color: var(--text-muted); }

/* ─── STOCK LOW ─── */
.stock-low { background: rgba(239,68,68,0.06); border-radius: 8px; padding: 10px 14px; font-size: 13px; }

/* ─── UTILS ─── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--accent-dark); }
.text-red { color: var(--danger); }
.text-amber { color: var(--warning); }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }
.fw-600 { font-weight: 600; }
.mt-4 { margin-top: 4px; }
.mb-4 { margin-bottom: 4px; }
.mt-8 { margin-top: 8px; }
.mb-8 { margin-bottom: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mt-24 { margin-top: 24px; }
.mb-24 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.search-bar { position: relative; }
.search-bar i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 14px; }
.search-bar input { padding-left: 34px; }

/* ─── LOGIN PAGE ─── */
.login-page {
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .brand-icon { margin: 0 auto 12px; width: 48px; height: 48px; font-size: 24px; }
.login-logo h1 { font-size: 20px; font-weight: 700; }
.login-logo p { color: var(--text-muted); font-size: 13px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

/* ─── PRINT ─── */
@media print {
  .sidebar, .topbar, .btn, .modal-overlay { display: none !important; }
  .main-wrap { margin-left: 0; }
  .page-content { padding: 0; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-wrap { margin-left: 0; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .calc-ingredient-row { grid-template-columns: 1fr 1fr; }
  .inv-item-row { grid-template-columns: 1fr 1fr; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
}
