/* ============================================================
   BASE.CSS — Config-driven CSS variable theming system
   QR Café Ordering System — White-Label Template
   ============================================================ */

/* ── 1. Design tokens (overridden per client via config.js) ── */
:root {
  /* Brand colours — set dynamically from config.json */
  --primary:        #c47f2e;   /* main CTA, buttons, highlights  */
  --primary-dark:   #a3681f;   /* hover / pressed state          */
  --primary-light:  #f0c87a;   /* tints, tags, backgrounds       */
  --accent:         #e8a84a;   /* secondary highlight, badges    */

  /* Surfaces */
  --bg:             #faf8f5;   /* page background                */
  --surface:        #ffffff;   /* cards, panels, modals          */
  --surface-2:      #f3ede4;   /* slightly elevated surface      */
  --overlay:        rgba(0, 0, 0, 0.45); /* modal backdrops     */

  /* Typography */
  --text:           #1a1612;   /* primary body text              */
  --text-secondary: #6b5e50;   /* sub-labels, timestamps         */
  --muted:          #b0a090;   /* placeholder, disabled text     */

  /* Borders */
  --border:         #e4dbd0;   /* default border colour          */
  --border-strong:  #c8bdb0;   /* emphasis borders               */

  /* Semantic status colours */
  --status-new:       #3b82f6; /* blue  — new orders             */
  --status-cooking:   #f59e0b; /* amber — cooking                */
  --status-ready:     #10b981; /* green — ready to serve         */
  --status-delivered: #6b7280; /* grey  — delivered              */
  --status-cancelled: #ef4444; /* red   — cancelled              */

  /* Timer urgency */
  --timer-warn:  #f59e0b;  /* > 5 min                           */
  --timer-alert: #ef4444;  /* > 10 min                          */

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Border radii */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', var(--font-sans);

  --text-xs:   0.75rem;   /* 12px */
  --text-sm:   0.875rem;  /* 14px */
  --text-base: 1rem;      /* 16px */
  --text-lg:   1.125rem;  /* 18px */
  --text-xl:   1.25rem;   /* 20px */
  --text-2xl:  1.5rem;    /* 24px */
  --text-3xl:  1.875rem;  /* 30px */

  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.09), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 30px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.07);
  --shadow-xl:  0 20px 48px rgba(0,0,0,0.16), 0 8px 16px rgba(0,0,0,0.08);

  /* Transitions */
  --transition-fast:   0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow:   0.4s ease;

  /* Z-index scale */
  --z-base:    1;
  --z-sticky:  100;
  --z-overlay: 200;
  --z-modal:   300;
  --z-toast:   400;
}

/* ── 2. Reset & base styles ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover { color: var(--primary-dark); }

ul, ol { list-style: none; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

/* ── 3. Utility classes ── */

/* Layout */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: var(--space-1); }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.grid        { display: grid; }
.hidden      { display: none !important; }
.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;
}

/* Spacing */
.p-2  { padding: var(--space-2); }
.p-4  { padding: var(--space-4); }
.p-6  { padding: var(--space-6); }
.px-4 { padding-inline: var(--space-4); }
.py-2 { padding-block: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }

/* Typography */
.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-2xl  { font-size: var(--text-2xl); }
.font-medium   { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }
.font-bold     { font-weight: var(--weight-bold); }
.text-muted    { color: var(--muted); }
.text-secondary { color: var(--text-secondary); }
.text-center   { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 4. Common component styles ── */

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-full);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(196, 127, 46, 0.35);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: #fef2f2;
  color: var(--status-cancelled);
  border-color: #fecaca;
}
.btn-danger:hover { background: var(--status-cancelled); color: #fff; }

.btn-lg { padding: var(--space-3) var(--space-8); font-size: var(--text-base); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.badge-new       { background: #eff6ff; color: var(--status-new); }
.badge-cooking   { background: #fffbeb; color: var(--status-cooking); }
.badge-ready     { background: #ecfdf5; color: var(--status-ready); }
.badge-delivered { background: #f9fafb; color: var(--status-delivered); }
.badge-cancelled { background: #fef2f2; color: var(--status-cancelled); }
.badge-sold-out  { background: var(--surface-2); color: var(--muted); }

/* Inputs */
.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(196, 127, 46, 0.15);
}
.input::placeholder { color: var(--muted); }

/* Dividers */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-4) 0;
}

/* Modal backdrop */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn var(--transition-fast) ease;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp var(--transition-normal) ease;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--text);
  color: #fff;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  animation: toastIn 0.3s ease;
  white-space: nowrap;
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── 5. Animations ── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Loading spinner */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── 6. Responsive helpers ── */
@media (max-width: 640px) {
  :root {
    --text-2xl: 1.375rem;
    --text-3xl: 1.625rem;
  }
}
