/*
 * 电车格局全局样式 — 总览页核心
 * 职责：summary-board、overview-range 时间范围、vehicle-block、metric 指标卡与内嵌趋势图（trend-chart/trend-key/trend-line）。
 * 拆分自原 styles.css 第 321-761 行：规则内容零改动，仅按行切分；级联顺序 = 本文件在 index.html 中的链接顺序。
 * EV 暗色主题适配：按 docs/reskin-guide.md 原位换肤——玻璃卡（配方1）、大数字渐变裁字（配方6）、下拉/快捷范围令牌化（配方3/4）、principal 反白卡改深色辉光英雄卡；未改任何选择器与布局属性。
 */
.summary-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-md);
  align-items: stretch;
}

.metric,
.expense-chart,
.quick-panel,
.vehicle-panel,
.insight-panel,
.ledger-panel,
.sync-panel {
  border-radius: var(--radius-card);
  background: var(--glass);
  backdrop-filter: var(--blur-glass);
  box-shadow: var(--shadow), var(--soft-edge);
}

.overview-range {
  min-width: 0;
  width: min(192px, 100%);
  align-self: center;
  justify-self: end;
  display: block;
  border-radius: var(--control-radius);
  background: transparent;
}

.overview-range.is-open {
  z-index: 12;
}

.overview-range-toggle {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--hairline);
  border-radius: var(--control-radius);
  padding: 6px 10px;
  color: var(--ink);
  background: var(--surface-control);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  align-items: center;
  gap: var(--space-sm);
  text-align: left;
}

.overview-range-toggle .lucide {
  justify-self: center;
  color: var(--muted);
  transition: transform 160ms ease;
}

.overview-range-toggle[aria-expanded="true"] .lucide {
  transform: rotate(180deg);
}

.overview-range-copy {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  align-items: center;
}

.overview-range-copy span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
}

.overview-range-copy strong {
  min-width: 0;
  font-family: "Avenir Next Condensed", "DIN Condensed", "PingFang SC", sans-serif;
  font-size: 1.18rem;
  line-height: 1;
}

.overview-range-copy small {
  display: block;
  min-width: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.12;
  white-space: nowrap;
}

.overview-range.is-period .overview-range-copy {
  grid-template-columns: auto auto;
  column-gap: var(--space-sm);
}

.overview-range.is-period .overview-range-copy > span {
  grid-column: 1;
  grid-row: 1;
}

.overview-range.is-period .overview-range-copy > .overview-range-days {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  font-size: 0.68rem;
}

.overview-range.is-period .overview-range-copy > #overviewRangeMeta {
  grid-column: 1 / -1;
  grid-row: 3;
  white-space: normal;
  text-wrap: balance;
}

.overview-range.is-period .overview-range-copy > strong {
  grid-column: 1 / -1;
  grid-row: 2;
}

.overview-range-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% - var(--space-sm));
  right: var(--space-xl);
  width: min(360px, calc(100% - 48px));
  display: grid;
  gap: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-card);
  background: color-mix(in oklch, var(--canvas-quiet), var(--glass));
  box-shadow: var(--shadow-raise), var(--soft-edge);
}

/* Popovers escape card transforms and backdrop-filter stacking contexts. */
.overview-range-panel[popover] {
  position: fixed;
  inset: auto;
  margin: 0;
  border: 0;
  width: min(360px, calc(100vw - 32px));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.overview-range-panel[popover]:not(:popover-open) {
  display: none;
}

/* Fallback for WebViews without the Popover API. */
.summary-board:has(.overview-range-panel:not([popover]):not([hidden])),
.vehicle-block:has(.overview-range-panel:not([popover]):not([hidden])) {
  position: relative;
  z-index: 30;
}

.overview-custom-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
  align-items: stretch;
}

.range-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: var(--space-sm);
}

.range-options button {
  min-height: 34px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0 var(--space-md);
  color: var(--muted);
  background: var(--glass);
  font-size: var(--type-control-sm);
  font-weight: 800;
}

.range-options button.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.range-error {
  min-height: 1.1em;
  margin: var(--space-xs) 0 0;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 700;
}

.vehicle-block {
  position: relative;
  grid-column: 1 / -1;
  min-height: 128px;
  padding: var(--space-xl) 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-lg);
  background: transparent;
}

.vehicle-heading {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
}

.vehicle-identity {
  flex: 1;
  min-width: 0;
  display: grid;
  align-content: start;
  align-self: start;
  gap: var(--space-xs);
}

/* The illustration and text form one group, centered against the range control. */

.vehicle-mascot {
  flex: 0 0 auto;
  height: 100px;
  width: auto;
  pointer-events: none;
}

.vehicle-mascot {
  --mascot-start: #30b89b;
  --mascot-end: #2099ad;
}

[data-theme="soft-dark"] .vehicle-mascot {
  --mascot-start: #78b2ce;
  --mascot-end: #4c8ea8;
}

[data-theme="dark"] .vehicle-mascot {
  --mascot-start: #58dbc4;
  --mascot-end: #41b9d0;
}

.vehicle-mascot .mascot-stop-a { stop-color: var(--mascot-start); }
.vehicle-mascot .mascot-stop-b { stop-color: var(--mascot-end); }
.vehicle-mascot .mascot-mirrors { fill: var(--mascot-end); }
.vehicle-mascot .mascot-grin { opacity: 0; }

/* Tiny suspension travel reads as driving, without moving the header or tires. */
@media (prefers-reduced-motion: no-preference) {
  .mascot-suspension {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: mascot-drive 1800ms cubic-bezier(0.45, 0, 0.55, 1) infinite;
  }

  .mascot-eyes {
    transform-box: fill-box;
    transform-origin: center;
    animation: mascot-blink 6200ms linear infinite;
  }

  .mascot-mouth {
    transform-box: fill-box;
    transform-origin: center;
    animation: mascot-mouth-lift 8100ms ease-in-out infinite;
  }

  .mascot-smile { animation: mascot-smile 8100ms ease-in-out infinite; }
  .mascot-grin { animation: mascot-grin 8100ms ease-in-out infinite; }

  @keyframes mascot-drive {
    0%, 100% { transform: translateY(0) rotate(-0.25deg) scale(1.004, 0.996); }
    24% { transform: translateY(-2px) rotate(0.15deg) scale(0.997, 1.009); }
    48% { transform: translateY(1px) rotate(0.3deg) scale(1.012, 0.986); }
    72% { transform: translateY(-1px) rotate(-0.15deg) scale(0.999, 1.004); }
  }

  @keyframes mascot-blink {
    0%, 40%, 44%, 47%, 51%, 100% { transform: scaleY(1); }
    42%, 49% { transform: scaleY(0.08); }
  }

  @keyframes mascot-mouth-lift {
    0%, 34%, 66%, 100% { transform: translateY(0) scale(1); }
    44%, 56% { transform: translateY(-0.4px) scale(1.08, 1.03); }
  }

  @keyframes mascot-smile {
    0%, 35%, 65%, 100% { opacity: 1; }
    44%, 56% { opacity: 0; }
  }

  @keyframes mascot-grin {
    0%, 35%, 65%, 100% { opacity: 0; }
    44%, 56% { opacity: 1; }
  }
}

.vehicle-name-label,
.section-heading p,
.metric span,
.field span,
.insight-copy > span {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

.section-heading p {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.section-heading p .lucide {
  width: 15px;
  height: 15px;
}

.vehicle-name-input {
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-family: "Avenir Next Condensed", "DIN Condensed", "PingFang SC", sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}

.vehicle-name-input[readonly] {
  cursor: default;
}

.trend-discovery-hint {
  text-wrap: balance;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.3;
}

.metric {
  min-height: 188px;
  padding: var(--space-lg);
  display: grid;
  align-content: start;
  gap: var(--space-sm);
  overflow: hidden;
  container-type: inline-size;
}

.metric.principal {
  background: linear-gradient(140deg, color-mix(in oklch, var(--surface), var(--green) 16%), color-mix(in oklch, var(--surface), var(--cyan) 8%));
  color: var(--ink);
  box-shadow: var(--shadow), var(--accent-glow);
}

.metric.principal span,
.metric.principal small {
  color: color-mix(in oklch, var(--ink), transparent 14%);
}

.metric strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: "Avenir Next Condensed", "DIN Condensed", "PingFang SC", sans-serif;
  font-size: 2.1rem;
  line-height: 0.92;
  background: var(--text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.01em;
}

.metric small {
  color: var(--muted);
  line-height: 1.28;
}

.metric-trend,
.insight-trend {
  min-width: 0;
  align-self: end;
}

.metric-trend {
  min-height: 58px;
  margin-top: auto;
  padding-top: var(--space-xs);
}

.insight-trend {
  min-height: 42px;
  margin-top: var(--space-xs);
}

.trend-chart {
  position: relative;
  min-width: 0;
  display: grid;
  gap: 3px;
}

.trend-open-button {
  position: absolute;
  z-index: 2;
  inset: 0;
  border: 0;
  border-radius: var(--control-radius);
  padding: 0;
  color: transparent;
  background: transparent;
  cursor: zoom-in;
}

.trend-open-button:focus-visible {
  outline: 2px solid color-mix(in oklch, var(--green), transparent 28%);
  outline-offset: 2px;
}

.trend-key {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px var(--space-sm);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
}

.trend-key span {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.trend-key i {
  width: 10px;
  height: 0;
  border-top: 1.5px solid var(--trend-series-color, var(--green));
}

.trend-key .series-depreciation i,
.trend-key .series-unit-l i {
  border-top-style: dashed;
}

.trend-key .series-running i {
  border-top-style: dotted;
}

.trend-plot {
  position: relative;
  min-width: 0;
}

.trend-svg {
  width: 100%;
  height: 44px;
  display: block;
  overflow: visible;
}

.insight-trend .trend-svg {
  height: 36px;
}

.trend-baseline {
  fill: none;
  stroke: var(--hairline-strong);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.trend-line {
  fill: none;
  stroke: var(--trend-series-color, var(--green));
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.trend-end {
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1px solid var(--surface);
  border-radius: 50%;
  background: var(--trend-series-color, var(--green));
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.trend-dot {
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1px solid var(--surface);
  border-radius: 50%;
  background: var(--trend-series-color, var(--green));
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.series-total,
.series-primary {
  --trend-series-color: var(--green);
}

.series-depreciation,
.series-unit-l {
  --trend-series-color: var(--amber);
}

.series-running {
  --trend-series-color: var(--blue);
}

.series-unit-kwh {
  --trend-series-color: var(--green);
}

.trend-line.series-depreciation,
.trend-line.series-unit-l {
  stroke-dasharray: 5 3;
}

.trend-line.series-running {
  stroke-dasharray: 1 3;
}

.metric.principal .trend-key {
  color: color-mix(in oklch, var(--ink), transparent 18%);
}

.metric.principal .trend-baseline {
  stroke: var(--hairline-strong);
}

.metric.principal .series-total {
  --trend-series-color: var(--ink);
}

.metric.principal .trend-end {
  border-color: var(--surface);
}

.trend-state {
  min-height: 42px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: var(--space-xs);
  align-items: end;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 500;
  line-height: 1.25;
}

.trend-state::before {
  content: "";
  width: 100%;
  border-top: 1px dashed var(--hairline-strong);
}

.metric.principal .trend-state {
  color: var(--muted);
}

.metric.principal .trend-state::before {
  border-color: var(--hairline);
}

