/* ============================================================================
   CodeBoost - DataBundlesHub (MTN) widgets  (DESIGN S13; behaviour in js/dbh.js)

   .dbh-elig    eligibility box under the recipient field (checking / eligible / not eligible / blocked /
                held order / couldn't check / check the number), height-animated open and close
   .dbh-speed   delivery estimate: chip (.dbh-speed-chip) or panel (.dbh-speed-panel); the pulse dot only
                while the reading is fresh
   .dbh-track   per-order tracker card: headline + status pill, Placed > Pending > Processing > Completed,
                amber hold panel (Verifying), rose attention panel, notes, live footer (only while polling)

   Rules: every class is dbh- prefixed; colours come from the theme tokens (codeboost-ui.css) with fallbacks;
   light is the default, [data-theme="dark"] is handled; on a storefront (always light) --brand is the
   agent's accent and the steps follow it; holds are calm amber, completed emerald, attention rose.
   Nothing here touches .cb-main / .cb-content / .cb-ft-* (iOS PWA rule) and no Tailwind is needed.
   ========================================================================== */

.dbh-elig,
.dbh-speed,
.dbh-track {
  --dbh-text: var(--text, #0d1526);
  --dbh-muted: var(--text-muted, #46556e);
  --dbh-faint: var(--text-faint, #66748f);
  --dbh-surface: var(--bg-elevated, #ffffff);
  --dbh-line: var(--card-border, rgba(15, 30, 60, 0.09));
  --dbh-brand: var(--brand, #2f6bff);
  --dbh-ok: #10b981;
  /* light-theme inks dark enough for small bold text on any page background (WCAG AA 4.5:1 with margin) */
  --dbh-ok-ink: #065f46;
  --dbh-warn: #f59e0b;
  --dbh-warn-ink: #92400e;
  --dbh-bad: #f43f5e;
  --dbh-bad-ink: #be123c;
  --dbh-info: #3b82f6;
  --dbh-info-ink: #1d4ed8;
  --dbh-neutral: #64748b;
  --dbh-neutral-ink: var(--text-muted, #46556e);
  --dbh-ease: var(--ease, cubic-bezier(0.22, 1, 0.36, 1));
  --dbh-tap: var(--ease-tap, cubic-bezier(0.34, 1.4, 0.64, 1));
  --dbh-fast: var(--dur-fast, 0.16s);
  --dbh-base: var(--dur-base, 0.26s);
}
[data-theme="dark"] .dbh-elig,
[data-theme="dark"] .dbh-speed,
[data-theme="dark"] .dbh-track {
  --dbh-text: var(--text, #f3f6fc);
  --dbh-muted: var(--text-muted, #9fb0c9);
  --dbh-faint: var(--text-faint, #8493ad);
  --dbh-surface: var(--bg-elevated, #0c1322);
  --dbh-line: var(--card-border, rgba(255, 255, 255, 0.11));
  --dbh-ok-ink: #34d399;
  --dbh-warn-ink: #fbbf24;
  --dbh-bad-ink: #fb7185;
  --dbh-info-ink: #93c5fd;
  --dbh-neutral: #94a3b8;
  --dbh-neutral-ink: var(--text-muted, #9fb0c9);
}

.dbh-elig p, .dbh-speed p, .dbh-track p { margin: 0; }
/* the tracker's persistent status node for screen readers (visually hidden) */
.dbh-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
/* the eligibility box holds keyboard focus only while "Check again" is being redrawn: no ring for that */
.dbh-elig:focus { outline: none; }
.dbh-ico { width: 1.05rem; height: 1.05rem; flex: none; display: block; }
.dbh-ico-sm { width: 0.85rem; height: 0.85rem; flex: none; display: block; }
.dbh-ico-xs { width: 0.7rem; height: 0.7rem; flex: none; display: block; }
.dbh-ico-sm, .dbh-ico-xs { stroke-width: 2.6; }

/* ---------------------------------------------------------------------------
   Eligibility box
   The page gives an empty element; .is-open grows it (grid rows 0fr -> 1fr) so the field below moves
   smoothly instead of jumping.
   --------------------------------------------------------------------------- */
.dbh-elig {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  transition: grid-template-rows var(--dbh-base) var(--dbh-ease), margin-top var(--dbh-base) var(--dbh-ease);
}
.dbh-elig.is-open { grid-template-rows: 1fr; margin-top: 0.6rem; }
.dbh-elig-in { min-height: 0; overflow: hidden; }

.dbh-elig-card {
  --tone: var(--dbh-neutral);
  --ink: var(--dbh-neutral-ink);
  display: flex;
  align-items: flex-start;
  gap: 0.68rem;
  padding: 0.72rem 0.8rem 0.74rem;
  border-radius: 0.95rem;
  background: color-mix(in srgb, var(--tone) 7%, var(--dbh-surface));
  border: 1px solid color-mix(in srgb, var(--tone) 24%, transparent);
  transition: background var(--dbh-base) var(--dbh-ease), border-color var(--dbh-base) var(--dbh-ease);
}
.dbh-elig-card[data-state="checking"] { --tone: var(--dbh-neutral); --ink: var(--dbh-text); }
/* checking is not a verdict: neutral box, only the spinner carries the brand (a store's accent may be green or red) */
.dbh-elig-card[data-state="checking"] .dbh-elig-ico { color: var(--dbh-brand); }
.dbh-elig-card[data-state="eligible"] { --tone: var(--dbh-ok); --ink: var(--dbh-ok-ink); }
.dbh-elig-card[data-state="not_eligible"],
.dbh-elig-card[data-state="held_order"] { --tone: var(--dbh-warn); --ink: var(--dbh-warn-ink); }
.dbh-elig-card[data-state="blocked"],
.dbh-elig-card[data-state="invalid"] { --tone: var(--dbh-bad); --ink: var(--dbh-bad-ink); }

.dbh-elig-ico {
  flex: none;
  width: 1.95rem;
  height: 1.95rem;
  border-radius: 0.68rem;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: color-mix(in srgb, var(--tone) 15%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 14%, transparent);
}
.dbh-elig-ico.is-spin .dbh-ico { animation: dbh-spin 0.85s linear infinite; }
.dbh-spin-track { opacity: 0.22; }
.dbh-elig-body { flex: 1; min-width: 0; padding-top: 0.06rem; }
.dbh-elig-title { font-size: 0.8rem; font-weight: 800; line-height: 1.3; letter-spacing: -0.005em; color: var(--ink); }
.dbh-elig-msg { margin-top: 0.14rem !important; font-size: 0.76rem; line-height: 1.48; color: var(--dbh-muted); overflow-wrap: anywhere; }
.dbh-elig-again {
  margin-top: 0.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  padding: 0.36rem 0.75rem 0.36rem 0.6rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--tone) 30%, var(--dbh-line));
  background: var(--dbh-surface);
  color: var(--dbh-text);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--dbh-fast) var(--dbh-tap), border-color var(--dbh-base) var(--dbh-ease), box-shadow var(--dbh-base) var(--dbh-ease);
}
.dbh-elig-again:hover { border-color: color-mix(in srgb, var(--dbh-brand) 45%, var(--dbh-line)); }
.dbh-elig-again:active { transform: scale(0.96); }
.dbh-elig-again:focus-visible { outline: 2px solid var(--dbh-brand); outline-offset: 2px; }
.dbh-elig-again .dbh-ico-sm { color: var(--ink); stroke-width: 2.2; }

/* ---------------------------------------------------------------------------
   Delivery speed: chip + panel
   --------------------------------------------------------------------------- */
.dbh-speed-chip,
.dbh-speed-panel { --tone: var(--dbh-neutral); --ink: var(--dbh-neutral-ink); }
.dbh-speed-chip[data-tone="ok"],
.dbh-speed-panel[data-tone="ok"] { --tone: var(--dbh-ok); --ink: var(--dbh-ok-ink); }
.dbh-speed-chip[data-tone="warn"],
.dbh-speed-panel[data-tone="warn"] { --tone: var(--dbh-warn); --ink: var(--dbh-warn-ink); }
.dbh-speed-chip[data-tone="bad"],
.dbh-speed-panel[data-tone="bad"] { --tone: var(--dbh-bad); --ink: var(--dbh-bad-ink); }

.dbh-speed-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  padding: 0.32rem 0.72rem 0.32rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  /* a solid base: the chip sits straight on the page (storefront, desktop wallet tray), so a transparent tint
     would let the page colour decide the text contrast */
  background: color-mix(in srgb, var(--tone) 11%, var(--dbh-surface));
  border: 1px solid color-mix(in srgb, var(--tone) 24%, transparent);
  vertical-align: middle;
}
.dbh-speed-chip-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbh-speed-chip .dbh-ico-sm { stroke-width: 2.2; }

.dbh-pulse {
  position: relative;
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--tone);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--tone) 18%, transparent);
}
.dbh-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--tone);
  animation: dbh-ping 1.9s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.dbh-speed-panel {
  position: relative;
  overflow: hidden;
  padding: 0.85rem 0.95rem 0.9rem;
  border-radius: 1.15rem;
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--tone) 10%, transparent), transparent 60%),
    var(--dbh-surface);
  border: 1px solid color-mix(in srgb, var(--tone) 20%, var(--dbh-line));
  box-shadow: var(--elev-1, 0 1px 3px -1px rgba(30, 50, 100, 0.1), 0 8px 20px -14px rgba(30, 50, 100, 0.18));
}
.dbh-speed-row { display: flex; align-items: flex-start; gap: 0.72rem; }
.dbh-speed-ico {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.8rem;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 16%, transparent);
}
.dbh-speed-ico .dbh-ico { width: 1.15rem; height: 1.15rem; }
.dbh-speed-panel[data-live] .dbh-speed-ico .dbh-ico { fill: color-mix(in srgb, var(--tone) 22%, transparent); }
.dbh-speed-main { flex: 1; min-width: 0; }
.dbh-speed-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display, inherit);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--dbh-text);
}
.dbh-speed-sentence { margin-top: 0.2rem !important; font-size: 0.78rem; line-height: 1.48; color: var(--dbh-muted); }
.dbh-speed-evidence {
  margin-top: 0.7rem !important;
  display: flex;
  align-items: flex-start;
  gap: 0.42rem;
  padding: 0.5rem 0.65rem;
  border-radius: 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  background: color-mix(in srgb, var(--tone) 8%, transparent);
  font-variant-numeric: tabular-nums;
}
.dbh-speed-evidence .dbh-ico-sm { margin-top: 0.1rem; }
.dbh-speed-note { margin-top: 0.6rem !important; font-size: 0.68rem; line-height: 1.45; color: var(--dbh-faint); }

/* ---------------------------------------------------------------------------
   Order tracker
   --------------------------------------------------------------------------- */
.dbh-track {
  --tone: var(--dbh-warn);
  --ink: var(--dbh-warn-ink);
  --step: var(--dbh-brand);
  position: relative;
  padding: 1rem 1rem 0.95rem;
  border-radius: 1.25rem;
  background: var(--dbh-surface);
  border: 1px solid var(--dbh-line);
  box-shadow: var(--elev-1, 0 1px 3px -1px rgba(30, 50, 100, 0.1), 0 8px 20px -14px rgba(30, 50, 100, 0.18));
  color: var(--dbh-text);
  text-align: left;
}
.dbh-track.is-flat { padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.dbh-track[data-tone="pending"] { --tone: var(--dbh-warn); --ink: var(--dbh-warn-ink); }
.dbh-track[data-tone="processing"] { --tone: var(--dbh-info); --ink: var(--dbh-info-ink); }
.dbh-track[data-tone="hold"] { --tone: var(--dbh-warn); --ink: var(--dbh-warn-ink); }
.dbh-track[data-tone="ok"] { --tone: var(--dbh-ok); --ink: var(--dbh-ok-ink); --step: var(--dbh-ok); }
.dbh-track[data-tone="bad"] { --tone: var(--dbh-bad); --ink: var(--dbh-bad-ink); }

.dbh-track-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.dbh-track-titles { min-width: 0; flex: 1; }
.dbh-track-headline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display, inherit);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.012em;
  color: var(--dbh-text);
  overflow-wrap: anywhere;
}
.dbh-track-meta {
  margin-top: 0.22rem !important;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.4rem;
  row-gap: 0.1rem;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--dbh-muted);
}
.dbh-sep { color: var(--dbh-faint); }
.dbh-num, .dbh-code { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.dbh-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.7rem; }

.dbh-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  margin-top: 0.08rem;
  padding: 0.28rem 0.66rem 0.28rem 0.56rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  color: color-mix(in srgb, var(--tone) 52%, var(--dbh-text));
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 18%, transparent);
}
.dbh-pill-dot { width: 0.42rem; height: 0.42rem; border-radius: 999px; background: var(--tone); flex: none; }
.dbh-pill.is-live .dbh-pill-dot { animation: dbh-blink 1.6s ease-in-out infinite; }
.dbh-head-dot { width: 0.55rem; height: 0.55rem; border-radius: 999px; background: var(--tone); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 18%, transparent); }
.dbh-head-dot.is-live { animation: dbh-blink 1.6s ease-in-out infinite; }

/* Placed > Pending > Processing > Completed */
.dbh-steps {
  list-style: none;
  margin: 1.05rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.dbh-step {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}
/* connector from the previous dot to this one */
.dbh-step + .dbh-step::before {
  content: "";
  position: absolute;
  top: calc(0.69rem - 1.5px);
  right: calc(50% + 0.95rem);
  left: calc(-50% + 0.95rem);
  height: 3px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--dbh-text) 10%, transparent);
}
.dbh-step.is-done + .dbh-step::before,
.dbh-step.is-done + .dbh-step.is-active::before { background: var(--step); }
.dbh-step.is-done + .dbh-step.is-bad::before { background: color-mix(in srgb, var(--dbh-bad) 55%, transparent); }
.dbh-step-dot {
  position: relative;
  z-index: 1;
  width: 1.38rem;
  height: 1.38rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--dbh-surface);
  border: 2px solid color-mix(in srgb, var(--dbh-text) 16%, transparent);
  transition: background var(--dbh-base) var(--dbh-ease), border-color var(--dbh-base) var(--dbh-ease);
}
.dbh-step.is-done .dbh-step-dot { background: var(--step); border-color: var(--step); box-shadow: 0 4px 10px -5px color-mix(in srgb, var(--step) 70%, transparent); }
.dbh-step.is-active .dbh-step-dot { border-color: var(--step); background: color-mix(in srgb, var(--step) 12%, var(--dbh-surface)); }
.dbh-step.is-active .dbh-step-dot::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--step);
}
.dbh-step.is-active .dbh-step-dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 999px;
  border: 2px solid var(--step);
  animation: dbh-ring 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.dbh-step.is-bad .dbh-step-dot { background: var(--dbh-bad); border-color: var(--dbh-bad); }
.dbh-step-lbl {
  margin-top: 0.42rem;
  max-width: 100%;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--dbh-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dbh-step.is-done .dbh-step-lbl,
.dbh-step.is-active .dbh-step-lbl { color: var(--dbh-text); }
.dbh-step.is-bad .dbh-step-lbl { color: var(--dbh-bad-ink); }
.dbh-step-at { margin-top: 0.12rem; font-size: 0.62rem; font-weight: 600; line-height: 1.2; color: var(--dbh-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }

.dbh-track-copy { margin-top: 0.85rem !important; font-size: 0.84rem; line-height: 1.52; color: var(--dbh-muted); overflow-wrap: anywhere; }

/* hold (amber) and attention (rose) panels */
.dbh-panel {
  --p: var(--dbh-warn);
  --p-ink: var(--dbh-warn-ink);
  margin-top: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.8rem 0.85rem 0.85rem;
  border-radius: 1rem;
  background: color-mix(in srgb, var(--p) 8%, var(--dbh-surface));
  border: 1px solid color-mix(in srgb, var(--p) 24%, transparent);
}
.dbh-panel--bad { --p: var(--dbh-bad); --p-ink: var(--dbh-bad-ink); }
.dbh-panel-ico {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 0.7rem;
  display: grid;
  place-items: center;
  color: var(--p-ink);
  background: color-mix(in srgb, var(--p) 15%, transparent);
}
.dbh-panel-copy { flex: 1; min-width: 0; padding-top: 0.08rem; font-size: 0.82rem; line-height: 1.55; color: var(--dbh-text); overflow-wrap: anywhere; }

/* notes: released (good news) / delayed */
.dbh-note {
  margin-top: 0.75rem !important;
  display: flex;
  align-items: flex-start;
  gap: 0.48rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.8rem;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--dbh-muted);
  background: color-mix(in srgb, var(--dbh-text) 4.5%, transparent);
}
.dbh-note .dbh-ico-sm { margin-top: 0.12rem; stroke-width: 2.2; }
.dbh-note.is-good { color: var(--dbh-ok-ink); background: color-mix(in srgb, var(--dbh-ok) 10%, transparent); }

/* live footer (only while polling) */
.dbh-foot {
  margin-top: 0.85rem !important;
  padding-top: 0.75rem;
  border-top: 1px dashed color-mix(in srgb, var(--dbh-text) 12%, transparent);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--dbh-faint);
}
.dbh-track.is-flat .dbh-foot { border-top-style: solid; }
.dbh-foot-dot {
  position: relative;
  flex: none;
  margin-top: 0.27rem;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--step);
}
.dbh-foot-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--step);
  animation: dbh-ping 2.2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* a completion that happens while watching */
.dbh-track.is-pop .dbh-step:last-child .dbh-step-dot { animation: dbh-pop 0.5s var(--dbh-tap) both; }
.dbh-track.is-pop .dbh-step:last-child .dbh-step-dot .dbh-ico-xs path { stroke-dasharray: 24; stroke-dashoffset: 24; animation: dbh-draw 0.4s 0.2s var(--dbh-ease) forwards; }

/* ---------------------------------------------------------------------------
   Motion
   --------------------------------------------------------------------------- */
@keyframes dbh-spin { to { transform: rotate(360deg); } }
@keyframes dbh-ping { 0% { transform: scale(1); opacity: 0.55; } 75%, 100% { transform: scale(2.7); opacity: 0; } }
@keyframes dbh-ring { 0% { transform: scale(1); opacity: 0.5; } 70%, 100% { transform: scale(1.75); opacity: 0; } }
@keyframes dbh-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes dbh-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes dbh-draw { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .dbh-elig, .dbh-elig-card, .dbh-elig-again, .dbh-step-dot { transition: none; }
  .dbh-pulse::after, .dbh-foot-dot::after, .dbh-step.is-active .dbh-step-dot::after { animation: none; display: none; }
  .dbh-pill.is-live .dbh-pill-dot, .dbh-head-dot.is-live, .dbh-elig-ico.is-spin .dbh-ico { animation: none; }
  .dbh-track.is-pop .dbh-step:last-child .dbh-step-dot,
  .dbh-track.is-pop .dbh-step:last-child .dbh-step-dot .dbh-ico-xs path { animation: none; stroke-dashoffset: 0; }
}
