/* ============================================================
   Croissant Orders — mobile-first web app
   Design tokens follow the validated data-viz palette so the
   analytics charts and the UI share one system.
   ============================================================ */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f2f1ec;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11, 11, 11, .10);
  --shadow:      0 1px 2px rgba(11,11,11,.05), 0 8px 24px rgba(11,11,11,.06);

  /* brand */
  --accent:      #a35a00;
  --accent-ink:  #ffffff;
  --accent-wash: #fdf3e6;

  /* categorical series — slots 1-3 (validated all-pairs, both modes) */
  --series-1:    #2a78d6;   /* Plain   */
  --series-2:    #eb6834;   /* Cheese  */
  --series-3:    #1baf7a;   /* Nutella */

  /* status */
  --good:        #0ca30c;
  --warning:     #fab219;
  --critical:    #d03b3b;
  --good-text:   #006300;

  --radius:      14px;
  --radius-sm:   10px;
  --tap:         44px;
  --font:        system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic",
                 "Geeza Pro", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #242422;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --grid:        #2c2c2a;
    --axis:        #383835;
    --border:      rgba(255, 255, 255, .10);
    --shadow:      0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);

    --accent:      #eda100;
    --accent-ink:  #1a1a19;
    --accent-wash: #2a2113;

    --series-1:    #3987e5;
    --series-2:    #d95926;
    --series-3:    #199e70;

    --good-text:   #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #242422;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --axis:        #383835;
  --border:      rgba(255, 255, 255, .10);
  --shadow:      0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);

  --accent:      #eda100;
  --accent-ink:  #1a1a19;
  --accent-wash: #2a2113;

  --series-1:    #3987e5;
  --series-2:    #d95926;
  --series-3:    #199e70;

  --good-text:   #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------------- login ---------------- */

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 70% at 50% 0%, var(--accent-wash) 0%, transparent 62%),
    var(--page);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 22px 20px;
}

.brand { text-align: center; margin-bottom: 22px; }
.brand-mark { font-size: 44px; line-height: 1; }
.brand h1 { font-size: 21px; margin-top: 10px; }
.brand-sub { color: var(--ink-2); font-size: 13px; margin-top: 4px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field textarea { min-height: 74px; resize: vertical; }

.form-error {
  color: var(--critical);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 10px;
}

.demo-accounts {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.demo-accounts summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 600;
  list-style: none;
}
.demo-accounts summary::-webkit-details-marker { display: none; }
.demo-accounts summary::before { content: "▸ "; }
.demo-accounts[open] summary::before { content: "▾ "; }
.demo-list { display: grid; gap: 6px; margin-top: 10px; }
.demo-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: start;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 13px;
}
.demo-chip code { color: var(--ink-2); font-size: 12px; }

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  transition: transform .06s ease, opacity .15s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn-danger { color: var(--critical); }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 16px;
}

/* ---------------- app shell ---------------- */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  background: var(--page);
  box-shadow: 0 0 0 1px var(--border);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-mark { font-size: 24px; }
.topbar-id strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-id small { display: block; font-size: 11.5px; color: var(--muted); }
.topbar-actions { display: flex; gap: 7px; flex-shrink: 0; }

.view {
  flex: 1;
  padding: 16px 14px 22px;
  display: grid;
  gap: 16px;
  align-content: start;
}

/* ---------------- tab bar ---------------- */

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 2px 7px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
}
.tab-ico { font-size: 19px; line-height: 1.15; }
.tab[aria-current="page"] { color: var(--accent); }
.tab-badge {
  position: absolute;
  top: 4px;
  inset-inline-start: 50%;
  margin-inline-start: 6px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ---------------- generic blocks ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.card-pad-0 { padding: 0; overflow: hidden; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.section-head h2 { font-size: 16px; }
.section-head .hint,
.hint { font-size: 12px; color: var(--muted); }

.empty {
  text-align: center;
  padding: 34px 16px;
  color: var(--muted);
  font-size: 13.5px;
}
.empty .empty-ico { font-size: 32px; display: block; margin-bottom: 8px; opacity: .75; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.pill-pending   { color: #8a6100; background: color-mix(in srgb, var(--warning) 18%, transparent); }
.pill-confirmed { color: var(--series-1); background: color-mix(in srgb, var(--series-1) 15%, transparent); }
.pill-delivered { color: var(--good-text); background: color-mix(in srgb, var(--good) 15%, transparent); }
.pill-cancelled { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); }

/* ---------------- products ---------------- */

.product-list { display: grid; gap: 12px; }

.product {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 13px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
/* a card with something in the cart reads as selected without shouting */
.product.is-picked {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}
.product-info { min-width: 0; }
.product-thumb {
  width: 62px;
  height: 62px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 30px;
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(255,255,255,.55), transparent 60%),
    var(--tint, var(--surface-2));
  border: 1px solid var(--border);
}

/* second row of the card: quick adds, then stepper + running amount */
.product-actions {
  grid-column: 1 / -1;
  display: grid;
  gap: 9px;
  padding-top: 11px;
  border-top: 1px solid var(--border);
}
.product-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.product-amt { font-size: 14.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.product-amt.is-zero { color: var(--muted); font-weight: 500; }

.quick-adds { display: flex; gap: 7px; }
.quick-add {
  flex: 1;
  min-height: 36px;
  border-radius: 9px;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.quick-add:active { transform: scale(.97); }
.product-name { font-size: 15px; font-weight: 600; }
.product-desc { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; }
.product-price { font-size: 13.5px; font-weight: 600; margin-top: 5px; }
.product-price small { color: var(--muted); font-weight: 500; }
.product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.product.is-out { opacity: .55; }

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--page);
  overflow: hidden;
}
.stepper button {
  width: 38px;
  height: 38px;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: 19px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.stepper button:disabled { color: var(--muted); opacity: .5; }
.stepper input {
  width: 46px;
  height: 38px;
  border: 0;
  background: none;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  outline: none;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* sticky cart summary bar */
.cartbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.cartbar-total { font-size: 12px; color: var(--muted); }
.cartbar-total strong { display: block; font-size: 17px; color: var(--ink); }

/* ---------------- lines / rows ---------------- */

.line {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
}
.line:last-child { border-bottom: 0; }
.line-ico {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 17px;
  background: var(--tint, var(--surface-2));
  border: 1px solid var(--border);
}
.line-name { font-size: 14px; font-weight: 600; }
.line-sub { font-size: 12px; color: var(--muted); }
.line-amt { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.totals { padding: 12px 13px; border-top: 1px solid var(--border); display: grid; gap: 7px; }
.totals-row { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--ink-2); }
.totals-row.grand { font-size: 17px; font-weight: 700; color: var(--ink); padding-top: 7px; border-top: 1px solid var(--border); }
.totals-row span:last-child { font-variant-numeric: tabular-nums; }

/* ---------------- order cards ---------------- */

.order {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.order-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  width: 100%;
  padding: 12px 13px;
  background: none;
  border: 0;
  text-align: start;
  color: inherit;
}
.order-id { font-size: 14px; font-weight: 600; }
.order-meta { font-size: 12px; color: var(--muted); grid-column: 1; }
.order-right { grid-row: 1 / 3; grid-column: 2; display: grid; gap: 5px; justify-items: end; align-content: center; }
.order-total { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.order-body { border-top: 1px solid var(--border); background: var(--page); }
.order-note {
  padding: 10px 13px;
  font-size: 12.5px;
  color: var(--ink-2);
  border-top: 1px solid var(--border);
}
.order-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 13px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------------- filters ---------------- */

.filters { display: grid; gap: 10px; }
.chiprow {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.chiprow::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.daterow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.daterow .field { margin: 0; }

/* ---------------- stats ---------------- */

.hero { text-align: start; }
.hero-label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.hero-value { font-size: 40px; font-weight: 700; letter-spacing: -.025em; line-height: 1.1; margin-top: 2px; }
.hero-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.delta { font-weight: 600; }
.delta-up { color: var(--good-text); }
.delta-down { color: var(--critical); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 11px;
}
.stat-label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; }
.stat-value { font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px; }

/* ---------------- charts ---------------- */

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}
.chart-head > div:first-child { min-width: 0; }
/* the metric toggle sits on its own row — arabic chart titles are long
   enough that sharing the head row causes collisions */
.metric-row { margin-top: 10px; overflow: visible; }
.metric-row .chip {
  min-height: 32px;
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
}
.chart-title { font-size: 14.5px; font-weight: 600; }
.chart-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.chart-wrap { position: relative; margin-top: 10px; direction: ltr; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }

/* SVG marks are styled here, not via presentation attributes —
   var() is not reliably supported in presentation attributes. */
.g-grid  { stroke: var(--grid); stroke-width: 1; }
.g-axis  { stroke: var(--axis); stroke-width: 1; }
.g-bar   { fill: var(--series-1); }
.g-hit   { fill: transparent; pointer-events: all; }
.g-tick,
.g-label { fill: var(--muted); font-family: var(--font); font-size: 10.5px; }
.g-tick  { font-variant-numeric: tabular-nums; }

.tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  transition: opacity .1s ease;
}
.tooltip strong { display: block; font-size: 12.5px; }
.tooltip .tt-val { font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* breakdown bars — direct-labelled (relief rule for light-mode aqua) */
.breakdown { display: grid; gap: 13px; margin-top: 12px; }
.bd-row { display: grid; gap: 5px; }
.bd-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.bd-name { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; }
.bd-key { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: 0 0 auto; }
.bd-val { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bd-track { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bd-fill {
  height: 100%;
  background: var(--c);
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  min-width: 3px;
}
.bd-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend-key { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

/* data table view */
.table-wrap { overflow-x: auto; margin-top: 12px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; text-align: end; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: start; }
table.data thead th { font-size: 11.5px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--axis); }
table.data td { border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tfoot td { font-weight: 700; border-top: 1px solid var(--axis); }

.linkish {
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------------- admin ---------------- */

.subtabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.subtab {
  border: 0;
  background: none;
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  min-height: 36px;
}
.subtab[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.admin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 12px 13px;
  border-bottom: 1px solid var(--border);
}
.admin-row:last-child { border-bottom: 0; }
.admin-row .sub { font-size: 12px; color: var(--muted); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }

select.status-select {
  min-height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--page);
  font-size: 13px;
  font-weight: 600;
}

.inline-form { display: grid; gap: 10px; padding: 13px; }
.inline-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form .field { margin: 0; }

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .tabbar, .topbar-actions, .chiprow, .cartbar { display: none !important; }
  .app { max-width: none; box-shadow: none; }
}


/* ============================================================
   Language switching / RTL
   ============================================================ */

.login-lang {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: 4px;
}
.lang-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 5px 12px;
  min-height: 32px;
  font-size: 12.5px;
  font-weight: 600;
}
.lang-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.icon-btn-text { font-size: 13px; font-weight: 700; }

/* the disclosure caret must point into the text, not away from it */
[dir="rtl"] .demo-accounts summary::before { content: "◂ "; }

/* right-aligned cell in a two-column admin row */
.admin-row-end { text-align: end; }

/* logins, phone numbers and prices are latin runs inside arabic text */
.ltr { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .ltr { text-align: end; }

/* the chart is forced ltr, so put its tooltip back in ltr flow too */
.chart-wrap .tooltip { direction: ltr; text-align: left; }
[dir="rtl"] .chart-wrap .tooltip { direction: rtl; text-align: right; }


/* ============================================================
   Storefront — greeting, balance, delivery
   ============================================================ */

.greet {
  background:
    radial-gradient(120% 130% at 100% 0%, var(--accent-wash) 0%, transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.greet-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.greet-hello { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.greet-name { font-size: 19px; letter-spacing: -.02em; margin-top: 1px; }
.greet-mark { font-size: 26px; line-height: 1; opacity: .9; }
.greet-repeat { justify-self: start; }

.balance {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.balance.is-due {
  background: color-mix(in srgb, var(--critical) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--critical) 30%, transparent);
}
.balance.is-clear {
  background: color-mix(in srgb, var(--good) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--good) 26%, transparent);
}
.balance-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.balance-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.balance.is-due .balance-value { color: var(--critical); }
.balance-side { font-size: 12px; color: var(--muted); }
.balance-side.balance-ok { color: var(--good-text); font-weight: 600; }

.delivery-hint { text-align: center; }
.delivery-hint.is-free { color: var(--good-text); font-weight: 600; }
.totals-row .is-free { color: var(--good-text); font-weight: 600; }
.waived-tag {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--good-text);
  background: color-mix(in srgb, var(--good) 14%, transparent);
  border-radius: 999px;
  padding: 1px 7px;
  margin-inline-start: 4px;
}
.btn-free {
  color: var(--good-text);
  border-color: color-mix(in srgb, var(--good) 38%, transparent);
}

/* cart line: amount with a quick remove underneath */
.line-end { display: grid; justify-items: end; gap: 6px; }
.line-del {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}
.line-del:hover, .line-del:active {
  color: var(--critical);
  border-color: color-mix(in srgb, var(--critical) 40%, transparent);
  background: color-mix(in srgb, var(--critical) 8%, var(--surface));
}

/* ============================================================
   Payment state
   ============================================================ */

.pill-paid    { color: var(--good-text); background: color-mix(in srgb, var(--good) 15%, transparent); }
.pill-partial { color: #8a6100; background: color-mix(in srgb, var(--warning) 18%, transparent); }
.pill-due     { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); }

.pill-stack { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
[dir="rtl"] .pill-stack { justify-content: flex-start; }

/* an unpaid order gets a hairline flag down its leading edge */
.order.is-unpaid { border-inline-start: 3px solid color-mix(in srgb, var(--critical) 55%, transparent); }

.order-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 13px;
  border-top: 1px solid var(--border);
}

/* Order footer: settle button beside the status select. The delivery date
   keeps its full width, so on a narrow phone the actions wrap to their own
   row rather than squeezing the date onto two lines. */
.order-foot { flex-wrap: wrap; row-gap: 8px; }
.order-foot > .hint { white-space: nowrap; }
.foot-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-inline-start: auto;
}
.btn-pay {
  color: var(--good-text);
  border-color: color-mix(in srgb, var(--good) 40%, transparent);
  background: color-mix(in srgb, var(--good) 10%, var(--surface));
}
.btn-unpay { color: var(--ink-2); }

.totals-row.is-due-row { color: var(--critical); font-weight: 700; }
.is-due-text { color: var(--critical); }
.is-ok-text  { color: var(--good-text); }

.ledger-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.ledger-split > div {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}
.ledger-label { display: block; font-size: 11.5px; color: var(--ink-2); font-weight: 600; }
.ledger-split strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.settled-note { margin-top: 10px; text-align: center; color: var(--good-text); font-weight: 600; }

.sub-head { padding: 13px 13px 3px; }
.sub-head h2 { font-size: 15px; }

.pay-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
}
.pay-row:last-child { border-bottom: 0; }
.pay-row .sub { font-size: 12px; color: var(--muted); }

/* ---------------- admin: debts ---------------- */

.hero-due .hero-value { color: var(--critical); }
.stat-value-sm { font-size: 15px; }

.debt-row { padding: 12px 13px; border-bottom: 1px solid var(--border); }
.debt-row:last-child { border-bottom: 0; }
.debt-row.is-due { background: color-mix(in srgb, var(--critical) 4%, transparent); }
.debt-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.debt-amt { text-align: end; }
.debt-amt .line-amt { font-size: 16px; }
.debt-row .sub { font-size: 12px; color: var(--muted); }
.debt-actions { margin-top: 9px; }

.pay-form {
  display: grid;
  gap: 10px;
  margin-top: 11px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.pay-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pay-form .field { margin: 0; }

/* the same form docked under an order row */
.pay-form-order {
  margin: 0;
  border-radius: 0;
  border-inline: 0;
  border-bottom: 0;
}
.pay-form-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.pay-form-foot strong { color: var(--critical); font-variant-numeric: tabular-nums; }


/* ============================================================
   Invoice — hidden on screen, the whole page when printing.
   Deliberately fixed colours: paper is white whatever the theme.
   ============================================================ */

.invoice-sheet { display: none; }

@media print {
  @page { size: A4; margin: 14mm; }

  /* clicking "print invoice" swaps the app out for the sheet */
  body.printing .app,
  body.printing .login-screen,
  body.printing .toast { display: none !important; }
  body.printing .invoice-sheet { display: block; }

  /* a plain Cmd+P still prints whatever screen is open */
  .tabbar, .topbar-actions, .chiprow, .cartbar,
  .quick-adds, .order-actions, .stepper { display: none !important; }
  .app { max-width: none; box-shadow: none; }
}

.invoice-sheet {
  color: #000;
  background: #fff;
  font-size: 11pt;
  line-height: 1.45;
  padding: 0;
}
.invoice-sheet h1, .invoice-sheet h2, .invoice-sheet h3 { margin: 0; }
.invoice-sheet p { margin: 0; }

.inv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 2px solid #000;
}
.inv-biz { display: flex; gap: 11px; align-items: flex-start; }
.inv-logo { font-size: 30px; line-height: 1; }
.inv-biz h1 { font-size: 15pt; letter-spacing: -.01em; }
.inv-biz p { font-size: 9.5pt; color: #444; }
.inv-meta { text-align: end; }
.inv-meta h2 { font-size: 17pt; letter-spacing: .06em; }
.inv-meta p { font-size: 9.5pt; margin-top: 2px; }
.inv-meta span { color: #666; }

.inv-parties {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin: 16px 0;
}
.inv-parties h3 { font-size: 8.5pt; text-transform: uppercase; letter-spacing: .09em; color: #666; }
.inv-parties p { font-size: 10pt; }
.inv-strong { font-weight: 700; font-size: 11.5pt; margin-top: 2px; }
.inv-status { text-align: end; }
.inv-status p { font-size: 9pt; color: #666; margin-top: 4px; }
.inv-stamp {
  display: inline-block;
  padding: 4px 12px;
  border: 2px solid currentColor;
  border-radius: 5px;
  font-size: 10pt;
  font-weight: 700;
  letter-spacing: .04em;
}
.inv-stamp-paid    { color: #0a7a0a; }
.inv-stamp-partial { color: #8a6100; }
.inv-stamp-due     { color: #c02b2b; }

.inv-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.inv-table th, .inv-table td { padding: 7px 8px; text-align: end; }
.inv-table th:first-child, .inv-table td:first-child { text-align: start; }
.inv-table thead th {
  font-size: 8.5pt;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #666;
  border-bottom: 1.5px solid #000;
}
.inv-table tbody td { border-bottom: 1px solid #ddd; font-size: 10pt; }
.inv-table tfoot td { font-size: 10pt; padding: 5px 8px; }
.inv-table tfoot td:first-child { text-align: end; color: #444; }
.inv-table tfoot tr:first-child td { padding-top: 10px; }
.inv-grand td { font-size: 12.5pt; font-weight: 700; border-top: 1.5px solid #000; padding-top: 8px !important; }
.inv-due td { color: #c02b2b; font-weight: 700; }

.inv-note {
  margin-top: 14px;
  padding: 9px 11px;
  background: #f4f4f2;
  border-radius: 5px;
  font-size: 9.5pt;
}
.inv-account {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1.5px solid #000;
  border-radius: 5px;
  font-size: 10.5pt;
}

.inv-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-top: 30px;
}
.inv-thanks { font-size: 10pt; font-style: italic; color: #444; }
/* arabic has no true italic — browsers fake it by slanting, which reads badly */
[dir="rtl"] .inv-thanks { font-style: normal; }
.inv-sign { text-align: center; }
.inv-sign span { font-size: 8.5pt; color: #666; }
.inv-sign i { display: block; width: 150px; border-bottom: 1px solid #000; margin-top: 26px; }
.inv-demo { margin-top: 16px; font-size: 8pt; color: #999; text-align: center; }
