/* ── base.css ─────────────────────────────────────────────────────────────────
   Reset · CSS Variables · Typography · Layout · RTL · Dark mode · Utilities
   ─────────────────────────────────────────────────────────────────────────── */

/* ── CSS Variables ───────────────────────────────────────────────────────── */
:root {
  /* ── Brand palette (Barmagly) ── */
  --delivery-primary:       #FF5722;
  --delivery-primary-light: rgba(255, 87, 34, 0.12);
  --delivery-primary-dark:  #E64A19;

  --delivery-accent:        #2FD3C6;
  --delivery-accent-light:  rgba(47, 211, 198, 0.12);

  --delivery-success:       #4CAF50;
  --delivery-success-light: rgba(76, 175, 80, 0.12);
  --delivery-warning:       #F59E0B;
  --delivery-danger:        #EF4444;
  --delivery-info:          #3B82F6;

  /* ── Surfaces ── */
  --delivery-bg:            #F8F9FA;
  --delivery-surface:       #FFFFFF;
  --delivery-card:          #FFFFFF;
  --delivery-border:        #E8ECF0;
  --delivery-border-dark:   #D1D9E0;

  /* ── Text ── */
  --delivery-text:          #1A1A2E;
  --delivery-text-secondary:#6B7280;
  --delivery-text-muted:    #9CA3AF;

  /* ── Nav (dark) ── */
  --nav-bg:                 #1A1A2E;
  --nav-text:               #FFFFFF;
  --nav-text-muted:         rgba(255,255,255,0.65);

  /* ── Order status ── */
  --status-pending:         #F59E0B;
  --status-accepted:        #3B82F6;
  --status-preparing:       #8B5CF6;
  --status-ready:           #2FD3C6;
  --status-on-way:          #FF5722;
  --status-delivered:       #10B981;
  --status-cancelled:       #EF4444;

  /* ── Loyalty tiers ── */
  --tier-bronze:            #CD7F32;
  --tier-silver:            #9CA3AF;
  --tier-gold:              #F59E0B;
  --tier-platinum:          #6366F1;

  /* ── Spacing scale ── */
  --space-xs:   4px;
  --space-sm:   8px;
  --space-md:   16px;
  --space-lg:   24px;
  --space-xl:   32px;
  --space-2xl:  48px;
  --space-3xl:  64px;

  /* ── Border radius ── */
  --radius-xs:  4px;
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  20px;
  --radius-xl:  28px;
  --radius-pill:9999px;

  /* ── Shadows ── */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.08);
  --shadow-xl:  0 20px 60px rgba(0,0,0,0.16);

  /* ── Transitions ── */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow:   400ms ease;

  /* ── Z-index scale ── */
  --z-base:           1;
  --z-sticky:         100;
  --z-modal-backdrop: 200;
  --z-modal:          300;
  --z-drawer:         350;
  --z-toast:          400;
  --z-splash:         500;

  /* ── Layout ── */
  --content-max:      680px;
  --page-max:        1280px;
  --nav-height:       64px;
  --bottom-nav-height:62px;
}

/* ── Dark mode ───────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --delivery-bg:      #0F1117;
    --delivery-surface: #1C1F2B;
    --delivery-card:    #242736;
    --delivery-border:  #2D3144;
    --delivery-border-dark: #3A3F5C;
    --delivery-text:    #F0F2F8;
    --delivery-text-secondary: #9CA3AF;
    --delivery-text-muted: #6B7280;
    --nav-bg:           #10111A;
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  background-color: var(--delivery-bg);
  color: var(--delivery-text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Mobile-first responsive defaults ─────────────────────────────────── */
img, video, svg, picture, iframe { max-width: 100%; height: auto; }
input, select, textarea, button { font: inherit; max-width: 100%; }
table { width: 100%; max-width: 100%; }
pre, code { white-space: pre-wrap; word-wrap: break-word; }
/* Tap targets ≥ 44px on phones */
@media (max-width: 640px) {
  button, .btn, [role="button"], input[type="submit"], input[type="button"] { min-height: 44px; }
  input, select, textarea { font-size: 16px; /* prevents iOS auto-zoom */ }
}

body[dir="rtl"] {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans Arabic",
    "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; text-decoration: none; }
a:focus-visible { outline: 2px solid var(--delivery-primary); outline-offset: 2px; }

img { max-width: 100%; height: auto; display: block; }

ul, ol { list-style: none; }

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
}
button:focus-visible { outline: 2px solid var(--delivery-primary); outline-offset: 2px; }

input, textarea, select {
  font: inherit;
  color: inherit;
  border: none;
  outline: none;
  background: none;
}

/* ── Lucide Icon Sizing ─────────────────────────────────────────────────── */
[data-lucide] { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.icon-xs  { width: 14px; height: 14px; }
.icon-sm  { width: 16px; height: 16px; }
.icon-md  { width: 20px; height: 20px; }
.icon-lg  { width: 24px; height: 24px; }
.icon-xl  { width: 32px; height: 32px; }
.icon-2xl { width: 48px; height: 48px; }
.icon-3xl { width: 64px; height: 64px; }

/* ── Typography ──────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--delivery-text);
}

h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.375rem, 3vw, 1.875rem); }
h3 { font-size: 1.375rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p { color: var(--delivery-text-secondary); line-height: 1.6; }

/* ── Text utilities ──────────────────────────────────────────────────────── */
.text-primary   { color: var(--delivery-primary); }
.text-secondary { color: var(--delivery-text-secondary); }
.text-muted     { color: var(--delivery-text-muted); }
.text-success   { color: var(--delivery-success); }
.text-danger    { color: var(--delivery-danger); }
.text-center    { text-align: center; }
.text-end       { text-align: end; }
.text-start     { text-align: start; }
.text-xs        { font-size: 0.75rem; }
.text-sm        { font-size: 0.875rem; }
.text-base      { font-size: 1rem; }
.text-lg        { font-size: 1.125rem; }
.text-xl        { font-size: 1.25rem; }
.font-medium    { font-weight: 500; }
.font-semibold  { font-weight: 600; }
.font-bold      { font-weight: 700; }
.uppercase      { text-transform: uppercase; }
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Layout utilities ────────────────────────────────────────────────────── */
.container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--space-md);
  width: 100%;
}

.container-wide {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  width: 100%;
}

.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.flex-wrap      { flex-wrap: wrap; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.items-end      { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between{ justify-content: space-between; }
.justify-end    { justify-content: flex-end; }
.flex-1         { flex: 1; }
.flex-shrink-0  { flex-shrink: 0; }
.gap-xs         { gap: var(--space-xs); }
.gap-sm         { gap: var(--space-sm); }
.gap-md         { gap: var(--space-md); }
.gap-lg         { gap: var(--space-lg); }
.gap-xl         { gap: var(--space-xl); }

.grid           { display: grid; }
.grid-2         { grid-template-columns: 1fr 1fr; }
.grid-3         { grid-template-columns: repeat(3, 1fr); }
.grid-auto      { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

.w-full         { width: 100%; }
.h-full         { height: 100%; }
.min-h-screen   { min-height: 100vh; }

.relative       { position: relative; }
.absolute       { position: absolute; }
.fixed          { position: fixed; }
.sticky         { position: sticky; }
.inset-0        { inset: 0; }
.overflow-hidden{ overflow: hidden; }
.overflow-auto  { overflow: auto; }

/* ── Spacing utilities ───────────────────────────────────────────────────── */
.p-xs  { padding: var(--space-xs); }
.p-sm  { padding: var(--space-sm); }
.p-md  { padding: var(--space-md); }
.p-lg  { padding: var(--space-lg); }
.p-xl  { padding: var(--space-xl); }
.px-md { padding-inline: var(--space-md); }
.px-lg { padding-inline: var(--space-lg); }
.py-sm { padding-block: var(--space-sm); }
.py-md { padding-block: var(--space-md); }
.py-lg { padding-block: var(--space-lg); }
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.ms-auto { margin-inline-start: auto; }

/* ── Scroll containers ───────────────────────────────────────────────────── */
.scroll-x {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.scroll-x::-webkit-scrollbar { display: none; }

/* ── Visibility ──────────────────────────────────────────────────────────── */
.hidden           { display: none !important; }
.invisible        { visibility: 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;
}

/* ── App shell layout ────────────────────────────────────────────────────── */
#app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#app {
  flex: 1;
  padding-bottom: var(--bottom-nav-height);
}

@media (min-width: 768px) {
  #app {
    padding-bottom: 0;
  }
}

/* ── Skeleton loading ────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--delivery-border) 25%,
    var(--delivery-bg) 50%,
    var(--delivery-border) 75%
  );
  background-size: 400% 100%;
  animation: skeleton-wave 1.6s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-wave {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--delivery-primary-light);
  border-top-color: var(--delivery-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Toast notifications ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: calc(var(--nav-height) + 12px);
  right: var(--space-md);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
  width: min(340px, calc(100vw - 32px));
}

@media (max-width: 767px) {
  #toast-container {
    top: auto;
    bottom: calc(var(--bottom-nav-height) + 12px);
    left: var(--space-md);
    right: var(--space-md);
    width: auto;
  }
}

.toast {
  background: var(--delivery-text);
  color: var(--delivery-surface);
  padding: 12px var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-slide-in 0.3s ease forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toast.success { background: #166534; }
.toast.error   { background: #7f1d1d; }
.toast.warning { background: #78350f; }
.toast::before {
  font-size: 1.1rem;
  flex-shrink: 0;
}
.toast.success::before { content: "✓"; }
.toast.error::before   { content: "✕"; }
.toast.warning::before { content: "⚠"; }

@keyframes toast-slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--delivery-border);
  margin: var(--space-md) 0;
}

.divider-sm { margin: var(--space-sm) 0; }

/* ── Section block ───────────────────────────────────────────────────────── */
.section-block {
  background: var(--delivery-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-md);
}

/* ── Professional Typography Scale ──────────────────────────────────────── */
.text-display {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.text-h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.text-h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.text-h3 { font-size: 1.1rem; font-weight: 600; }
.text-body { font-size: 0.95rem; line-height: 1.5; }
.text-caption { font-size: 0.8125rem; color: var(--delivery-text-secondary); }
.text-overline {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--delivery-text-muted);
}

/* ── Skeleton Variants ─────────────────────────────────────────────────── */
.skeleton-text {
  height: 14px;
  border-radius: var(--radius-xs);
}
.skeleton-text.sm { height: 12px; width: 60%; }
.skeleton-text.lg { height: 20px; }

.skeleton-card {
  border-radius: var(--radius-md);
  overflow: hidden;
}
.skeleton-card .skeleton-img { aspect-ratio: 16/9; }
.skeleton-card .skeleton-body { padding: var(--space-sm); }

.skeleton-avatar {
  border-radius: 50%;
}

.skeleton-circle {
  border-radius: 50%;
}

/* ── Focus & Accessibility ─────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--delivery-primary);
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Offline banner ─────────────────────────────────────────────────────── */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--delivery-danger); color: #fff;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem; font-weight: 600;
  text-align: center; z-index: var(--z-toast);
  display: flex; align-items: center; justify-content: center; gap: var(--space-sm);
  transform: translateY(0); transition: transform var(--transition-normal);
}
.offline-banner.hidden { transform: translateY(-100%); pointer-events: none; }

/* ── Responsive helpers ──────────────────────────────────────────────────── */
.desktop-only { display: none; }
.mobile-only  { display: block; }

@media (min-width: 768px) {
  .desktop-only { display: block; }
  .mobile-only  { display: none; }
  .flex.desktop-only { display: flex; }
}
