/* stats screens (v0.6): date-range picker, KPI tiles, the sales chart, best sellers, credits & usage.
   Chart colours were checked with the data-viz palette validator (lightness band, chroma, colour-blind separation,
   contrast) against the card surface of each theme: light #FFFFFF, dark #121826. */

:root,
:root[data-theme='light'] {
  --stats-rev: #3B6CF6;   /* revenue: the area and its line */
  --stats-ord: #F1641E;   /* orders: the bars underneath */
}
:root[data-theme='dark'] {
  --stats-rev: #4D7BF3;
  --stats-ord: #E8682B;
}

.is-refreshing { opacity: .62; transition: opacity var(--t-med) var(--ease); }

/* ------------------------------------------------------------- toolbar */
.stats-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; }
.stats-bar__end { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.stats-bar__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stats-bar .section-title h2 { margin: 0; }

.updated { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-xs); font-weight: 700; color: var(--muted); white-space: nowrap; }
.updated__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.updated.is-busy .updated__dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); animation: stats-pulse 1s var(--ease) infinite alternate; }
@keyframes stats-pulse { to { transform: scale(.6); } }

/* --------------------------------------------------------- range picker */
.range-picker { position: relative; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; max-width: 100%; }
.range-picker__seg {
  display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; border-radius: var(--r-sm);
  background: var(--surface-3); border: 1px solid var(--line);
}
.range-picker__seg button {
  height: 32px; padding: 0 12px; border-radius: 8px; font-size: var(--fs-xs); font-weight: 800; color: var(--muted); white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), box-shadow var(--t-fast);
}
.range-picker__seg button:hover { color: var(--ink); }
.range-picker__seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.range-picker__more {
  display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: var(--fs-xs); font-weight: 800; color: var(--ink-2); white-space: nowrap;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
}
.range-picker__more svg { width: 15px; height: 15px; }
.range-picker__more:hover { border-color: var(--line-strong); color: var(--ink); }
.range-picker__more.is-active { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.range-picker__more[aria-expanded='true'] .range-picker__chev { transform: rotate(180deg); }
.range-picker__chev { transition: transform var(--t-fast) var(--ease); }

.range-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; width: min(440px, calc(100vw - 32px));
  display: grid; gap: 14px; padding: 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
}
.range-pop__title { font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.range-pop__months { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; max-height: 196px; overflow-y: auto; padding-right: 2px; }
.range-pop__years { display: flex; flex-wrap: wrap; gap: 3px; }
.range-pop__opt {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 32px; padding: 0 8px; border-radius: 8px;
  font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); white-space: nowrap;
}
.range-pop__years .range-pop__opt { padding: 0 14px; }
.range-pop__opt:hover { background: var(--surface-3); color: var(--ink); }
.range-pop__opt.is-selected { background: var(--brand-soft); color: var(--brand); font-weight: 800; }
.range-pop__opt svg { width: 13px; height: 13px; stroke-width: 3; }
.range-pop__opt--all { border: 1px solid var(--line); }
.range-pop__custom { border-top: 1px solid var(--line-2); padding-top: 12px; }
.range-pop__dates { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.range-pop__dates label { display: grid; gap: 4px; font-size: var(--fs-xs); font-weight: 750; color: var(--muted); min-width: 0; }
.range-pop__dates .input { min-height: 36px; padding: 6px 8px; font-size: var(--fs-sm); }
.range-pop__dates .btn { height: 36px; }
.range-pop__problem { margin: 6px 0 0; color: var(--no-ink); font-size: var(--fs-xs); font-weight: 700; }

/* ----------------------------------------------------------- headings */
.stats-title { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.stats-title h2 { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-xl); letter-spacing: -.01em; }
.stats-title--sm h2 { font-size: var(--fs-lg); }
.stats-title__range {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--line); color: var(--ink-2); font-size: var(--fs-xs); font-weight: 750;
}
.stats-title__range svg { width: 13px; height: 13px; }
.stats-foot { display: flex; align-items: center; gap: 6px; margin: 0; }

/* -------------------------------------------------------------- tiles */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
.stat-grid--compact { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--sp-3); }
.stat {
  --stat-ink: var(--brand); --stat-soft: var(--brand-soft);
  position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; overflow: hidden;
  padding: 16px 18px 15px; border-radius: var(--r-lg); background: var(--surface); border: var(--card-border); box-shadow: var(--shadow-xs);
}
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--stat-ink); opacity: .75; }
.stat--blue { --stat-ink: var(--blue-ink); --stat-soft: var(--blue-soft); }
.stat--violet { --stat-ink: var(--violet-ink); --stat-soft: var(--violet-soft); }
.stat--ok { --stat-ink: var(--ok-ink); --stat-soft: var(--ok-soft); }
.stat--warn { --stat-ink: var(--warn-ink); --stat-soft: var(--warn-soft); }
.stat--no { --stat-ink: var(--no-ink); --stat-soft: var(--no-soft); }
.stat__top { display: flex; align-items: center; gap: 9px; min-width: 0; }
.stat__icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--stat-soft); color: var(--stat-ink); }
.stat__icon svg { width: 15px; height: 15px; }
.stat__label { font-size: var(--fs-sm); font-weight: 750; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat__main { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; min-width: 0; }
.stat__value { font-size: 1.75rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; white-space: nowrap; color: var(--ink); }
.stat__foot { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; line-height: 1.4; }
.stat--hero { grid-column: span 2; background: linear-gradient(135deg, var(--brand-soft), transparent 62%), var(--surface); }
.stat--hero .stat__value { font-size: 3rem; letter-spacing: -.04em; }
.stat-grid--compact .stat { padding: 12px 14px; gap: 6px; }
.stat-grid--compact .stat__value { font-size: 1.3rem; }
.stat-grid--compact .stat__icon { width: 24px; height: 24px; border-radius: 8px; }
.stat-grid--compact .stat__icon svg { width: 13px; height: 13px; }
.stat-grid--compact .stat__label { font-size: var(--fs-xs); }

.delta { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 3px 5px; font-size: .74rem; font-weight: 700; color: var(--muted); line-height: 1.3; }
.delta b { font-weight: 800; }
.delta.is-good { color: var(--ok-ink); }
.delta.is-bad { color: var(--no-ink); }
.delta__arrow { width: 11px; height: 11px; fill: currentColor; flex: none; }
.delta__arrow.is-down { transform: rotate(180deg); }
.delta__vs { color: var(--muted); font-weight: 600; }

.spark { width: 120px; height: 34px; flex: none; overflow: visible; }
.stat:not(.stat--hero) .stat__main { flex-direction: column; align-items: stretch; gap: 6px; }
.stat:not(.stat--hero) .spark { width: 100%; height: 28px; }
.stat-grid--compact .delta__vs { display: none; } /* the line above the tiles names the range they are compared with */
.spark__line { fill: none; stroke: var(--stats-rev); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark__area { fill: var(--stats-rev); opacity: .1; }
.spark__ring, .spark__end { fill: none; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark__ring { stroke: var(--surface); stroke-width: 10; }
.spark__end { stroke: var(--stats-rev); stroke-width: 6; }

.stat-details { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.stat-detail {
  flex: 1 1 150px; display: grid; gap: 1px; align-content: start; padding: 10px 14px; min-width: 0;
  border-radius: var(--r-md); background: var(--surface); border: var(--card-border);
}
.stat-detail span { font-size: var(--fs-xs); font-weight: 700; color: var(--muted); }
.stat-detail b { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-detail small { font-size: .7rem; color: var(--faint); font-weight: 600; overflow-wrap: anywhere; }

.money-src { display: flex; align-items: baseline; gap: 9px; font-size: var(--fs-sm); font-weight: 650; color: var(--muted); }
.money-src.is-estimate { color: var(--warn-ink); }
.money-src__text { margin: 0; min-width: 0; line-height: 1.45; }
.money-src__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; transform: translateY(-1px); }
.money-src__dot.is-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.money-src__sep { color: var(--faint); }
.linkish { padding: 0; border: 0; background: none; color: var(--brand); font: inherit; font-weight: 800; cursor: pointer; }
.linkish:hover { text-decoration: underline; }
.linkish[disabled] { opacity: .6; cursor: progress; text-decoration: none; }

/* -------------------------------------------------------------- chart */
.vchart { position: relative; margin: 0; display: grid; gap: 10px; min-width: 0; }
.vchart__legend { display: flex; gap: 18px; font-size: var(--fs-xs); font-weight: 750; color: var(--ink-2); }
.vchart__key { display: inline-flex; align-items: center; gap: 7px; }
.vchart__key--line::before { content: ''; width: 16px; height: 3px; border-radius: 3px; background: var(--stats-rev); }
.vchart__key--bar::before { content: ''; width: 9px; height: 11px; border-radius: 3px 3px 0 0; background: var(--stats-ord); opacity: .7; }
.vchart__stage { position: relative; min-height: 236px; }
.vchart__svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; border-radius: var(--r-xs); }
.vchart__svg:focus-visible { box-shadow: var(--ring); }
.vchart__grid { stroke: var(--line-2); stroke-width: 1; shape-rendering: crispEdges; }
.vchart__base { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.vchart__tick, .vchart__xlabel { fill: var(--muted); font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; }
.vchart__bar-label { fill: var(--ink-2); font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.vchart__bar { fill: var(--stats-ord); opacity: .45; transition: opacity var(--t-fast); }
.vchart__bar.is-current { opacity: .8; }
.vchart__bar.is-hover { opacity: 1; }
.vchart__stop-top { stop-color: var(--stats-rev); stop-opacity: .26; }
.vchart__stop-bottom { stop-color: var(--stats-rev); stop-opacity: .02; }
.vchart__line { fill: none; stroke: var(--stats-rev); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.vchart__end, .vchart__focus { fill: var(--stats-rev); stroke: var(--surface); stroke-width: 2.5; }
.vchart__peak-dot { fill: var(--surface); stroke: var(--stats-rev); stroke-width: 2; }
.vchart__peak-label { fill: var(--ink-2); font-size: 11.5px; font-weight: 800; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.vchart__cross { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.vchart__hit { fill: transparent; cursor: crosshair; }
.vchart__tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px; display: grid; gap: 4px; padding: 9px 12px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-md);
}
.vchart__tip-date { font-size: .72rem; font-weight: 750; color: var(--muted); white-space: nowrap; }
.vchart__tip-row { display: flex; align-items: center; gap: 7px; font-size: var(--fs-xs); font-weight: 650; color: var(--muted); white-space: nowrap; }
.vchart__tip-row b { color: var(--ink); font-size: .95rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.vchart__tip-row--line::before { content: ''; width: 12px; height: 3px; border-radius: 3px; background: var(--stats-rev); flex: none; }
.vchart__tip-row--bar::before { content: ''; width: 12px; height: 3px; border-radius: 3px; background: var(--stats-ord); flex: none; }
.vchart__empty {
  min-height: 236px; display: grid; place-items: center; align-content: center; gap: 6px; padding: 24px; text-align: center;
  color: var(--ink-2); border: 1px dashed var(--line-strong); border-radius: var(--r-md); background: var(--surface-2);
}
.vchart__empty-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue-ink); }
.vchart__empty-icon svg { width: 20px; height: 20px; }

/* ------------------------------------------------------- best sellers */
.best { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.best__item { display: grid; grid-template-columns: 18px 72px minmax(0, 1fr); gap: 12px; align-items: center; padding: 8px; margin: 0 -8px; border-radius: var(--r-md); transition: background var(--t-fast); }
.best__item:hover { background: var(--surface-2); }
.best__rank { font-size: .78rem; font-weight: 800; color: var(--faint); text-align: center; font-variant-numeric: tabular-nums; }
.best__photo {
  width: 72px; height: 72px; border-radius: 14px; overflow: hidden; display: grid; place-items: center;
  background: var(--surface-3); color: var(--faint); border: 1px solid var(--line);
}
.best__photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.best__photo svg { width: 22px; height: 22px; }
.best__main { display: grid; gap: 3px; min-width: 0; }
.best__title {
  font-size: var(--fs-sm); font-weight: 750; line-height: 1.35; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere;
}
a.best__title:hover { color: var(--brand); text-decoration: none; }
.best__meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: var(--fs-xs); font-weight: 650; color: var(--muted); }
.best__meta b { color: var(--ink); font-weight: 800; }
.best__shop { font-weight: 800; letter-spacing: .04em; }
.best__open { display: inline-flex; align-items: center; gap: 4px; width: fit-content; font-size: var(--fs-xs); font-weight: 800; color: var(--brand); }
.best-empty { display: flex; align-items: center; gap: 10px; padding: 6px 0; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; }
.best-empty svg { width: 18px; height: 18px; flex: none; }

/* ------------------------------------------------- shops, orders, home */
.shop-switch__logo--all { background: linear-gradient(135deg, var(--brand), #C2408C); }
.shop-switch__logo--all svg { width: 18px; height: 18px; }
.orders-status { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.orders-card .card__head { flex-wrap: wrap; }
.orders-mode button { white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.order__money { display: inline-flex; align-items: baseline; gap: 6px; margin-left: auto; }
.stars--low { color: var(--no); }
.stat-grid--today .stat__value { font-size: 2rem; }

.usage { display: grid; gap: 16px; }
.usage__row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.usage__icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); }
.usage__icon svg { width: 16px; height: 16px; }
.usage__icon--ok { background: var(--ok-soft); color: var(--ok-ink); }
.usage__icon--warn { background: var(--warn-soft); color: var(--warn-ink); }
.usage__icon--no { background: var(--no-soft); color: var(--no-ink); }
.usage__text { display: grid; gap: 3px; min-width: 0; }
.usage__text b { font-size: var(--fs-sm); font-weight: 750; }
.usage__text > span { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.usage__text .progress { margin-top: 4px; }
.usage__value { font-size: var(--fs-sm); font-weight: 800; white-space: nowrap; color: var(--ink); }

/* ------------------------------------------------------------ narrow */
@media (max-width: 1240px) {
  .stat-grid--compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-grid--compact .stat:last-child { grid-column: span 2; }
}
@media (max-width: 1100px) {
  .orders-status { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .stat-grid, .stat-grid--compact { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .stat-grid--compact .stat:last-child { grid-column: span 2; }
  .stat { padding: 13px 14px; }
  .stat__value { font-size: 1.3rem; }
  .stat--hero .stat__value { font-size: 2.3rem; }
  .stat-grid--today .stat__value { font-size: 1.45rem; }
  .stat__foot { font-size: .7rem; }
  .stat:not(.stat--hero) .delta__vs { display: none; } /* the tile's title still says what it is compared with */
  .stats-bar { align-items: stretch; }
  .stats-bar__end { margin-left: 0; width: 100%; justify-content: space-between; }
  .range-picker { width: 100%; }
  .range-picker__seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .range-picker__seg button { padding: 0 6px; }
  .range-picker__more { width: 100%; justify-content: center; }
  .range-pop { left: 0; right: auto; width: 100%; }
  .range-pop__months { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .range-pop__dates { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .range-pop__dates .btn { grid-column: span 2; }
  .stat-detail { flex-basis: 40%; }
  .best__item { grid-template-columns: 64px minmax(0, 1fr); }
  .best__rank { display: none; }
  .best__photo { width: 64px; height: 64px; }
}
