/* =====================================================================
   Price Manager - Design System (RTL first, light + dark from day one)
   Sections: 1 tokens · 2 base · 3 shell · 4 controls · 5 data display
             6 overlays · 7 price table · 8 responsive
   Rules: logical properties only (margin-inline, padding-block ...),
          all colours come from tokens, dark mode = token swap, no per-component overrides.
   ===================================================================== */

@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* ---------- 1. Tokens ---------- */
:root {
  --font: "Vazirmatn", "Tahoma", system-ui, sans-serif;

  /* type scale (px) — 12 / 13 / 14 / 16 / 20 / 28 */
  --fs-xs: 0.75rem; --fs-sm: 0.8125rem; --fs-md: 0.875rem; --fs-lg: 1rem; --fs-xl: 1.25rem; --fs-2xl: 1.75rem;
  --lh: 1.7;

  /* spacing scale: 4px steps */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;

  /* radius: control < panel < modal */
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px;

  --sidebar-w: 236px; --topbar-h: 56px;
  --ease: cubic-bezier(.2, .7, .2, 1);

  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;      /* table header, hovers */
  --surface-3: #e9edf1;
  --line: #dbe1e7;
  --line-strong: #c3ccd5;
  --ink: #16202a;
  --ink-2: #4a5866;
  --ink-3: #74838f;

  --primary: #0f6e78;         /* petrol teal */
  --primary-ink: #ffffff;
  --primary-soft: #dcf0f1;
  --primary-line: #a9d4d8;

  --up: #c2410c;              /* price increase */
  --up-soft: #fde9dd;
  --down: #15803d;            /* price decrease */
  --down-soft: #dcf3e4;
  --warn: #a16207;
  --warn-soft: #fbf0cf;
  --danger: #b42318;
  --danger-soft: #fde4e1;
  --info-soft: #e4ecf6;

  /* staleness scale — used by the freshness bar and "days ago" badges */
  --age-0: #2f9e6b;
  --age-1: #c9a227;
  --age-2: #dd7a1f;
  --age-3: #c2362b;

  --shadow-pop: 0 12px 32px rgba(15, 30, 45, .16), 0 2px 6px rgba(15, 30, 45, .08);
  --focus: 0 0 0 3px rgba(15, 110, 120, .32);
  --overlay: rgba(12, 20, 28, .48);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1218;
  --surface: #141b23;
  --surface-2: #19222c;
  --surface-3: #202b37;
  --line: #26323f;
  --line-strong: #364555;
  --ink: #e7ecf1;
  --ink-2: #b0bcc8;
  --ink-3: #7f8e9c;

  --primary: #45b6c0;
  --primary-ink: #06222a;
  --primary-soft: #13343a;
  --primary-line: #21545c;

  --up: #ff9a62;
  --up-soft: #3a2316;
  --down: #52cf86;
  --down-soft: #14301f;
  --warn: #e6b94d;
  --warn-soft: #362b10;
  --danger: #ff7d70;
  --danger-soft: #3a1a17;
  --info-soft: #182636;

  --age-0: #3fc088;
  --age-1: #dcb63a;
  --age-2: #f08d34;
  --age-3: #f0564a;

  --shadow-pop: 0 14px 36px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
  --focus: 0 0 0 3px rgba(69, 182, 192, .38);
  --overlay: rgba(0, 0, 0, .62);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1218; --surface: #141b23; --surface-2: #19222c; --surface-3: #202b37;
    --line: #26323f; --line-strong: #364555; --ink: #e7ecf1; --ink-2: #b0bcc8; --ink-3: #7f8e9c;
    --primary: #45b6c0; --primary-ink: #06222a; --primary-soft: #13343a; --primary-line: #21545c;
    --up: #ff9a62; --up-soft: #3a2316; --down: #52cf86; --down-soft: #14301f;
    --warn: #e6b94d; --warn-soft: #362b10; --danger: #ff7d70; --danger-soft: #3a1a17; --info-soft: #182636;
    --age-0: #3fc088; --age-1: #dcb63a; --age-2: #f08d34; --age-3: #f0564a;
    --shadow-pop: 0 14px 36px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
    --focus: 0 0 0 3px rgba(69, 182, 192, .38); --overlay: rgba(0, 0, 0, .62);
  }
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 var(--fs-md)/var(--lh) var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--fs-xl); font-weight: 700; line-height: 1.4; }
h2 { font-size: var(--fs-lg); font-weight: 650; line-height: 1.4; }
h3 { font-size: var(--fs-md); font-weight: 650; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- 3. App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: var(--s4) var(--s3);
}
.brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3) var(--s5); font-weight: 700; font-size: var(--fs-lg); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin: var(--s4) var(--s3) var(--s1); font-size: var(--fs-xs); color: var(--ink-3); }
.nav a {
  display: flex; align-items: center; gap: var(--s3); padding: 8px var(--s3);
  border-radius: var(--r-sm); color: var(--ink-2); font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.nav .count { margin-inline-start: auto; font-size: var(--fs-xs); color: var(--ink-3); }
.sidebar-foot { margin-top: auto; padding: var(--s3); font-size: var(--fs-xs); color: var(--ink-3); border-top: 1px solid var(--line); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s3); padding-inline: var(--s6);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .grow { flex: 1; }
.global-search { position: relative; width: min(420px, 100%); }
.global-search input { padding-inline-start: 36px; }
.global-search .icon { position: absolute; inset-inline-start: 11px; top: 50%; translate: 0 -50%; color: var(--ink-3); pointer-events: none; }
.kbd { font-size: var(--fs-xs); padding: 0 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; color: var(--ink-3); background: var(--surface); font-family: inherit; }
.global-search .kbd { position: absolute; inset-inline-end: 8px; top: 50%; translate: 0 -50%; }
.user-chip { display: flex; align-items: center; gap: var(--s2); padding: 4px 6px 4px var(--s3); border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); }
.btn.menu-btn { display: none; }

.page { padding: var(--s6); display: flex; flex-direction: column; gap: var(--s5); max-width: 1680px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.page-head p { color: var(--ink-3); font-size: var(--fs-sm); margin-top: 2px; }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- 4. Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding-inline: 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 500; white-space: nowrap;
  transition: background .12s var(--ease), border-color .12s var(--ease), transform .08s var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 650; }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 30px; padding-inline: 10px; font-size: var(--fs-sm); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.input, .select {
  width: 100%; height: 36px; padding-inline: 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); outline: none;
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
.input::placeholder { color: var(--ink-3); }
.input:focus, .select:focus { border-color: var(--primary); box-shadow: var(--focus); }
.input-num { text-align: end; direction: ltr; font-variant-numeric: tabular-nums; }
.select { appearance: none; padding-inline-end: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2374838f' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 10px center; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label { font-size: var(--fs-sm); color: var(--ink-2); font-weight: 500; }
.hint { font-size: var(--fs-xs); color: var(--ink-3); }
.field-error { font-size: var(--fs-sm); color: var(--danger); }
.input[aria-invalid="true"] { border-color: var(--danger); }

.check { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: var(--r-sm); }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 5px; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 500; }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); font-weight: 650; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding-inline: 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: var(--fs-sm); color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary); font-weight: 600; }
.chip-margin { height: 28px; padding-inline: 10px; }

/* ---------- 5. Data display ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.panel-body { padding: var(--s5); }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding-inline: 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.badge-up { background: var(--up-soft); color: var(--up); }
.badge-down { background: var(--down-soft); color: var(--down); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* stat strip: one container, ruled cells — not a grid of identical cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.stat { padding: var(--s4) var(--s5); border-inline-end: 1px solid var(--line); border-block-end: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.stat:nth-child(4n) { border-inline-end: 0; }
.stat:nth-last-child(-n+4) { border-block-end: 0; }
.stat .v { font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.5; }
.stat .l { font-size: var(--fs-sm); color: var(--ink-3); }
.stat.is-warn .v { color: var(--age-2); }
.stat.is-alert .v { color: var(--age-3); }

/* freshness bar: the signature element. Segment widths = share of products */
.fresh-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; }
.fresh-bar button { border: 0; padding: 0; min-width: 4px; transition: filter .15s var(--ease), transform .15s var(--ease); }
.fresh-bar button:hover { filter: brightness(1.12); transform: scaleY(1.25); }
.fresh-legend { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); margin-top: var(--s4); }
.fresh-legend button { text-align: start; border: 0; background: none; padding: 0; display: flex; flex-direction: column; }
.fresh-legend b { font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }
.fresh-legend span { font-size: var(--fs-sm); color: var(--ink-3); }
.fresh-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-inline-end: 6px; }

.age { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); white-space: nowrap; }
.age .dot { background: var(--age-0); }
.age[data-level="1"] .dot { background: var(--age-1); }
.age[data-level="2"] .dot { background: var(--age-2); }
.age[data-level="3"] .dot { background: var(--age-3); }
.age[data-level="3"], .age[data-level="2"] { font-weight: 600; }

.delta { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; font-weight: 600; font-size: var(--fs-sm); }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: var(--s3); padding: 10px var(--s5); border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; }
.bars i { display: block; width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 3px; opacity: .85; }
.bars small { font-size: 11px; color: var(--ink-3); }

.empty { padding: var(--s8); text-align: center; color: var(--ink-3); }

/* ---------- 6. Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: var(--overlay); display: none; align-items: center; justify-content: center; padding: var(--s4); }
.overlay.open { display: flex; animation: fade .15s var(--ease); }
.modal { width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); animation: pop .18s var(--ease); }
.modal-lg { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }

.toasts { position: fixed; inset-block-end: var(--s5); inset-inline-start: var(--s5); z-index: 80; display: flex; flex-direction: column; gap: var(--s2); }
.toast { display: flex; align-items: flex-start; gap: 10px; min-width: 260px; max-width: 380px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); border-inline-start: 4px solid var(--down); box-shadow: var(--shadow-pop); animation: pop .2s var(--ease); }
.toast.error { border-inline-start-color: var(--danger); }
.toast.info { border-inline-start-color: var(--primary); }
.toast b { display: block; font-weight: 650; }
.toast small { color: var(--ink-3); }

.menu { position: absolute; z-index: 40; min-width: 200px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-pop); display: none; }
.menu.open { display: block; animation: pop .14s var(--ease); }
.menu label, .menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: none; border-radius: var(--r-sm); text-align: start; }
.menu label:hover, .menu button:hover { background: var(--surface-2); }
.pos-rel { position: relative; }

.pagination { display: flex; align-items: center; gap: 4px; }
.pagination button { min-width: 32px; height: 32px; border: 1px solid transparent; border-radius: var(--r-sm); background: none; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.pagination button:hover { background: var(--surface-3); }
.pagination button[aria-current="page"] { background: var(--primary); color: var(--primary-ink); font-weight: 650; }

.savebar { position: sticky; inset-block-end: var(--s4); z-index: 30; align-self: center; display: none; align-items: center; gap: var(--s4); padding: 10px 14px 10px 10px; background: var(--ink); color: var(--bg); border-radius: 999px; box-shadow: var(--shadow-pop); }
.savebar.show { display: flex; animation: pop .18s var(--ease); }
.savebar .btn { height: 32px; }
.savebar .kbd { background: transparent; border-color: color-mix(in srgb, var(--bg) 40%, transparent); color: inherit; }

/* ---------- 7. Price table ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.toolbar .select { width: auto; min-width: 150px; }
.toolbar .search { flex: 1; min-width: 220px; max-width: 360px; position: relative; }
.toolbar .search input { padding-inline-start: 34px; }
.toolbar .search .icon { position: absolute; inset-inline-start: 10px; top: 50%; translate: 0 -50%; color: var(--ink-3); pointer-events: none; }
.bulkbar { display: none; align-items: center; gap: var(--s3); padding: 8px var(--s4); background: var(--primary-soft); border-bottom: 1px solid var(--primary-line); color: var(--primary); font-weight: 600; }
.bulkbar.show { display: flex; }

.table-wrap { overflow-x: auto; }
table.ptable { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.ptable th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: var(--fs-sm); color: var(--ink-2); text-align: start; padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable .c-age { white-space: nowrap; }
.ptable td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ptable tbody tr.item:hover td { background: var(--surface-2); }
.ptable .col-check { width: 40px; padding-inline-end: 0; }
.ptable .col-num { text-align: end; }
.ptable th.col-num { text-align: end; }
.ptable tr.is-dirty td { background: color-mix(in srgb, var(--warn-soft) 55%, transparent); }
.ptable tr.is-saved td { animation: flash 1.4s var(--ease); }
.ptable tr.is-saving td { opacity: .6; }
@keyframes flash { 0% { background: var(--down-soft); } 100% { background: transparent; } }

.pname { display: flex; align-items: center; gap: var(--s3); min-width: 220px; }
.thumb { width: 40px; height: 40px; border-radius: 8px; background: var(--surface-3); border: 1px solid var(--line); flex: none; display: grid; place-items: center; color: var(--ink-3); font-size: var(--fs-xs); overflow: hidden; }
.pname b { font-weight: 600; display: block; line-height: 1.5; }
.pname small { color: var(--ink-3); font-size: var(--fs-xs); }
.expander { width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink-2); flex: none; transition: transform .15s var(--ease); }
.expander[aria-expanded="true"] { transform: rotate(-90deg); background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary); }
.sku { direction: ltr; unicode-bidi: isolate; white-space: nowrap; display: inline-block; color: var(--ink-2); font-size: var(--fs-sm); }
.price { font-variant-numeric: tabular-nums; white-space: nowrap; }
.price small { color: var(--ink-3); font-size: var(--fs-xs); margin-inline-start: 3px; }
.price-range { color: var(--ink-2); }

tr.variation td { background: var(--surface-2); border-bottom-style: dashed; }
tr.variation .pname { padding-inline-start: 44px; min-width: 0; }
tr.variation .pname b { font-weight: 500; }
tr.variation td:first-child { box-shadow: inset 3px 0 0 var(--primary-line); }
.var-tools { display: flex; align-items: center; gap: var(--s2); padding: 6px var(--s3) 6px 0; }

.pricecell { display: flex; align-items: center; gap: 6px; }
.pricecell .input { width: 128px; height: 32px; }
.pricecell .input.is-changed { border-color: var(--warn); background: var(--warn-soft); }
.method-btn { height: 32px; padding-inline: 8px; border: 1px dashed var(--line-strong); background: transparent; border-radius: var(--r-sm); font-size: var(--fs-xs); color: var(--ink-2); white-space: nowrap; }
.method-btn:hover { background: var(--surface-3); }
.method-btn[data-method="percent"], .method-btn[data-method="wholesale"], .method-btn[data-method="dependent"] { border-style: solid; border-color: var(--primary-line); background: var(--primary-soft); color: var(--primary); }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

tr.editor td { background: var(--surface-2); padding: 0; border-bottom: 2px solid var(--primary-line); }
.editor-box { padding: var(--s4) var(--s5); display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: var(--s5); }
.editor-fields { display: flex; flex-direction: column; gap: var(--s3); }
.editor-fields .fields { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end; }
.editor-fields .field { width: 180px; }
.calc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s2); }
.calc-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); font-size: var(--fs-sm); color: var(--ink-2); }
.calc-row b { white-space: nowrap; font-size: var(--fs-md); color: var(--ink); font-variant-numeric: tabular-nums; }
.calc-result { display: flex; justify-content: space-between; align-items: baseline; padding-top: var(--s2); border-top: 1px dashed var(--line-strong); }
.calc-result b { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }
.calc .warning { display: flex; gap: 8px; padding: 8px 10px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: var(--fs-sm); }
.formula { font-size: var(--fs-sm); color: var(--ink-3); }

.table-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); flex-wrap: wrap; }

/* chart */
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-tip { position: absolute; pointer-events: none; padding: 6px 10px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg); font-size: var(--fs-xs); white-space: nowrap; display: none; z-index: 2; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.line-price { fill: none; stroke: var(--primary); stroke-width: 2.2; stroke-linejoin: round; }
.area-price { fill: var(--primary); opacity: .09; }
.pt { fill: var(--surface); stroke: var(--primary); stroke-width: 2; }

.meta-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
.meta-strip div { display: flex; flex-direction: column; }
.meta-strip small { color: var(--ink-3); font-size: var(--fs-sm); }
.meta-strip b { font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }

.rules-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s5); align-items: start; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree ul { list-style: none; margin: 0; padding-inline-start: 22px; border-inline-start: 1px dashed var(--line-strong); margin-inline-start: 8px; }
.tree li { padding: 3px 0; }

.ds-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s5); }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.swatch { border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; font-size: var(--fs-xs); }
.swatch i { display: block; height: 36px; }
.swatch span { display: block; padding: 4px 6px; color: var(--ink-2); direction: ltr; text-align: end; }

/* ---------- 8. Responsive ---------- */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(4n) { border-inline-end: 1px solid var(--line); }
  .stat:nth-child(2n) { border-inline-end: 0; }
  .stat:nth-last-child(-n+4) { border-block-end: 1px solid var(--line); }
  .stat:nth-last-child(-n+2) { border-block-end: 0; }
  .rules-layout { grid-template-columns: 1fr; }
  .col-secondary { display: none; }            /* tablet: SKU + wholesale move into the row editor */
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 70; width: min(300px, 86vw); translate: 100% 0; transition: translate .22s var(--ease); box-shadow: var(--shadow-pop); }
  [dir="ltr"] .sidebar { translate: -100% 0; }
  .sidebar.open { translate: 0 0; }
  .btn.menu-btn { display: inline-flex; }
  .page { padding: var(--s4); }
  .topbar { padding-inline: var(--s4); }
  .editor-box { grid-template-columns: 1fr; }
  .user-chip .name { display: none; }
  .global-search .kbd { display: none; }
}
@media (max-width: 720px) {
  .fresh-legend { grid-template-columns: repeat(2, 1fr); }
  .meta-strip { grid-template-columns: 1fr; }
  .toolbar .select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .ptable tr.item td.is-empty { display: none; }
  .pricecell { min-width: 0; }
  .pricecell .input { min-width: 0; }
  .toolbar .search { max-width: none; flex-basis: 100%; }

  /* table -> cards */
  .table-wrap { overflow: visible; }
  .panel { overflow-x: clip; }
  table.ptable, .ptable tbody, .ptable tr, .ptable td { display: block; width: 100%; }
  .ptable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .ptable tr.item { position: relative; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 2px var(--s3); }
  .ptable tr.item td { border: 0; padding: 4px 0; background: transparent !important; width: auto; min-width: 0; }
  .pname { min-width: 0; }
  .ptable tr.item td::before { content: attr(data-label); display: block; font-size: var(--fs-xs); color: var(--ink-3); }
  .ptable tr.item td.col-name { grid-column: 1 / -1; padding-inline-start: 28px; }
  .ptable tr.item td.col-name::before, .ptable tr.item td.col-check::before, .ptable tr.item td.col-actions::before { display: none; }
  .ptable tr.item td.col-check { position: absolute; inset-inline-start: var(--s4); top: var(--s4); width: auto; padding: 0; }
  .ptable tr.item td.col-actions { grid-column: 1 / -1; }
  .ptable tr.item td.col-secondary { display: block; }
  .ptable .col-num { text-align: start; }
  .ptable tr.variation { margin-inline-start: var(--s4); border-inline-start: 3px solid var(--primary-line); background: var(--surface-2); }
  tr.variation .pname { padding-inline-start: 0; }
  tr.editor td { border: 0; }
  .pricecell .input { flex: 1; width: auto; }
  .row-actions { justify-content: flex-start; }
  .stat .v { font-size: var(--fs-lg); }
  .toasts { inset-inline: var(--s3); inset-block-end: var(--s3); }
  .toast { max-width: none; }
}

/* ---------- 9. Auth (login / error pages) ---------- */
.sprite { position: absolute; }
.auth-body { min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s4); }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: var(--s8) var(--s6); display: flex; flex-direction: column; gap: var(--s4); }
.auth-card form { display: flex; flex-direction: column; gap: var(--s4); }
.auth-brand { display: flex; align-items: center; gap: var(--s3); font-weight: 700; font-size: var(--fs-lg); }
.auth-sub { margin-top: calc(var(--s2) * -1); font-size: var(--fs-sm); }
.auth-submit { height: 42px; margin-top: var(--s1); }
.auth-foot { display: flex; gap: 6px; align-items: flex-start; }
.auth-error { text-align: center; align-items: center; }
.error-code { font-size: 3.5rem; font-weight: 700; color: var(--ink-3); line-height: 1.2; }
.input-ltr { direction: ltr; text-align: left; }
.input-group .input { flex: 1; min-width: 0; }
.input-group { display: flex; gap: var(--s2); align-items: center; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-sm); font-size: var(--fs-sm); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.nav .nav-item { display: flex; align-items: center; gap: var(--s3); padding: 8px var(--s3); border-radius: var(--r-sm); color: var(--ink-3); font-weight: 500; }
.nav .nav-item.is-soon { opacity: .55; cursor: not-allowed; }

/* ---------- 10. Utilities and page-level pieces (no inline styles: the CSP forbids them) ---------- */
[hidden] { display: none !important; }
.small { font-size: var(--fs-sm); }
.row.between { justify-content: space-between; }
.row.end { align-items: flex-end; }
.gap-2 { gap: var(--s2); } .gap-3 { gap: var(--s3); }
.w-150 { width: 150px; }
.select-narrow { width: auto; min-width: 130px; }
.modal-sm { width: min(460px, 100%); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--s5); align-items: start; }
.col-stack { display: flex; flex-direction: column; gap: var(--s5); }
.col-stack.tight { gap: var(--s3); }
.sticky-panel { position: sticky; top: calc(var(--topbar-h) + 16px); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-ok { background: var(--down-soft); color: var(--down); }
.bell-dot { position: absolute; top: 6px; inset-inline-end: 6px; min-width: 16px; height: 16px; padding-inline: 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }
.menu-end { inset-inline-end: 0; top: 40px; }
.menu-notif { inset-inline-end: 0; top: 40px; width: 320px; max-height: 60vh; overflow: auto; }
.menu-notif .n-item { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.menu-notif .n-item:last-child { border-bottom: 0; }
.menu-notif .n-item b { display: block; }
.logbox { margin: 0; max-height: 260px; overflow: auto; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; color: var(--ink-2); }
.picklist { border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); max-height: 220px; overflow: auto; }
.picklist button { display: block; width: 100%; text-align: start; padding: 7px 10px; border: 0; background: none; border-bottom: 1px solid var(--line); }
.picklist button:hover { background: var(--surface-2); }
.picklist small { color: var(--ink-3); }
.progress { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s var(--ease); }
.bars i { transition: height .3s var(--ease); }
#ptable.hide-wholesale .c-wholesale, #ptable.hide-age .c-age { display: none; }
.toolbar .field { min-width: 150px; }
.toolbar .field > label { font-size: var(--fs-xs); }
.tag-empty { color: var(--ink-3); }
.err-row td { color: var(--danger); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.gap-1 { gap: 4px; }
.w-260 { width: 260px; } .w-170 { width: 170px; }
.plain { font-family: inherit; white-space: normal; }
.warning-err { background: var(--danger-soft) !important; color: var(--danger) !important; }
.field .picklist { position: absolute; z-index: 30; inset-inline: 0; top: 100%; box-shadow: var(--shadow-pop); }
.field { position: relative; }
.chart-wrap .empty { padding: var(--s6); }

/* ---------- 11. Marketer panel (mobile-first) ---------- */
.mkt-app { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.mkt-topbar {
  position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: var(--s3);
  padding-inline: var(--s4); background: var(--surface); border-bottom: 1px solid var(--line);
}
.mkt-topbar .title { font-weight: 700; font-size: var(--fs-lg); }
.mkt-main { flex: 1; padding: var(--s4); padding-bottom: calc(72px + var(--s4)); max-width: 720px; margin: 0 auto; width: 100%; }
.mkt-bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mkt-bottom-nav a, .mkt-bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 4px 6px;
  color: var(--ink-3); font-size: 11px; border: 0; background: none; position: relative;
}
.mkt-bottom-nav a[aria-current="page"] { color: var(--primary); font-weight: 650; }
.mkt-bottom-nav .icon { width: 22px; height: 22px; }
.mkt-bottom-nav .fab {
  margin-top: -22px; width: 46px; height: 46px; border-radius: 50%; background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; align-self: center; box-shadow: 0 4px 14px rgba(15,110,120,.4);
}
.mkt-bottom-nav .fab .icon { width: 24px; height: 24px; }

.mkt-search { position: relative; margin-bottom: var(--s4); }
.mkt-search input { padding-inline-start: 36px; height: 42px; }
.mkt-search .icon { position: absolute; inset-inline-start: 11px; top: 50%; translate: 0 -50%; color: var(--ink-3); }

.p-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3);
  display: flex; gap: var(--s3); align-items: center; margin-bottom: var(--s3);
}
.p-card .thumb { width: 48px; height: 48px; flex: none; }
.p-card .info { min-width: 0; flex: 1; }
.p-card .info b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-card .info small { color: var(--ink-3); }
.p-card .price { text-align: end; flex: none; }
.p-card .price b { display: block; font-size: var(--fs-lg); color: var(--primary); font-variant-numeric: tabular-nums; }
.p-card .price small { color: var(--ink-3); font-size: var(--fs-xs); }
.p-card.is-expandable { cursor: pointer; }
.p-card .chev { color: var(--ink-3); flex: none; }

.q-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4);
  margin-bottom: var(--s3); display: flex; flex-direction: column; gap: 6px;
}
.q-card .top { display: flex; justify-content: space-between; align-items: baseline; }
.q-card .top b { font-size: var(--fs-lg); }
.q-card .muted-row { color: var(--ink-3); font-size: var(--fs-sm); display: flex; justify-content: space-between; }
.q-card .actions { display: flex; gap: var(--s2); margin-top: var(--s2); }
.q-card .actions .btn { flex: 1; }

.line-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3); margin-bottom: var(--s3); }
.line-card .top { display: flex; justify-content: space-between; gap: var(--s2); align-items: flex-start; }
.line-card .name { font-weight: 600; flex: 1; min-width: 0; }
.line-card .sub { color: var(--ink-3); font-size: var(--fs-xs); margin-top: 2px; }
.line-card .grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-top: var(--s3); }
.line-card .grid .field { width: auto; }
.line-card .qty-stepper { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; height: 36px; }
.line-card .qty-stepper button { width: 34px; height: 100%; border: 0; background: var(--surface); font-size: 16px; }
.line-card .qty-stepper input { border: 0; width: 100%; text-align: center; height: 100%; background: var(--surface); }
.line-card .profit { margin-top: var(--s2); font-size: var(--fs-sm); display: flex; justify-content: space-between; padding-top: var(--s2); border-top: 1px dashed var(--line-strong); }
.line-card .profit b { color: var(--down); }
.line-card .remove { color: var(--danger); background: none; border: 0; font-size: var(--fs-xs); }

.editor-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4); margin-bottom: var(--s4); }
.editor-section h3 { margin-bottom: var(--s3); }
.sticky-footer-bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line);
  padding: var(--s3) var(--s4); padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px));
  display: flex; gap: var(--s3); align-items: center; box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
.sticky-footer-bar .total { flex: 1; }
.sticky-footer-bar .total b { display: block; font-size: var(--fs-lg); color: var(--primary); }
.sticky-footer-bar .total small { color: var(--ink-3); }
.add-item-box { display: flex; gap: var(--s2); }
.add-item-box .field { flex: 1; position: relative; }

.logo-preview { display: flex; align-items: center; gap: var(--s3); }
.logo-preview img { max-height: 60px; max-width: 160px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; padding: 4px; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

@media (min-width: 720px) {
  .mkt-bottom-nav { display: none; }
  .mkt-main { padding-bottom: var(--s4); }
  .mkt-app { flex-direction: row; }
  .mkt-side {
    width: 220px; flex: none; background: var(--surface); border-inline-end: 1px solid var(--line);
    display: flex; flex-direction: column; padding: var(--s4) var(--s3); gap: 2px; min-height: 100vh; position: sticky; top: 0;
  }
  .mkt-side a, .mkt-side button.mkt-side-new {
    display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s3); border-radius: var(--r-sm); color: var(--ink-2); font-weight: 500; border: 0; background: none; text-align: start; width: 100%;
  }
  .mkt-side a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
  .mkt-side-new { background: var(--primary) !important; color: var(--primary-ink) !important; margin-top: var(--s3); }
  .mkt-topbar.is-desktop-hidden { display: none; }
  .mkt-main { max-width: 900px; margin: 0; padding: var(--s6); }
}
@media (max-width: 719px) {
  .mkt-side { display: none; }
}

/* toasts never block taps: container is click-through, only the toast itself is interactive.
   On the marketer panel they slide in from the TOP so they can't cover the bottom bars. */
.toasts { pointer-events: none; }
.toast { pointer-events: auto; }
.mkt .toasts { inset-block-end: auto; inset-block-start: 60px; inset-inline: var(--s3); align-items: stretch; }
.mkt .toast { max-width: none; }
.no-bottom-nav .mkt-main { padding-bottom: calc(96px + var(--s4)); }
@media (min-width: 720px) { .mkt .toasts { inset-inline-start: auto; inset-inline-end: var(--s5); width: 360px; inset-inline-end: var(--s5); } }

/* classes replacing inline styles (CSP: style-src 'self') */
.mkt-side-brand { margin-bottom: var(--s4); }
.mkt-side-logout { margin-top: auto; }
.mkt-side-logout .btn { width: 100%; }
.mkt-content { flex: 1; min-width: 0; }
.mkt-page-head { margin-bottom: var(--s4); }
.mkt-page-head p { margin: 0; }
.mkt-pager { border: 0; justify-content: center; }
.mb-3 { margin-bottom: var(--s3); } .mt-4 { margin-top: var(--s4); }
.textarea { height: auto; padding-block: 8px; }
.p-children { margin-inline-start: 16px; }
.btn-danger-text { color: var(--danger); }
.mkt-bottom-nav .fab { flex: none; width: 52px; height: 52px; padding: 0; margin-inline: var(--s2); }
