/* ===========================================================================
   SmartDine — Design System
   Mobile-first, app-like, PWA-ready. ~400 lines covering everything.
   =========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --brand: #FF4D00;
  --brand-dark: #E04400;
  --brand-light: #FFE5D6;
  --ink: #0F1115;
  --ink-2: #2A2D33;
  --ink-3: #5A5F69;
  --muted: #8B919C;
  --line: #E6E8EC;
  --line-2: #F1F2F4;
  --bg: #FFFFFF;
  --bg-2: #FAFAFB;
  --bg-3: #F4F5F7;
  --success: #16A34A;
  --warning: #F59E0B;
  --danger: #DC2626;
  --info: #2563EB;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 17, 21, 0.06), 0 1px 1px rgba(15, 17, 21, 0.04);
  --shadow: 0 4px 16px rgba(15, 17, 21, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 17, 21, 0.14);
  --t-fast: 120ms ease;
  --t: 180ms ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

img, video { max-width: 100%; height: auto; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); }
h1 { font-size: clamp(28px, 6vw, 44px); letter-spacing: -0.02em; }
h2 { font-size: clamp(22px, 4vw, 32px); }
h3 { font-size: 18px; }
h4 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.container-sm { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.section { padding: 32px 0; }
.section-lg { padding: 64px 0; }
.row { display: flex; flex-wrap: wrap; gap: 16px; }
.col { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.cluster { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.center { display: flex; align-items: center; justify-content: center; }
.spacer { flex: 1; }
.hide-mobile { display: none; }
@media (min-width: 768px) {
  .hide-desktop { display: none !important; }
  .hide-mobile { display: initial; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--radius-pill);
  font-weight: 600; font-size: 15px;
  background: var(--ink); color: #fff;
  transition: transform var(--t-fast), background var(--t), box-shadow var(--t);
  white-space: nowrap; user-select: none;
  min-height: 44px; /* tap target */
}
.btn:hover { background: var(--ink-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost:hover { background: var(--bg-3); }
.btn-soft { background: var(--brand-light); color: var(--brand-dark); }
.btn-soft:hover { background: #ffd6bd; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }
.btn-lg { padding: 16px 28px; font-size: 16px; min-height: 52px; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  transition: box-shadow var(--t), transform var(--t);
}
.card-hover:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.card-flat { border: 0; background: var(--bg-3); }
.card-tight { padding: 14px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 15px;
  color: var(--ink);
  transition: border-color var(--t), box-shadow var(--t);
  min-height: 44px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255, 77, 0, 0.12);
}
.textarea { min-height: 100px; resize: vertical; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.field-help { color: var(--muted); font-size: 12px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--line); border-radius: 999px;
  transition: var(--t);
}
.switch-slider::before {
  position: absolute; content: ''; height: 20px; width: 20px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: var(--t); box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.switch input:checked + .switch-slider { background: var(--brand); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

/* ---------- Badges & pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge-success { background: #DCFCE7; color: #166534; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger  { background: #FEE2E2; color: #991B1B; }
.badge-info    { background: #DBEAFE; color: #1E40AF; }
.badge-muted   { background: var(--bg-3); color: var(--ink-3); }
.badge-brand   { background: var(--brand-light); color: var(--brand-dark); }

/* ---------- Navbar ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.95);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; color: var(--ink); letter-spacing: -0.02em; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.nav-links { display: none; gap: 28px; }
.nav-links a { color: var(--ink-2); font-weight: 500; }
.nav-links a:hover { color: var(--brand); }
@media (min-width: 768px) { .nav-links { display: flex; } }

/* ---------- Hero ---------- */
.hero {
  padding: 60px 0 80px;
  background: linear-gradient(180deg, #FFF7F1 0%, #FFFFFF 100%);
  text-align: center;
}
.hero h1 { margin-bottom: 16px; }
.hero p { font-size: 18px; color: var(--ink-3); max-width: 580px; margin: 0 auto 28px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- Stats / Features ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (min-width: 768px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { padding: 24px; background: var(--bg-3); border-radius: var(--radius); text-align: center; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--brand); }
.stat-label { color: var(--muted); font-size: 13px; }

.features-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .features-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .features-grid { grid-template-columns: repeat(3, 1fr); } }
.feature-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--brand-light); color: var(--brand-dark);
  display: grid; place-items: center; margin-bottom: 12px;
}

/* ---------- Restaurant page ---------- */
.cover {
  position: relative;
  height: 200px;
  background: linear-gradient(135deg, var(--brand) 0%, #ff7a3d 100%);
  background-size: cover; background-position: center;
}
.cover::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.5) 100%);
}
.cover-content {
  position: absolute; bottom: 16px; left: 16px; right: 16px;
  color: #fff; z-index: 1;
}
.cover-content h1 { color: #fff; font-size: 24px; }

.cat-nav {
  position: sticky; top: 60px; z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 16px;
}
.cat-nav::-webkit-scrollbar { display: none; }
.cat-nav-inner { display: flex; gap: 4px; padding: 12px 0; }
.cat-chip {
  padding: 8px 16px; border-radius: var(--radius-pill);
  background: var(--bg-3); color: var(--ink-2);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background var(--t), color var(--t);
  border: 0; cursor: pointer;
}
.cat-chip.active { background: var(--ink); color: #fff; }

.menu-list { display: flex; flex-direction: column; gap: 12px; padding: 16px 0 100px; }
.menu-item {
  display: flex; gap: 14px; padding: 14px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color var(--t), transform var(--t);
}
.menu-item:active { transform: scale(0.98); }
.menu-item:hover { border-color: var(--brand); }
.menu-item-img {
  width: 88px; height: 88px; border-radius: var(--radius-sm);
  background: var(--bg-3); flex-shrink: 0;
  background-size: cover; background-position: center;
}
.menu-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.menu-item-name { font-weight: 600; font-size: 15px; }
.menu-item-desc { color: var(--muted); font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.menu-item-price { font-weight: 700; color: var(--brand); margin-top: 4px; }
.menu-item-add {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink); color: #fff; display: grid; place-items: center;
  font-size: 18px; font-weight: 600; align-self: flex-end;
  transition: background var(--t), transform var(--t);
}
.menu-item-add:hover { background: var(--brand); }
.menu-item-add:active { transform: scale(0.85); }
.menu-item.unavailable { opacity: 0.5; pointer-events: none; }

/* ---------- Cart drawer + FAB ---------- */
.cart-fab {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 16px; right: 16px;
  background: var(--ink); color: #fff;
  border-radius: var(--radius-pill);
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  transform: translateY(120%);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
  font-weight: 600;
}
.cart-fab.show { transform: translateY(0); }
.cart-fab-count {
  background: var(--brand); padding: 2px 10px;
  border-radius: var(--radius-pill); font-size: 13px;
}

.drawer {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 17, 21, 0.5);
  display: none;
  align-items: flex-end;
}
.drawer.show { display: flex; }
.drawer-panel {
  width: 100%; max-height: 90vh;
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex; flex-direction: column;
  animation: slideUp 280ms cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: var(--safe-bottom);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.drawer-handle {
  width: 36px; height: 4px; background: var(--line);
  border-radius: 2px; margin: 10px auto;
}
.drawer-header { padding: 8px 20px 16px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-footer { padding: 16px 20px; border-top: 1px solid var(--line); }

@media (min-width: 768px) {
  .drawer { align-items: center; justify-content: flex-end; }
  .drawer-panel { max-width: 420px; height: 100%; max-height: 100%; border-radius: 0; animation: slideRight 280ms cubic-bezier(0.32, 0.72, 0, 1); }
  @keyframes slideRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
  .drawer-handle { display: none; }
}

.cart-line { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.qty { display: inline-flex; align-items: center; gap: 8px; background: var(--bg-3); border-radius: var(--radius-pill); padding: 4px; }
.qty button { width: 28px; height: 28px; border-radius: 50%; background: var(--bg); }
.qty span { min-width: 20px; text-align: center; font-weight: 600; }

/* ---------- Order status steps ---------- */
.steps { display: flex; gap: 4px; padding: 16px 0; }
.step { flex: 1; height: 4px; background: var(--line); border-radius: 2px; transition: background var(--t); }
.step.done { background: var(--brand); }
.step.current { background: var(--brand); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ---------- Sidebar layout (admin & restaurant) ---------- */
.app-shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; min-height: 100dvh; background: var(--bg-2); }
@media (min-width: 1024px) { .app-shell { grid-template-columns: 240px 1fr; } }
.sidebar {
  background: var(--ink); color: rgba(255,255,255,0.8);
  padding: 20px 12px; display: none; flex-direction: column; gap: 4px;
}
@media (min-width: 1024px) { .sidebar { display: flex; } }
.sidebar .brand { color: #fff; padding: 8px 12px 20px; }
.sidebar a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.7); font-size: 14px; font-weight: 500;
  transition: background var(--t), color var(--t);
}
.sidebar a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar a.active { background: var(--brand); color: #fff; }
.app-main { padding: 16px; }
@media (min-width: 768px) { .app-main { padding: 24px; } }

/* Mobile bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg); border-top: 1px solid var(--line);
  display: flex; padding-bottom: var(--safe-bottom);
  z-index: 40;
}
@media (min-width: 1024px) { .bottom-nav { display: none; } }
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0; color: var(--muted); font-size: 11px; font-weight: 500;
}
.bottom-nav a.active { color: var(--brand); }
.bottom-nav .icon { font-size: 20px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); }

/* ---------- Stat cards (dashboards) ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { padding: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value { font-size: 26px; font-weight: 800; margin-top: 4px; }

/* ---------- Toast & popup ---------- */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  z-index: 200; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t), transform var(--t);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-8px); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Admin popup notification */
.popup-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(15, 17, 21, 0.6);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.popup-overlay.show { display: flex; animation: fadeIn 200ms ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.popup {
  width: 100%; max-width: 420px;
  background: var(--bg); border-radius: var(--radius-lg);
  padding: 24px; text-align: center;
  animation: popIn 280ms cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.popup-icon {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto 12px;
  font-size: 28px;
}
.popup-icon.info { background: #DBEAFE; color: var(--info); }
.popup-icon.warning { background: #FEF3C7; color: var(--warning); }
.popup-icon.urgent { background: #FEE2E2; color: var(--danger); }
.popup-icon.promo { background: var(--brand-light); color: var(--brand-dark); }
.popup h3 { margin-bottom: 8px; }
.popup p { color: var(--ink-3); margin-bottom: 20px; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; padding: 24px 16px; background: var(--bg-2); }
.auth-card { width: 100%; max-width: 420px; margin: 0 auto; padding: 32px 24px; background: var(--bg); border-radius: var(--radius-lg); border: 1px solid var(--line); }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin-bottom: 24px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.btn-google {
  width: 100%; background: #fff; color: var(--ink);
  border: 1.5px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-google:hover { background: var(--bg-3); }
.role-toggle { display: flex; gap: 0; padding: 4px; background: var(--bg-3); border-radius: var(--radius-pill); margin-bottom: 20px; }
.role-toggle button { flex: 1; padding: 10px; border-radius: var(--radius-pill); font-weight: 600; font-size: 13px; color: var(--ink-3); }
.role-toggle button.active { background: var(--bg); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Empty state ---------- */
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }

/* ---------- Loading spinner ---------- */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; } .mt-4 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; } .gap-3 { gap: 24px; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.no-scroll { overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
