:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --text: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #888);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --danger: #d9534f;
  --success: #4caf50;
  --radius: 12px;
  /* Apothecary brand accent (fixed — used to feature a priority payment method) */
  --brand-gold: #C9A84C;
  --brand-gold-hover: #DFC06A;
  --brand-black: #111111;
}

/* Seasonal shop themes (System → Branding → Shop theme, admin-picked — not
   date-automatic). Mini App only, set via body[data-theme] in app.js's boot().
   A configured brand accent colour (loadBrand) is applied as an inline style
   on :root and always wins over --button/--link here, so the brand stays
   recognisable while the background/surface colours carry the season. */
body[data-theme="christmas"] {
  --bg: #0f2e1d; --secondary-bg: #15402a; --text: #f3f3f3; --hint: #bcd9c7;
  --button: #c8102e; --button-text: #ffffff; --link: #e6c200;
}
body[data-theme="halloween"] {
  --bg: #170b22; --secondary-bg: #241334; --text: #f1e9ff; --hint: #b79ed6;
  --button: #ff7518; --button-text: #170b22; --link: #ff9e45;
}
body[data-theme="easter"] {
  --bg: #fff7ec; --secondary-bg: #fdecd8; --text: #4a3626; --hint: #9c8469;
  --button: #7fb3d5; --button-text: #ffffff; --link: #5b8fb0;
}
body[data-theme="valentines"] {
  --bg: #fff0f3; --secondary-bg: #ffdde4; --text: #4a1620; --hint: #a66775;
  --button: #e63950; --button-text: #ffffff; --link: #c81d3d;
}

/* Falling particle effect for Christmas (snowflakes) / Halloween (pumpkins).
   Built in JS (startParticles in app.js) as plain emoji spans inside one
   overlay, appended once in boot(). Fixed + pointer-events:none so it never
   intercepts taps; sits above page content but below the lock screen (1000)
   and the referral modal (900). */
.particle-overlay {
  position: fixed; inset: 0; z-index: 50; overflow: hidden; pointer-events: none;
}
.particle {
  position: absolute; top: -10%; line-height: 1;
  animation-name: particle-fall; animation-timing-function: linear; animation-iteration-count: infinite;
  will-change: transform;
}
@keyframes particle-fall {
  from { transform: translateY(-10vh) translateX(0) rotate(0deg); }
  to   { transform: translateY(110vh) translateX(var(--drift, 0px)) rotate(360deg); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}
#app { display: flex; flex-direction: column; min-height: 100vh; }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--secondary-bg);
}
#view-title { margin: 0; font-size: 18px; font-weight: 600; }
.icon-btn { background: none; border: none; color: var(--link); font-size: 22px; cursor: pointer; position: relative; padding: 4px 8px; }
.badge-count {
  position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px;
  background: var(--danger); color: #fff; border-radius: 8px; font-size: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px; font-weight: 700;
}

#content { flex: 1; padding: 12px 16px 90px; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--bg); border-top: 1px solid var(--secondary-bg);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1; background: none; border: none; color: var(--hint);
  font-size: 11px; padding: 8px 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 20px; }
.tab.active { color: var(--link); }

.card { background: var(--secondary-bg); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card.clickable { cursor: pointer; }
.card.clickable:active { opacity: 0.7; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row + .row { margin-top: 4px; }
.muted { color: var(--hint); font-size: 13px; }
.bold { font-weight: 600; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.pending_payment { background: #ffe0b2; color: #8a5200; }
.badge.payment_confirmed, .badge.processing { background: #bbdefb; color: #0d47a1; }
.badge.dispatched { background: #c8e6c9; color: #1b5e20; }
.badge.delivered { background: #a5d6a7; color: #1b5e20; }
.badge.cancelled, .badge.refunded { background: #ffcdd2; color: #b71c1c; }
.badge.sale { background: #ffe0b2; color: #8a5200; }
.badge.out { background: #ffcdd2; color: #b71c1c; }
.badge.stock { background: var(--secondary-bg); color: var(--text); }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.chip { flex: 0 0 auto; padding: 6px 12px; border-radius: 20px; border: none; background: var(--secondary-bg); color: var(--text); font-size: 13px; cursor: pointer; }
.chip.active { background: var(--button); color: var(--button-text); }

input, select, textarea {
  width: 100%; padding: 10px; border-radius: 8px; font-size: 15px;
  border: 1px solid var(--hint); background: var(--bg); color: var(--text);
}
label { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--hint); }

button.primary, button.danger, button.secondary {
  border: none; border-radius: 10px; padding: 12px 14px; font-size: 15px; cursor: pointer; font-weight: 600; width: 100%;
}
button.primary { background: var(--button); color: var(--button-text); }
button.danger { background: var(--danger); color: #fff; }
button.secondary { background: var(--secondary-bg); color: var(--text); }
button:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row button { width: auto; flex: 1; }

.search-bar { margin-bottom: 10px; }
.loading, .empty { text-align: center; color: var(--hint); padding: 40px 0; }
.error { color: var(--danger); text-align: center; padding: 20px 0; }
.hidden { display: none !important; }
h2 { font-size: 17px; margin: 0 0 12px; }
.section-title { font-size: 13px; text-transform: uppercase; color: var(--hint); margin: 18px 0 8px; letter-spacing: 0.5px; }
.kv { display: flex; justify-content: space-between; padding: 4px 0; }
.kv span:first-child { color: var(--hint); }
a { color: var(--link); }

/* product cards */
.price { font-weight: 700; color: var(--text); }
.strike { text-decoration: line-through; color: var(--hint); font-weight: 400; margin-right: 6px; }

/* quantity stepper */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--button); color: var(--button-text); font-size: 18px; cursor: pointer;
}
.stepper span { min-width: 22px; text-align: center; font-weight: 600; }

/* sticky checkout bar */
.checkout-bar {
  position: fixed; bottom: 56px; left: 0; right: 0; z-index: 9;
  padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--secondary-bg);
}
.checkout-bar button { width: 100%; }

.banner { background: var(--button); color: var(--button-text); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }

/* One card holds both the sale and shipping progress rows (when both are
   showing) instead of each getting its own card — two full stacked cards
   read as cluttered for what's otherwise two short lines of information. */
.progress-card { background: var(--secondary-bg); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.progress-bar-row + .progress-bar-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(127, 127, 127, 0.15); }
.progress-bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.progress-bar-track { background: rgba(127, 127, 127, 0.25); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar-fill { background: var(--button); height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.progress-bar-row.unlocked .progress-bar-fill { background: var(--success); }
.progress-bar-row.unlocked .progress-bar-label { color: var(--success); font-weight: 600; margin-bottom: 0; }
.copy-field {
  display: flex; align-items: center; gap: 8px; background: var(--secondary-bg);
  border-radius: 8px; padding: 10px; word-break: break-all; font-family: monospace; font-size: 13px; margin: 6px 0;
}
.copy-field button { width: auto; flex: 0 0 auto; padding: 6px 10px; font-size: 13px; }

.opt {
  display: flex; align-items: center; gap: 10px; padding: 15px 16px;
  background: var(--secondary-bg); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer;
  font-size: 16px; font-weight: 600; line-height: 1.35;
}
.opt.selected { outline: 2px solid var(--button); }
.opt .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--hint); flex: 0 0 auto; }
.opt.selected .dot { background: var(--button); border-color: var(--button); }

/* Featured / prioritised payment method — brand gold accent, pops in both themes */
.opt.featured {
  border: 2px solid var(--brand-gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.22);
}
.opt.featured.selected { outline-color: var(--brand-gold); }
.opt.featured .dot { border-color: var(--brand-gold); }
.opt.featured.selected .dot { background: var(--brand-gold); border-color: var(--brand-gold); }
.opt .badge {
  margin-left: auto; flex: 0 0 auto;
  background: var(--brand-gold); color: var(--brand-black);
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}

/* Password lock screen */
.lock-overlay { position: fixed; inset: 0; z-index: 1000; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.lock-card { width: 100%; max-width: 360px; text-align: center; }
.lock-card h2 { margin: 8px 0; }
.lock-card input { margin: 12px 0; text-align: center; width: 100%; box-sizing: border-box; }
.lock-card .lock-err { color: var(--danger); min-height: 1.2em; }

/* In-app modal (referral welcome) */
.modal-overlay { position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { width: 100%; max-width: 380px; max-height: 90vh; overflow-y: auto; background: var(--bg); color: var(--text); border-radius: var(--radius); padding: 18px 16px; }
.modal-card .section-title { margin-top: 12px; }
.steps { margin: 6px 0 10px; padding-left: 22px; }
.steps li { margin: 6px 0; }
