/* ============================================================
   WrenchIt! Vehicle History Overlay
   Scoped under .history-overlay only. No rule here touches
   any class outside this file's namespace.
   ============================================================ */

/* ---------- Local design tokens ---------- */
.history-overlay {
  --h-bg:            var(--color-background, #f5f6f8);
  --h-surface:       var(--color-surface, #ffffff);
  --h-surface-alt:   #f9fafb;
  --h-text:          var(--color-text, #111827);
  --h-muted:         var(--color-text-muted, #6b7280);
  --h-border:        var(--color-border, #e5e7eb);
  --h-border-strong: #d1d5db;

  --h-primary:       var(--color-primary, #7c3aed);
  --h-primary-dark:  #6d28d9;
  --h-primary-soft:  rgba(124, 58, 237, 0.10);
  --h-primary-ring:  rgba(124, 58, 237, 0.22);

  --h-good:          var(--color-success, #16a34a);
  --h-good-soft:     rgba(22, 163, 74, 0.10);
  --h-warn:          #b8860b;
  --h-warn-soft:     rgba(212, 160, 23, 0.14);
  --h-danger:        var(--color-danger, #dc2626);
  --h-danger-soft:   rgba(220, 38, 38, 0.10);

  --h-radius-lg:     18px;
  --h-radius:        14px;
  --h-radius-sm:     10px;

  --h-shadow-card:
    0 1px 2px rgba(16, 24, 40, 0.04),
    0 1px 3px rgba(16, 24, 40, 0.06);
  --h-shadow-card-hover:
    0 2px 4px rgba(16, 24, 40, 0.05),
    0 8px 20px rgba(16, 24, 40, 0.08);
  --h-shadow-panel:
    0 8px 24px rgba(16, 24, 40, 0.12),
    0 24px 60px rgba(16, 24, 40, 0.18);

  --h-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --h-dur:  200ms;

  position: fixed;
  inset: 0;
  z-index: 4200;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: rgba(17, 24, 39, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  font-family: inherit;
  color: var(--h-text);
  opacity: 0;
  transition: opacity var(--h-dur) var(--h-ease);
}

.history-overlay.history-visible {
  opacity: 1;
}

/* ============================================================
   Panel
   ============================================================ */
.history-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  background: var(--h-bg);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 260ms var(--h-ease);
}
.history-overlay.history-visible .history-panel {
  transform: translateY(0);
}

@media (min-width: 900px) {
  .history-overlay { padding: 24px; }
  .history-panel {
    max-width: 1080px;
    max-height: 92vh;
    border-radius: var(--h-radius-lg);
    box-shadow: var(--h-shadow-panel);
    transform: translateY(0) scale(0.98);
  }
  .history-overlay.history-visible .history-panel {
    transform: translateY(0) scale(1);
  }
}

/* ============================================================
   Header
   ============================================================ */
.history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--h-surface);
  border-bottom: 1px solid var(--h-border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
  flex-shrink: 0;
}

.history-header-text {
  flex: 1;
  min-width: 0;
}
.history-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--h-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--h-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--h-muted);
  cursor: pointer;
  transition: background 150ms var(--h-ease), color 150ms var(--h-ease),
              border-color 150ms var(--h-ease);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.history-icon-btn svg { width: 22px; height: 22px; }
.history-icon-btn:focus-visible {
  outline: none;
  border-color: var(--h-primary);
  box-shadow: 0 0 0 3px var(--h-primary-ring);
}
@media (hover: hover) {
  .history-icon-btn:hover {
    background: rgba(17, 24, 39, 0.05);
    color: var(--h-text);
  }
}

/* ============================================================
   Summary strip
   ============================================================ */
.history-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 14px 18px;
  background: var(--h-surface);
  border-bottom: 1px solid var(--h-border);
  flex-shrink: 0;
}
.history-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  text-align: center;
  padding: 0 6px;
}
.history-summary-item + .history-summary-item {
  border-left: 1px solid var(--h-border);
}
.history-summary-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--h-muted);
}
.history-summary-value {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--h-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media (min-width: 900px) {
  .history-summary { padding: 16px 24px; }
  .history-summary-value { font-size: 18px; }
  .history-summary-label { font-size: 11px; }
}

/* ============================================================
   Body / scroll area
   ============================================================ */
.history-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
}

@media (min-width: 900px) {
  .history-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 20px 24px;
  }
}

/* ============================================================
   Card base
   ============================================================ */
.history-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--h-surface);
  border: 1px solid var(--h-border);
  border-radius: var(--h-radius);
  box-shadow: var(--h-shadow-card);
  animation: history-fade-up 260ms var(--h-ease);
  min-width: 0;
}
@media (hover: hover) {
  .history-card:hover {
    box-shadow: var(--h-shadow-card-hover);
    border-color: var(--h-border-strong);
  }
}

@media (min-width: 900px) {
  .history-card-wide { grid-column: 1 / -1; }
}

/* AI card always full-width */
.history-card-ai { grid-column: 1 / -1; }

/* Semantic colour variants */
.history-card-good {
  border-color: rgba(22, 163, 74, 0.30);
  background: linear-gradient(180deg, var(--h-good-soft), transparent 60%);
}
.history-card-warn {
  border-color: rgba(184, 134, 11, 0.40);
  background: linear-gradient(180deg, var(--h-warn-soft), transparent 60%);
}

/* Card header */
.history-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.history-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: var(--h-primary-soft);
  color: var(--h-primary);
  border-radius: 10px;
}
.history-card-icon svg { width: 18px; height: 18px; }

.history-card-title {
  flex: 1;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--h-muted);
}

.history-card-good .history-card-icon {
  background: var(--h-good-soft);
  color: var(--h-good);
}
.history-card-warn .history-card-icon {
  background: var(--h-warn-soft);
  color: var(--h-warn);
}
.history-card-ai .history-card-icon {
  background: var(--h-warn-soft);
  color: var(--h-warn);
}

/* Loading placeholder inside a card */
.history-card-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--h-muted);
}

/* ============================================================
   Key-value list (Owner Profile, Frequency, etc.)
   ============================================================ */
.history-kv {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
}
.history-kv-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--h-border);
  min-width: 0;
}
.history-kv-row:last-child { border-bottom: none; }
.history-kv-row dt {
  font-size: 12.5px;
  color: var(--h-muted);
  flex: 0 0 auto;
}
.history-kv-row dd {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--h-text);
  text-align: right;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* Small grey line of text under a card */
.history-meta-line {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--h-muted);
  line-height: 1.4;
}

/* ============================================================
   Empty and error states
   ============================================================ */
.history-empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 24px;
  color: var(--h-muted);
}
.history-empty-state p {
  margin: 0 0 8px;
  font-size: 14px;
}
.history-empty-hint {
  font-size: 12.5px !important;
  color: var(--h-muted);
}
.history-empty-error {
  color: var(--h-danger);
}

/* ============================================================
   Warnings
   ============================================================ */
.history-warning-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.history-warning-row {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(184, 134, 11, 0.30);
  border-radius: var(--h-radius-sm);
}
[data-theme="dark"] .history-warning-row {
  background: rgba(255, 255, 255, 0.04);
}
.history-warning-icon {
  flex-shrink: 0;
  color: var(--h-warn);
  display: inline-flex;
  align-items: flex-start;
  padding-top: 1px;
}
.history-warning-icon svg { width: 18px; height: 18px; }
.history-warning-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--h-text);
}
.history-warning-action {
  margin: 4px 0 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--h-muted);
}

/* ============================================================
   Recurring problems
   ============================================================ */
.history-recurring-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-recurring-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  padding: 8px 10px;
  background: var(--h-surface-alt);
  border-radius: var(--h-radius-sm);
  align-items: center;
}
.history-recurring-system {
  grid-column: 1;
  grid-row: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--h-text);
}
.history-recurring-count {
  grid-column: 2;
  grid-row: 1;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--h-primary);
  background: var(--h-primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
}
.history-recurring-dates {
  grid-column: 1 / -1;
  grid-row: 2;
  font-size: 11.5px;
  color: var(--h-muted);
  line-height: 1.4;
}

/* ============================================================
   Horizontal bar list (Job Type Breakdown)
   ============================================================ */
.history-bar-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 2fr) auto;
  gap: 10px;
  align-items: center;
}
.history-bar-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--h-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.history-bar-track {
  height: 8px;
  background: rgba(17, 24, 39, 0.06);
  border-radius: 999px;
  overflow: hidden;
}
[data-theme="dark"] .history-bar-track {
  background: rgba(255, 255, 255, 0.08);
}
.history-bar-fill {
  height: 100%;
  background: var(--h-primary);
  border-radius: 999px;
  transition: width 400ms var(--h-ease);
}
.history-bar-count {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--h-muted);
  text-align: right;
  min-width: 28px;
}

/* ============================================================
   Spend trend
   ============================================================ */
.history-trend-total {
  margin: 0;
  font-size: 13px;
  color: var(--h-muted);
}
.history-trend-total strong {
  color: var(--h-text);
  font-variant-numeric: tabular-nums;
}

.history-trend-chart {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  height: 96px;
  align-items: end;
  padding: 4px 0;
}
.history-trend-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  min-width: 0;
}
.history-trend-bar {
  width: 100%;
  max-width: 22px;
  background: linear-gradient(180deg, var(--h-primary), var(--h-primary-dark));
  border-radius: 4px 4px 2px 2px;
  min-height: 4px;
  transition: height 400ms var(--h-ease);
}
.history-trend-label {
  margin-top: 6px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--h-muted);
  text-transform: uppercase;
}

/* ============================================================
   Upcoming maintenance
   ============================================================ */
.history-upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-upcoming-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  padding: 8px 10px;
  background: var(--h-surface-alt);
  border-radius: var(--h-radius-sm);
}
.history-upcoming-system {
  grid-column: 1;
  grid-row: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--h-text);
}
.history-upcoming-due {
  grid-column: 2;
  grid-row: 1;
  font-size: 12px;
  font-weight: 700;
  color: var(--h-warn);
  background: var(--h-warn-soft);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.history-upcoming-basis {
  grid-column: 1 / -1;
  grid-row: 2;
  font-size: 11.5px;
  color: var(--h-muted);
}

/* ============================================================
   Timeline
   ============================================================ */
.history-timeline-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-timeline-row {
  border: 1px solid var(--h-border);
  border-radius: var(--h-radius-sm);
  overflow: hidden;
  background: var(--h-surface);
}

.history-timeline-summary {
  display: grid;
  grid-template-columns: minmax(90px, auto) minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 120ms var(--h-ease);
}
@media (hover: hover) {
  .history-timeline-summary:hover {
    background: var(--h-surface-alt);
  }
}
.history-timeline-summary:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--h-primary-ring);
}

.history-timeline-date {
  font-size: 12.5px;
  color: var(--h-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.history-timeline-type {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--h-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.history-timeline-amount {
  font-size: 13px;
  font-weight: 700;
  color: var(--h-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.history-timeline-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--h-muted);
  transition: transform 180ms var(--h-ease);
}
.history-timeline-chevron svg { width: 18px; height: 18px; }
.history-timeline-summary[aria-expanded="true"] .history-timeline-chevron {
  transform: rotate(90deg);
}

.history-timeline-details {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--h-border);
  background: var(--h-surface-alt);
  font-size: 13px;
  line-height: 1.5;
  color: var(--h-text);
  animation: history-slide-down 200ms var(--h-ease);
}
.history-timeline-details p {
  margin: 0 0 6px;
}
.history-timeline-details p:last-child {
  margin-bottom: 0;
}
.history-timeline-financials {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 6px;
  font-size: 12.5px;
  color: var(--h-muted);
}
.history-timeline-financials strong {
  color: var(--h-text);
  font-variant-numeric: tabular-nums;
}

.history-show-all {
  align-self: flex-start;
  margin-top: 4px;
}

/* ============================================================
   Buttons (footer + inline)
   ============================================================ */
.history-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.005em;
  border: 1px solid transparent;
  border-radius: var(--h-radius-sm);
  cursor: pointer;
  transition: background 140ms var(--h-ease), color 140ms var(--h-ease),
              border-color 140ms var(--h-ease), transform 100ms var(--h-ease);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.history-btn:active {
  transform: scale(0.98);
}
.history-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--h-primary-ring);
}
.history-btn-primary {
  background: var(--h-primary);
  color: #ffffff;
}
@media (hover: hover) {
  .history-btn-primary:hover { background: var(--h-primary-dark); }
}
.history-btn-secondary {
  background: var(--h-surface);
  color: var(--h-text);
  border-color: var(--h-border);
}
@media (hover: hover) {
  .history-btn-secondary:hover { background: var(--h-surface-alt); }
}

/* ============================================================
   AI card
   ============================================================ */
.history-ai-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--h-border);
  border-radius: 999px;
  color: var(--h-muted);
  cursor: pointer;
  transition: background 140ms var(--h-ease), color 140ms var(--h-ease),
              transform 100ms var(--h-ease);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.history-ai-refresh:active { transform: scale(0.94); }
.history-ai-refresh:focus-visible {
  outline: none;
  border-color: var(--h-primary);
  box-shadow: 0 0 0 3px var(--h-primary-ring);
}
.history-ai-refresh svg { width: 16px; height: 16px; }
@media (hover: hover) {
  .history-ai-refresh:hover {
    background: var(--h-primary-soft);
    color: var(--h-primary);
  }
}

.history-ai-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--h-text);
}
.history-ai-body p {
  margin: 0;
}

.history-ai-footer {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--h-muted);
  font-style: italic;
}

/* ============================================================
   Footer
   ============================================================ */
.history-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--h-surface);
  border-top: 1px solid var(--h-border);
  flex-shrink: 0;
}
@media (min-width: 900px) {
  .history-footer { padding: 14px 24px; }
}

/* ============================================================
   Skeleton
   ============================================================ */
.history-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.history-skel-line {
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    rgba(17, 24, 39, 0.05) 0%,
    rgba(17, 24, 39, 0.09) 50%,
    rgba(17, 24, 39, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: history-skel-pulse 1.4s ease-in-out infinite;
}
.history-skel-lg { height: 22px; width: 60%; }
.history-skel-sm { height: 12px; width: 40%; }

[data-theme="dark"] .history-skel-line {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
}

/* ============================================================
   Spinner
   ============================================================ */
.history-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--h-primary-soft);
  border-top-color: var(--h-primary);
  animation: history-spin 700ms linear infinite;
  flex-shrink: 0;
}

/* ============================================================
   Toast
   ============================================================ */
.history-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 4300;
  max-width: min(88vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(17, 24, 39, 0.96);
  color: #ffffff;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.22);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 180ms var(--h-ease), transform 180ms var(--h-ease);
}
.history-toast.history-toast-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.history-toast-error   { background: rgba(220, 38, 38, 0.97); }
.history-toast-success { background: rgba(22, 163, 74, 0.97); }

/* ============================================================
   Dark mode overrides
   ============================================================ */
[data-theme="dark"] .history-overlay {
  --h-bg:          var(--color-background, #0f172a);
  --h-surface:     var(--color-surface, #1e293b);
  --h-surface-alt: #263548;
  --h-text:        var(--color-text, #f1f5f9);
  --h-muted:       var(--color-text-muted, #94a3b8);
  --h-border:      rgba(255, 255, 255, 0.10);
  --h-border-strong: rgba(255, 255, 255, 0.18);
}
[data-theme="dark"] .history-card {
  background: var(--h-surface);
}
[data-theme="dark"] .history-card-good {
  background: linear-gradient(180deg, rgba(22, 163, 74, 0.10), transparent 60%);
}
[data-theme="dark"] .history-card-warn {
  background: linear-gradient(180deg, rgba(212, 160, 23, 0.10), transparent 60%);
}
[data-theme="dark"] .history-timeline-details {
  background: rgba(255, 255, 255, 0.03);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes history-fade-up {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes history-slide-down {
  0%   { opacity: 0; transform: translateY(-4px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes history-skel-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes history-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .history-overlay,
  .history-panel,
  .history-card,
  .history-btn,
  .history-icon-btn,
  .history-ai-refresh,
  .history-timeline-chevron,
  .history-timeline-details,
  .history-bar-fill,
  .history-trend-bar {
    transition: none !important;
    animation: none !important;
  }
  .history-skel-line,
  .history-spinner {
    animation: none !important;
  }
  .history-btn:active { transform: none; }
  .history-ai-refresh:active { transform: none; }
  .history-timeline-chevron {
    transform: none !important;
  }
}

/* ============================================================
   Small phones
   ============================================================ */
@media (max-width: 380px) {
  .history-header { padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .history-summary { padding: 12px 14px; }
  .history-body { padding: 12px; gap: 10px; }
  .history-card { padding: 14px; }
  .history-card-title { font-size: 12px; }
  .history-card-icon { width: 30px; height: 30px; }
  .history-card-icon svg { width: 16px; height: 16px; }
  .history-summary-value { font-size: 14px; }
  .history-timeline-summary {
    grid-template-columns: minmax(72px, auto) minmax(0, 1fr) auto 16px;
    gap: 6px;
    padding: 8px 10px;
  }
  .history-trend-chart { gap: 2px; }
  .history-trend-label { font-size: 8.5px; }
}