/* ── base.css ─────────────────────────────────────────────────────────────────
   Reset · CSS Variables · Typography · Layout · RTL · Dark mode · Utilities
   ─────────────────────────────────────────────────────────────────────────── */

/* ── CSS Variables ───────────────────────────────────────────────────────── */
/* Light-first. The bare :root block is the light palette; dark is a swap of
   the same names, applied either by the OS (until the customer states a
   preference) or by <html data-theme="dark"> once they have. The preference
   itself lives in localStorage under "kassenta_theme" — the same key the
   customer app, the POS and the dashboards read. */
:root {
  color-scheme: light;

  /* ── Kassenta design tokens ──
     Brand is navy #040E32 + teal #00C1B0. --accent is the ink-bearing teal:
     it ALWAYS takes white text, so never lighten it below this value. */
  --bg:          #F2F6F5;
  --bg-2:        #E9F0EF;
  --surface:     #FFFFFF;
  --surface-2:   #F7FAFA;
  --border:      #E3EAE9;
  --border-2:    #CEDBD9;
  --text:        #0B1F26;
  --text-2:      #4A6362;
  --text-dim:    #7F9694;
  --accent:      #0A6E65;
  --accent-2:    #0E9C8D;
  --accent-soft: #E1F1EF;
  --accent-ring: rgba(10, 110, 101, 0.16);
  --teal:        #00C1B0;
  --navy:        #040E32;
  --scrim:       rgba(6, 26, 24, 0.55);

  /* Two-layer elevation: a tight contact shadow plus a wide soft one. */
  --shadow-card: 0 1px 2px rgba(11,31,38,0.04), 0 10px 26px rgba(11,31,38,0.07);
  --shadow-pop:  0 2px 6px rgba(11,31,38,0.06), 0 20px 48px rgba(11,31,38,0.13);

  /* ── Brand palette (legacy --delivery-* names, new Kassenta values) ──
     Per-store branding may still override --delivery-primary at runtime; the
     bootstrap in index.html ignores the retired orange default so a store that
     never picked a colour lands on the Kassenta accent instead. */
  --delivery-primary:       #0A6E65;
  --delivery-primary-light: rgba(10, 110, 101, 0.10);
  --delivery-primary-dark:  #08574F;

  --delivery-accent:        #00C1B0;
  --delivery-accent-light:  rgba(0, 193, 176, 0.12);

  --delivery-success:       #0F9D6E;
  --delivery-success-light: rgba(15, 157, 110, 0.12);
  --delivery-warning:       #C07A06;
  --delivery-danger:        #D64545;
  --delivery-info:          #3B6BF5;

  /* ── Surfaces ── */
  --delivery-bg:            #F2F6F5;
  --delivery-surface:       #FFFFFF;
  --delivery-card:          #FFFFFF;
  --delivery-border:        #E3EAE9;
  --delivery-border-dark:   #CEDBD9;

  /* ── Text ── */
  --delivery-text:          #0B1F26;
  --delivery-text-secondary:#4A6362;
  --delivery-text-muted:    #7F9694;

  /* ── Nav (navy) ── */
  --nav-bg:                 #040E32;
  --nav-text:               #FFFFFF;
  --nav-text-muted:         rgba(255,255,255,0.65);

  /* ── Order status ── */
  --status-pending:         #C07A06;
  --status-accepted:        #3B6BF5;
  --status-preparing:       #7C6BF5;
  --status-ready:           #00C1B0;
  --status-on-way:          #0E9C8D;
  --status-delivered:       #0F9D6E;
  --status-cancelled:       #D64545;

  /* ── Loyalty tiers ── */
  --tier-bronze:            #B4713C;
  --tier-silver:            #8FA3A1;
  --tier-gold:              #C07A06;
  --tier-platinum:          #5B6BD6;

  /* ── 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:  6px;
  --radius-sm:  10px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --radius-xl:  26px;
  --radius-pill:9999px;
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 26px; --r-pill: 999px;

  /* ── Shadows ── */
  --shadow-xs:  0 1px 2px rgba(11,31,38,0.05);
  --shadow-sm:  0 1px 2px rgba(11,31,38,0.04), 0 4px 12px rgba(11,31,38,0.05);
  --shadow-md:  0 1px 2px rgba(11,31,38,0.04), 0 10px 26px rgba(11,31,38,0.07);
  --shadow-lg:  0 2px 6px rgba(11,31,38,0.06), 0 20px 48px rgba(11,31,38,0.13);
  --shadow-xl:  0 4px 10px rgba(11,31,38,0.08), 0 32px 70px rgba(11,31,38,0.18);

  /* ── 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 ─────────────────────────────────────────────────────────────
   Opt-in via <html data-theme="dark">, which wins over everything below. */
html[data-theme="dark"] {
  color-scheme: dark;

  --bg:          #040E32;
  --bg-2:        #071544;
  --surface:     #0D1A44;
  --surface-2:   #132355;
  --border:      #1F2F5D;
  --border-2:    #2B3E73;
  --text:        #F1F5FD;
  --text-2:      #B5C0D8;
  --text-dim:    #8492B4;
  --accent:      #0E8A7E;
  --accent-2:    #00C1B0;
  --accent-soft: #0C2E36;
  --accent-ring: rgba(0, 193, 176, 0.22);
  --scrim:       rgba(0, 0, 0, 0.60);

  --shadow-card: 0 2px 6px rgba(0,0,0,0.32), 0 16px 40px rgba(0,0,0,0.40);
  --shadow-pop:  0 4px 12px rgba(0,0,0,0.40), 0 28px 60px rgba(0,0,0,0.52);

  --delivery-primary:       #0E8A7E;
  --delivery-primary-light: rgba(0, 193, 176, 0.14);
  --delivery-primary-dark:  #0A6E65;
  --delivery-accent:        #00C1B0;
  --delivery-accent-light:  rgba(0, 193, 176, 0.16);

  --delivery-success:       #10B981;
  --delivery-success-light: rgba(16, 185, 129, 0.16);
  --delivery-warning:       #F59E0B;
  --delivery-danger:        #EF4444;
  --delivery-info:          #5B84FF;

  --delivery-bg:            #040E32;
  --delivery-surface:       #0D1A44;
  --delivery-card:          #132355;
  --delivery-border:        #1F2F5D;
  --delivery-border-dark:   #2B3E73;

  --delivery-text:          #F1F5FD;
  --delivery-text-secondary:#B5C0D8;
  --delivery-text-muted:    #8492B4;

  --nav-bg:                 #071544;

  --shadow-xs:  0 1px 2px rgba(0,0,0,0.30);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.30), 0 4px 12px rgba(0,0,0,0.34);
  --shadow-md:  0 2px 6px rgba(0,0,0,0.32), 0 16px 40px rgba(0,0,0,0.40);
  --shadow-lg:  0 4px 12px rgba(0,0,0,0.40), 0 28px 60px rgba(0,0,0,0.52);
  --shadow-xl:  0 8px 20px rgba(0,0,0,0.46), 0 40px 84px rgba(0,0,0,0.60);
}

/* Follow the OS only until the customer states a preference — once they do,
   data-theme sits on <html> and the block above wins. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;

    --bg:          #040E32;
    --bg-2:        #071544;
    --surface:     #0D1A44;
    --surface-2:   #132355;
    --border:      #1F2F5D;
    --border-2:    #2B3E73;
    --text:        #F1F5FD;
    --text-2:      #B5C0D8;
    --text-dim:    #8492B4;
    --accent:      #0E8A7E;
    --accent-2:    #00C1B0;
    --accent-soft: #0C2E36;
    --accent-ring: rgba(0, 193, 176, 0.22);
    --scrim:       rgba(0, 0, 0, 0.60);

    --shadow-card: 0 2px 6px rgba(0,0,0,0.32), 0 16px 40px rgba(0,0,0,0.40);
    --shadow-pop:  0 4px 12px rgba(0,0,0,0.40), 0 28px 60px rgba(0,0,0,0.52);

    --delivery-primary:       #0E8A7E;
    --delivery-primary-light: rgba(0, 193, 176, 0.14);
    --delivery-primary-dark:  #0A6E65;
    --delivery-accent:        #00C1B0;
    --delivery-accent-light:  rgba(0, 193, 176, 0.16);

    --delivery-success:       #10B981;
    --delivery-success-light: rgba(16, 185, 129, 0.16);
    --delivery-warning:       #F59E0B;
    --delivery-danger:        #EF4444;
    --delivery-info:          #5B84FF;

    --delivery-bg:            #040E32;
    --delivery-surface:       #0D1A44;
    --delivery-card:          #132355;
    --delivery-border:        #1F2F5D;
    --delivery-border-dark:   #2B3E73;

    --delivery-text:          #F1F5FD;
    --delivery-text-secondary:#B5C0D8;
    --delivery-text-muted:    #8492B4;

    --nav-bg:                 #071544;

    --shadow-xs:  0 1px 2px rgba(0,0,0,0.30);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.30), 0 4px 12px rgba(0,0,0,0.34);
    --shadow-md:  0 2px 6px rgba(0,0,0,0.32), 0 16px 40px rgba(0,0,0,0.40);
    --shadow-lg:  0 4px 12px rgba(0,0,0,0.40), 0 28px 60px rgba(0,0,0,0.52);
    --shadow-xl:  0 8px 20px rgba(0,0,0,0.46), 0 40px 84px rgba(0,0,0,0.60);
  }
}

/* ── 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; }
}
