.stats-page {
  min-height: 100vh;
  padding: 14px 18px 28px;
  background: var(--bg);
}

.stats-shell {
  width: min(1320px, 100%);
  margin: 0;
  padding: 0 0 34px;
  display: grid;
  gap: 14px;
}

.stats-heading-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stats-panel {
  width: 100%;
  display: grid;
  gap: 14px;
  padding: 12px 14px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 14px 38px rgba(23, 32, 27, 0.07);
}

.stats-panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.stats-panel-header h3 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.1;
}

.stats-panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.25;
}

.stats-icon-button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.stats-icon-button:hover,
.stats-icon-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.stats-icon-button:disabled {
  opacity: 0.48;
  cursor: default;
}

.stats-icon-button:disabled:hover {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--muted-strong);
}

.stats-icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stats-panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stats-period-field {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.stats-period-field::after {
  content: "";
  position: absolute;
  right: 10px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  color: var(--muted-strong);
  pointer-events: none;
  transform: translateY(-2px) rotate(45deg);
}

.stats-period-select {
  appearance: none;
  -webkit-appearance: none;
  height: 28px;
  min-width: 92px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font: inherit;
  font-size: 11px;
  font-weight: 400;
  line-height: 26px;
  cursor: pointer;
  outline: none;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.stats-period-select:hover,
.stats-period-select:focus {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.stats-metric-select {
  min-width: 84px;
}

.stats-period-field:has(.stats-period-select:hover)::after,
.stats-period-field:has(.stats-period-select:focus)::after {
  color: var(--accent);
}

.stats-chart-wrap {
  position: relative;
  height: 288px;
  min-width: 0;
  background: #ffffff;
  overflow: visible;
}

.stats-chart {
  width: 100%;
  height: 100%;
  display: block;
  shape-rendering: crispEdges;
}

.stats-axis {
  stroke: #c9d3cb;
  stroke-width: 1;
}

.stats-grid {
  stroke: #e1e7e2;
  stroke-width: 1;
}

.stats-label {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.stats-bar {
  fill: #8fb8b5;
}

.stats-bar-orders {
  fill: #8fb8b5;
}

.stats-bar-profit {
  fill: #d4c49c;
}

.stats-bar-day {
  fill: #efdba2;
}

.stats-bar-night {
  fill: #aeb7c2;
}

.stats-line {
  fill: none;
  stroke-width: 1.25;
  stroke-linecap: square;
  stroke-linejoin: miter;
  opacity: 0.68;
  vector-effect: non-scaling-stroke;
  transition:
    opacity 120ms ease,
    stroke-width 120ms ease;
}

.stats-line.is-hidden {
  opacity: 0;
}

.stats-line.is-hovered {
  opacity: 1;
  stroke-width: 2.8;
}

.stats-line-profit {
  stroke-dasharray: 4 4;
}

.stats-point {
  opacity: 0.78;
  transition: opacity 120ms ease;
}

.stats-point.is-hidden {
  opacity: 0;
}

.stats-point.is-hovered {
  opacity: 1;
}

.stats-hit {
  fill: transparent;
  cursor: crosshair;
}

.stats-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  background: rgba(255, 255, 255, 0.58);
}

.stats-empty[hidden] {
  display: none;
}

.stats-legend {
  min-height: 25px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 400;
}

.stats-legend-compact {
  min-height: 18px;
}

.stats-legend button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: color 120ms ease;
}

.stats-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.stats-legend button.is-disabled {
  color: var(--muted-soft);
  text-decoration: none;
}

.stats-legend button.is-hovered {
  color: var(--ink);
}

.stats-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 999px;
  background: currentColor;
  box-shadow: inset 0 0 0 1px rgba(23, 32, 27, 0.12);
}

.stats-dot-day {
  background: #efdba2;
}

.stats-dot-night {
  background: #aeb7c2;
}

.stats-dot-orders {
  background: #8fb8b5;
}

.stats-dot-profit {
  background: #d4c49c;
}

.stats-legend button.is-disabled .stats-dot {
  background: transparent !important;
  box-shadow: inset 0 0 0 1px var(--muted-soft);
}

.stats-tooltip {
  position: fixed;
  z-index: 40;
  max-width: 260px;
  padding: 7px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  box-shadow: 0 12px 32px rgba(23, 32, 27, 0.14);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.35;
  pointer-events: none;
}

.stats-tooltip strong {
  display: block;
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 900;
}

.stats-tooltip-table {
  display: grid;
  grid-template-columns: max-content 3ch max-content;
  column-gap: 10px;
  row-gap: 2px;
  align-items: baseline;
}

.stats-tooltip-table-daily {
  grid-template-columns: max-content max-content;
  column-gap: 12px;
}

.stats-tooltip-name {
  min-width: 0;
}

.stats-tooltip-count,
.stats-tooltip-value,
.stats-tooltip-money {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats-table-panel {
  gap: 10px;
}

.stats-table-wrap {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.stats-table {
  width: 100%;
  min-width: 820px;
  table-layout: fixed;
  border-collapse: collapse;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.25;
}

.stats-table th,
.stats-table td {
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-table th:first-child,
.stats-table td:first-child {
  width: 22%;
  text-align: left;
}

.stats-table th:not(:first-child),
.stats-table td:not(:first-child) {
  width: 13%;
}

.stats-table th {
  color: var(--muted);
  font-weight: 650;
}

.stats-table tbody tr:last-child td {
  border-bottom: 0;
}

.stats-table tbody tr,
.stats-table tfoot tr {
  transition:
    background 120ms ease,
    color 120ms ease;
}

.stats-table tbody tr:hover,
.stats-table tbody tr.is-hovered {
  background: var(--surface-soft);
}

.stats-table tbody tr:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -2px;
}

.stats-table tbody tr {
  cursor: pointer;
}

.stats-table tbody tr.is-disabled {
  color: var(--muted-soft);
}

.stats-table tbody tr.is-disabled .stats-vehicle-name,
.stats-table tbody tr.is-disabled .stats-vehicle-type {
  color: var(--muted-soft);
}

.stats-table tbody tr.is-disabled .stats-dot {
  background: transparent !important;
  box-shadow: inset 0 0 0 1px var(--muted-soft);
}

.stats-table tfoot td {
  border-top: 1px solid var(--line-strong);
  border-bottom: 0;
  color: var(--ink);
  font-weight: 750;
}

.stats-sort-button {
  min-height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.stats-sort-button::after {
  content: "";
  display: inline-block;
  width: 10px;
  color: var(--muted-strong);
  text-align: right;
}

.stats-sort-button.is-sorted.asc::after {
  content: "↑";
}

.stats-sort-button.is-sorted.desc::after {
  content: "↓";
}

.stats-vehicle-cell {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.stats-vehicle-meta {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.stats-vehicle-name {
  color: var(--ink);
}

.stats-vehicle-type {
  color: var(--muted);
  font-size: 10px;
}

.stats-muted-value {
  color: var(--muted-soft);
}

@media (max-width: 760px) {
  .stats-page {
    padding: 10px;
  }

  .stats-shell {
    gap: 12px;
    padding-bottom: 20px;
  }

  .stats-heading-actions {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .stats-panel {
    gap: 12px;
    padding: 12px;
    box-shadow: none;
  }

  .stats-panel-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
  }

  .stats-panel-header h3 {
    font-size: 14px;
  }

  .stats-panel-header p {
    font-size: 11px;
  }

  .stats-panel-actions {
    justify-self: end;
    justify-content: flex-end;
  }

  .stats-period-select {
    height: 34px;
    min-width: 112px;
    font-size: 12px;
    line-height: 32px;
  }

  .stats-icon-button {
    width: 34px;
    height: 34px;
  }

  .stats-chart-wrap {
    height: 240px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stats-chart-wrap::-webkit-scrollbar {
    display: none;
  }

  .stats-chart {
    min-width: 520px;
  }

  .stats-legend {
    align-items: flex-start;
    gap: 8px 10px;
    font-size: 10px;
  }

  .stats-legend button,
  .stats-legend span {
    min-height: 24px;
  }
}

@media (max-width: 380px) {
  .stats-chart-wrap {
    height: 220px;
  }

  .stats-chart {
    min-width: 480px;
  }
}
