/*
  Fidélix design system. Mobile first (designed at 360px, then widened), right-to-left aware (logical properties only),
  light and dark. Tokens follow the Tailwind scale (stone neutrals, blue accent, amber for rewards).
  Rule: nothing is ever a bare error code; every problem uses .alert with an icon, a title and what to do next.
*/
:root {
  --font-latin: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-ar: 'Cairo', 'Segoe UI', Tahoma, system-ui, sans-serif;
  --font: var(--font-latin);

  /* Majorelle blue + saffron + coral on warm cream: the blue of Marrakech and Sidi Bou Said with the yellow of its gardens */
  --bg: #FFFBF5; --surface: #FFFFFF; --surface-2: #F7F2EA; --line: #EDE5D9; --line-strong: #DCCFBD;
  --text: #1E1B3A; --muted: #5C5873; --faint: #7C7894;
  --brand: #5B4BDB; --brand-hover: #4A3CC4; --brand-soft: #F0EEFF; --brand-line: #D5D0FF; --on-brand: #FFFFFF;
  --gold: #FFC53D; --gold-soft: #FFF4D6; --gold-ink: #7A5200;
  --coral: #FF6B5E; --coral-soft: #FFE9E6;
  --ok: #047857; --ok-soft: #E8FAF1; --ok-line: #A7F0CF;
  --bad: #C81E3A; --bad-soft: #FFF0F2; --bad-line: #FFC9D1;
  --warn: #A64B00; --warn-soft: #FFF6E0; --warn-line: #FFE0A3;
  --info: #5B4BDB; --info-soft: #F0EEFF; --info-line: #D5D0FF;
  --grad: linear-gradient(135deg, #5B4BDB 0%, #8E54E9 52%, #FF6B5E 100%);
  --grad-soft: linear-gradient(135deg, #F0EEFF 0%, #FFF0EC 100%);

  --r: 18px; --r-sm: 14px; --r-pill: 999px;
  --shadow: 0 1px 2px rgb(30 27 58 / .05), 0 8px 22px rgb(30 27 58 / .07);
  --shadow-brand: 0 10px 28px rgb(91 75 219 / .30);
  --ease: cubic-bezier(.2, .8, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12102A; --surface: #1C1940; --surface-2: #25214F; --line: #322D63; --line-strong: #4A4585;
    --text: #F6F4FF; --muted: #C3BFE0; --faint: #9A95C2;
    --brand: #9C93FF; --brand-hover: #B7B0FF; --brand-soft: #25214F; --brand-line: #3E3890; --on-brand: #12102A;
    --gold-soft: #3A2D0C; --gold-ink: #FFD770; --coral-soft: #3A1E24;
    --ok: #4ADE9B; --ok-soft: #0D2D22; --ok-line: #14583B;
    --bad: #FF9AAA; --bad-soft: #35121C; --bad-line: #6B2132;
    --warn: #FFC66B; --warn-soft: #2E2209; --warn-line: #64480F;
    --info: #9C93FF; --info-soft: #25214F; --info-line: #3E3890;
    --grad: linear-gradient(135deg, #4A3CC4 0%, #7A47D6 52%, #E0564B 100%);
    --grad-soft: linear-gradient(135deg, #25214F 0%, #35202B 100%);
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 22px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #12102A; --surface: #1C1940; --surface-2: #25214F; --line: #322D63; --line-strong: #4A4585;
    --text: #F6F4FF; --muted: #C3BFE0; --faint: #9A95C2;
    --brand: #9C93FF; --brand-hover: #B7B0FF; --brand-soft: #25214F; --brand-line: #3E3890; --on-brand: #12102A;
    --gold-soft: #3A2D0C; --gold-ink: #FFD770; --coral-soft: #3A1E24;
    --ok: #4ADE9B; --ok-soft: #0D2D22; --ok-line: #14583B;
    --bad: #FF9AAA; --bad-soft: #35121C; --bad-line: #6B2132;
    --warn: #FFC66B; --warn-soft: #2E2209; --warn-line: #64480F;
    --info: #9C93FF; --info-soft: #25214F; --info-line: #3E3890;
    --grad: linear-gradient(135deg, #4A3CC4 0%, #7A47D6 52%, #E0564B 100%);
    --grad-soft: linear-gradient(135deg, #25214F 0%, #35202B 100%);
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 22px rgb(0 0 0 / .35);
    color-scheme: dark;
}
html[lang="ar"] { --font: var(--font-ar); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 400 1rem/1.6 var(--font);
  min-height: 100dvh; padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.02em; font-weight: 800; text-wrap: balance; }
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3 { letter-spacing: 0; line-height: 1.4; }
h1 { font-size: clamp(1.5rem, 5.5vw, 2rem); } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0; } a { color: var(--brand); }
[hidden] { display: none !important; }
.i18n-pending [data-t] { visibility: hidden; }
.muted { color: var(--muted); } .faint { color: var(--faint); font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--brand-line); outline-offset: 2px; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

/* ---------- icons: one sprite, stroke style ---------- */
.i { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.i.fill { fill: currentColor; stroke: none; }
.i.lg { width: 1.75em; height: 1.75em; } .i.xl { width: 2.5em; height: 2.5em; }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: 560px; margin-inline: auto; padding: 16px; }
.wrap.wide { max-width: 1120px; }
.stack { display: grid; gap: 16px; } .stack.sm { gap: 8px; } .stack.lg { gap: 24px; }
/* grid children may shrink below their content; without this a wide child (tabs, a long link) pushes the whole page wider than the phone */
.stack > *, .cols > *, .kpis > *, .shops > *, .two > *, .form2 > *, .features > *, .steps > * { min-width: 0; }
html, body { overflow-x: clip; }
.row { display: flex; align-items: center; gap: 12px; } .row.wrap-r { flex-wrap: wrap; } .row.between { justify-content: space-between; } .grow { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; max-width: 1120px; margin-inline: auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; text-decoration: none; color: var(--text); min-height: 44px; }
.brand .mark { width: 34px; height: 34px; border-radius: 11px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; box-shadow: var(--shadow-brand); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; } .card.soft { background: var(--surface-2); box-shadow: none; }
.card h2 + p, .card h3 + p { margin-top: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: var(--r-sm); border: 1.5px solid transparent; font: 700 1rem var(--font); cursor: pointer; text-decoration: none;
  background: var(--surface-2); color: var(--text); transition: transform .12s var(--ease), background-color .15s, box-shadow .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { background: var(--line); } .btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-brand); } .btn.primary:hover { background: var(--brand-hover); }
.btn.gold { background: var(--gold); color: #1C1917; } .btn.gold:hover { filter: brightness(.95); }
.btn.outline { background: transparent; border-color: var(--line-strong); } .btn.outline:hover { background: var(--surface-2); }
.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); } .btn.danger:hover { background: var(--bad-line); }
.btn.ghost { background: transparent; } .btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; } .btn.sm { min-height: 40px; padding: 0 14px; font-size: .9rem; border-radius: 10px; } .btn.lg { min-height: 56px; font-size: 1.1rem; }
.btn[disabled], .btn.loading { opacity: .6; pointer-events: none; }
.btn.loading::after { content: ""; width: 1em; height: 1em; border: 2.5px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; color: var(--brand); font: 600 .95rem var(--font); cursor: pointer; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > label { font-weight: 700; font-size: .95rem; }
.field > label .opt { font-weight: 500; color: var(--faint); }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 0 14px; border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: 500 16px var(--font);   /* 16px stops iOS from zooming in */
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { padding: 12px 14px; min-height: 96px; resize: vertical; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-line); }
.input::placeholder { color: var(--faint); font-weight: 400; }
.field .hint { color: var(--faint); font-size: .85rem; }
.field.err .input { border-color: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }
.field .msg { display: flex; gap: 6px; align-items: flex-start; color: var(--bad); font-size: .9rem; font-weight: 600; }
.field .msg .i { margin-top: 3px; }
.pwd { position: relative; } .pwd .input { padding-inline-end: 48px; }
.pwd button { position: absolute; inset-inline-end: 4px; top: 4px; width: 40px; height: 40px; border: 0; background: none; color: var(--faint); border-radius: 10px; cursor: pointer; }
.input[dir="ltr"], .ltr { direction: ltr; unicode-bidi: plaintext; }
/* iOS Safari: date fields keep their own minimum width (overflowing the card) and show nothing when empty */
input[type="date"].input { min-width: 0; max-width: 100%; }
@supports (-webkit-touch-callout: none) {   /* iOS only: other browsers size and label date fields correctly */
  input[type="date"].input { -webkit-appearance: none; appearance: none; display: block; position: relative; line-height: 46px; }
  input[type="date"].input::-webkit-date-and-time-value { text-align: start; margin: 0; }
  input[type="date"].input.date-empty:not(:focus)::before { content: attr(data-hint); position: absolute; inset-inline-start: 14px; color: var(--faint); font-weight: 400; }
}
html[dir="rtl"] .input.ltr { text-align: end; }

/* ---------- alerts: every problem is labelled, with an icon and a next step ---------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid; border-radius: var(--r); animation: rise .25s var(--ease); }
.alert .ic { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.alert b { display: block; font-weight: 800; line-height: 1.3; } .alert p { margin-top: 2px; font-size: .93rem; opacity: .92; }
.alert.bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); } .alert.bad .ic { background: var(--bad-line); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); } .alert.ok .ic { background: var(--ok-line); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); } .alert.warn .ic { background: var(--warn-line); }
.alert.info { background: var(--info-soft); border-color: var(--info-line); color: var(--info); } .alert.info .ic { background: var(--info-line); }
.alert .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- badges, segmented control, toast ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill); font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.info { background: var(--info-soft); color: var(--info); } .badge.gold { background: var(--gold-soft); color: var(--gold-ink); }
.seg { display: inline-flex; padding: 3px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0; background: none; color: var(--muted); font: 700 .85rem var(--font); padding: 7px 14px; border-radius: var(--r-pill); cursor: pointer; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.toast-host { position: fixed; inset-inline: 0; bottom: max(16px, env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 50; pointer-events: none; padding-inline: 16px; }
.toast { pointer-events: auto; max-width: 440px; width: 100%; display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: var(--r-sm); background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow-brand); animation: rise .25s var(--ease); }

/* ---------- empty states and skeletons ---------- */
.empty { display: grid; justify-items: center; gap: 10px; padding: 28px 16px; text-align: center; color: var(--muted); }
.empty .ic { width: 64px; height: 64px; border-radius: 22px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.skeleton { border-radius: 10px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; min-height: 1em; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- stamps (the loyalty card) ---------- */
.dots { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 10px; direction: ltr; }
.dot { aspect-ratio: 1; border-radius: 50%; border: 2px dashed currentColor; opacity: .38; display: grid; place-items: center; }
.dot.on { border: 0; opacity: 1; background: var(--gold); color: #1C1917; animation: pop .45s var(--ease) both; animation-delay: calc(var(--n, 0) * 60ms); }
.dot .i { width: 52%; height: 52%; }
@keyframes pop { 0% { transform: scale(.3) rotate(-25deg); opacity: 0; } 70% { transform: scale(1.12) rotate(4deg); } 100% { transform: none; opacity: 1; } }

/* ---------- numbers and charts ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); display: grid; gap: 4px; }
.kpi .lab { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi .lab .i { color: var(--brand); } .kpi b { font-size: 1.9rem; line-height: 1.1; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; direction: ltr; padding-top: 8px; }
.bars i { flex: 1; min-width: 3px; background: var(--brand-line); border-radius: 5px 5px 2px 2px; transition: height .5s var(--ease); position: relative; }
.bars i.peak { background: var(--brand); } .bars i:hover { background: var(--brand); }
.axis { display: flex; justify-content: space-between; direction: ltr; font-size: .75rem; color: var(--faint); margin-top: 6px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(3, 1fr); } .wrap { padding: 24px; } }
@media (min-width: 960px) { .kpis.four { grid-template-columns: repeat(4, 1fr); } }

/* ---------- sheet / dialog: bottom sheet on phones, centered box on larger screens ---------- */
.scrim { position: fixed; inset: 0; background: rgb(12 10 9 / .55); z-index: 40; display: grid; align-items: end; animation: fade .2s; }
.sheet { background: var(--surface); width: 100%; max-height: 92dvh; overflow: auto; border-radius: 24px 24px 0 0; padding: 20px 16px max(20px, env(safe-area-inset-bottom)); animation: slide .28s var(--ease); }
@media (min-width: 720px) { .scrim { align-items: center; justify-items: center; } .sheet { max-width: 520px; border-radius: 24px; padding: 24px; } }
@keyframes fade { from { opacity: 0; } } @keyframes slide { from { transform: translateY(40px); opacity: 0; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: -8px auto 16px; } @media (min-width: 720px) { .sheet .grab { display: none; } }

/* ---------- scanner ---------- */
.viewfinder { position: relative; border-radius: 20px; overflow: hidden; background: #0C0A09; aspect-ratio: 4 / 3; display: grid; place-items: center; color: #fff; }
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.viewfinder .frame { position: relative; width: 62%; aspect-ratio: 1; border-radius: 22px; box-shadow: 0 0 0 999px rgb(12 10 9 / .45); }
.viewfinder .frame::before, .viewfinder .frame::after { content: ""; position: absolute; inset: 0; border-radius: 22px; border: 4px solid var(--gold); clip-path: polygon(0 0, 22% 0, 22% 4px, 4px 4px, 4px 22%, 0 22%, 0 0, 100% 0, 100% 22%, calc(100% - 4px) 22%, calc(100% - 4px) 4px, 78% 4px, 78% 0); }
.viewfinder .frame::after { transform: rotate(180deg); }
.viewfinder .laser { position: absolute; inset-inline: 8%; height: 3px; border-radius: 3px; background: var(--gold); box-shadow: 0 0 14px 2px var(--gold); animation: laser 2s ease-in-out infinite alternate; }
@keyframes laser { from { top: 12%; } to { top: 86%; } }
.viewfinder .idle { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; text-align: center; padding: 16px; }
.result { display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: var(--r); background: var(--ok-soft); border: 1px solid var(--ok-line); color: var(--ok); animation: rise .25s var(--ease); }
.result .ring { flex: none; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-line); }
.result b { font-size: 1.1rem; display: block; color: var(--text); }
.feed { display: grid; gap: 0; } .feed > div { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); } .feed > div:first-child { border-top: 0; }
.feed .ic { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.feed .ic.gold { background: var(--gold-soft); color: var(--gold-ink); }

/* ---------- colour and pattern helpers ---------- */
.grad { background: var(--grad); color: #fff; }
.grad-soft { background: var(--grad-soft); }
.text-grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
/* a subtle eight-point star lattice, in the spirit of zellige tiles */
.zellige { position: relative; isolation: isolate; }
.zellige::after { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.16' stroke-width='1.2'%3E%3Cpath d='M28 4l6 10 11-4-4 11 10 6-10 6 4 11-11-4-6 10-6-10-11 4 4-11-10-6 10-6-4-11 11 4z'/%3E%3C/g%3E%3C/svg%3E"); }

@media (max-width: 559px) { .hide-sm { display: none !important; } }
.brand span:last-child { white-space: nowrap; }

/* ---------- print (counter sign) ---------- */
@media print { body { background: #fff; } .no-print { display: none !important; } }
.foot-link { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 8px; }

.theme-btn { flex: none; width: 44px; height: 44px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface-2); color: var(--text); display: inline-grid; place-items: center; cursor: pointer; }
.theme-btn:hover { border-color: var(--line-strong); }
.nav .theme-btn { background: rgb(255 255 255 / .16); border-color: rgb(255 255 255 / .3); color: #fff; }
@media print { .theme-btn { display: none; } }
