:root {
  --bg: #111010;
  --surface: #1c1b1b;
  --surface2: #252424;
  --border: #333;
  --accent: #f5a623;
  --accent-dark: #c4831a;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --text: #f0ece4;
  --muted: #888;
  --font: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
  --display: 'Bebas Neue', sans-serif;
  --radius: 8px;
  --sidebar: 200px;
  --bottom-nav-h: 60px;
}

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

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar (desktop) ─────────────────────────────── */
#sidebar {
  width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-name { font-family: var(--display); font-size: 22px; color: var(--accent); letter-spacing: 1px; }
.brand-logo { font-size: 20px; }

.nav-links { list-style: none; padding: 12px 8px; flex: 1; }
.nav-links li { margin-bottom: 2px; }
.nav-links a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-links a:hover { background: var(--surface2); color: var(--text); }
.nav-links a.active { background: var(--accent); color: #111; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

/* ── Bottom nav (mobile only) ──────────────────────── */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  /* iOS safe area */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  gap: 2px;
  transition: color 0.15s;
  min-height: var(--bottom-nav-h);
}
#bottom-nav a.active { color: var(--accent); }
#bottom-nav a:hover { color: var(--text); }
.bnav-icon { font-size: 22px; line-height: 1; }

/* ── Main content ──────────────────────────────────── */
#main { flex: 1; overflow-y: auto; background: var(--bg); }
.page { display: none; padding: 24px; max-width: 1100px; }
.page.active { display: block; }

/* ── Page header ───────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-family: var(--display); font-size: 28px; color: var(--text); letter-spacing: 0.5px; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}
.btn-primary { background: var(--accent); color: #111; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: #111; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 6px 10px; }

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* ── Stat row ──────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-family: var(--display); font-size: 28px; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Table ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; border-bottom: 1px solid var(--border); font-weight: 500; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ── Badges ────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--mono);
}
.badge-green { background: rgba(74,222,128,0.15); color: var(--green); }
.badge-red { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-yellow { background: rgba(251,191,36,0.15); color: var(--yellow); }
.badge-gray { background: var(--surface2); color: var(--muted); }
.badge-accent { background: rgba(245,166,35,0.2); color: var(--accent); }

/* ── Forms ─────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select option { background: var(--surface2); }
textarea { resize: vertical; min-height: 80px; }

/* ── Search bar ────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input { flex: 1; }

/* ── Recipe ingredient row ─────────────────────────── */
.recipe-ing-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.recipe-ing-row input, .recipe-ing-row select { margin: 0; }

/* ── Camera scanner ────────────────────────────────── */
#scanner-container {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--accent);
}
/* html5-qrcode injects its own video element; style it */
#barcode-scanner video { width: 100% !important; border-radius: 0; }
#barcode-scanner { border-radius: var(--radius); overflow: hidden; }

/* ── Modal ─────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
#modal-overlay.hidden { display: none; }
#modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
#modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
#modal-title { font-family: var(--display); font-size: 20px; }
#modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
#modal-close:hover { background: var(--surface2); color: var(--text); }
#modal-body { padding: 20px; }

/* ── Toast ─────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  min-width: 200px;
  animation: toast-in 0.2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Stock bar ─────────────────────────────────────── */
.stock-bar { width: 80px; height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.stock-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* ── Section title ─────────────────────────────────── */
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }

/* ── Empty state ───────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ── Cost % coloring ───────────────────────────────── */
.cost-good { color: var(--green); }
.cost-warn { color: var(--yellow); }
.cost-bad { color: var(--red); }

/* ── Receive page layout ───────────────────────────── */
.receive-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── Mobile ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Hide sidebar, show bottom nav */
  #sidebar { display: none; }
  #bottom-nav { display: flex; }

  /* Push content above bottom nav */
  #main {
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }

  /* Toasts sit above bottom nav */
  #toast-container {
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
    right: 12px;
    left: 12px;
  }
  .toast { min-width: unset; width: 100%; }

  /* Page padding */
  .page { padding: 16px; }
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 24px; }

  /* Modal full-width on mobile */
  #modal-overlay { padding: 0; align-items: flex-end; }
  #modal-box {
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    border-bottom: none;
  }

  /* Stacked forms */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .receive-layout { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }

  /* Prevent iOS input zoom (requires font-size >= 16px) */
  input, select, textarea { font-size: 16px; }

  /* Larger tap targets */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }

  /* Recipe ingredient rows stack better */
  .recipe-ing-row { flex-wrap: wrap; }
  .recipe-ing-row select:first-child { flex: 1 1 100%; }

  /* Hide lower-priority table columns on small screens */
  .col-hide-mobile { display: none; }
}
