/* ============================================
   Cards & Dashboard
   ============================================ */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing-unit) * 2.5);
}

.drive-history {
  display: flex;
  flex-direction: column;
}

.drive-history h3 {
  margin-bottom: var(--spacing-xl);
}

.view-all-link {
  margin: var(--spacing-xl) auto 0;
  text-align: center;
  padding-top: var(--spacing-lg);
  max-width: 350px;
}

.view-all-link .button {
  width: 100%;
  min-height: 48px;
}

.empty-state {
  text-align: center;
  padding: var(--spacing-3xl) var(--spacing-lg);
  color: var(--color-text-light);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.tooltip-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
  color: var(--color-text-light);
  transition: color var(--duration-fast) ease;
}

@media (hover: hover) {
  .tooltip-trigger:hover {
    color: var(--color-primary);
  }
}

.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + var(--spacing-sm));
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--color-text);
  color: var(--color-surface);
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--border-radius-sm);
  font-size: 0.8125rem;
  font-weight: 400;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--duration-fast) ease, visibility var(--duration-fast) ease, transform var(--duration-fast) ease;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  max-width: 280px;
  white-space: normal;
  text-align: center;
  line-height: 1.4;
}

.tooltip-trigger:active::after {
  opacity: 1;
  visibility: visible;
}

@media (hover: hover) {
  .tooltip-trigger:hover::after {
    opacity: 1;
    visibility: visible;
  }
}

/* Mobile Card Styles */
@media (max-width: 768px) {
  .dashboard {
    gap: calc(var(--spacing-unit) * 2);
  }

  .drive-history {
    padding: 0;
    border-radius: 0;
    background-color: transparent;
    border: none;
    box-shadow: none;
  }

  .view-all-link {
    display: none;
  }

  .empty-state {
    padding: calc(var(--spacing-unit) * 2.5) var(--spacing-lg);
    font-size: 0.875rem;
  }
}

@media (max-width: 480px) {
  .tooltip-trigger::after {
    max-width: 200px;
    font-size: 0.75rem;
    padding: calc(var(--spacing-unit) * 0.625) var(--spacing-lg);
  }
}

/* ============================================
   Dashboard redesign — layout
   ============================================ */
.dashboard-greeting { margin-bottom: var(--spacing-xl); }
.dashboard-greeting-title,
.page-header-title { font-family: var(--font-display); font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; color: var(--color-text); margin: 0; }
.dashboard-greeting-date,
.page-header-subtitle { font-size: .9rem; color: var(--color-text-light); font-weight: 600; margin: 4px 0 0; }

.dashboard-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-xl);
}
@media (min-width: 769px) {
  .dashboard-summary {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    align-items: stretch;
  }
}

/* ---- Hero ---- */
.dash-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--border-radius-lg);
  padding: calc(var(--spacing-unit) * 1.75) calc(var(--spacing-unit) * 1.875);
  overflow: hidden;
  color: #fff;
  background: var(--hero-gradient);
  border: 1px solid var(--hero-border);
  box-shadow: var(--hero-shadow);
  font-feature-settings: "tnum" 1;
}
.dash-hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 55%;
  pointer-events: none;
  background: var(--hero-horizon);
}
.dash-hero > * { position: relative; z-index: 1; }

.dash-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--spacing-lg);
}
.dash-hero-number { font-family: var(--font-display); font-size: 4.4rem; font-weight: 800; line-height: .82; letter-spacing: -.02em; }
.dash-hero-caption { font-size: .82rem; color: rgba(255,255,255,.72); font-weight: 600; margin-top: 10px; }

.dash-hero-finish { text-align: right; flex-shrink: 0; }
.dash-hero-finish-label { font-size: .64rem; letter-spacing: .06em; text-transform: uppercase; color: rgba(255,255,255,.58); font-weight: 700; }
.dash-hero-finish-value { font-size: 1.1rem; font-weight: 800; margin-top: 4px; white-space: nowrap; }

.dash-hero-progress {
  height: 9px; border-radius: 6px;
  background: rgba(255,255,255,.16);
  display: flex; overflow: hidden;
  margin-top: var(--spacing-xl);
}

/* clip-path rather than width, so the fill costs no layout. Only the dashboard's
   own render opts in — the broadcast replaces this element on every stats change,
   including ones that don't move the bar, and @starting-style would replay the
   whole wipe for each. */
.dash-hero-progress.is-revealing {
  clip-path: inset(0 0 0 0);
  transition: clip-path var(--duration-reveal) var(--ease-out);
}

@starting-style {
  .dash-hero-progress.is-revealing { clip-path: inset(0 100% 0 0); }
}

/* A click navigation renders twice — Turbo paints the cached snapshot first,
   then the response — and each insertion is a new element, so @starting-style
   replays the wipe halfway through the first one. Hold the preview at the start
   position and the wipe runs once, on the render carrying the real figures. */
[data-turbo-preview] .dash-hero-progress.is-revealing {
  clip-path: inset(0 100% 0 0);
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .dash-hero-progress.is-revealing { transition: none; }
}
.dash-hero-bar-day { background: linear-gradient(90deg,#fcd34d,#f59e0b); }
.dash-hero-bar-night { background: linear-gradient(90deg,#a5b4fc,#818cf8); }

.dash-hero-chips {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--spacing-sm); margin-top: var(--spacing-xl);
}
.dash-hero-chip {
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--border-radius-sm);
  padding: 11px 13px;
  backdrop-filter: blur(8px);
}
a.dash-hero-chip {
  color: inherit;
  text-decoration: none;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, transform var(--duration-base) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
@media (hover: hover) {
  a.dash-hero-chip:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.32); }
}
/* Press feedback has to land inside a tap, so it snaps in and eases back out. */
a.dash-hero-chip:active {
  background: rgba(255,255,255,.22);
  transform: scale(.98);
  transition-duration: var(--duration-press);
}
.dash-hero-chip-key { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: rgba(255,255,255,.62); }
.dash-hero-chip-value { display: block; font-size: 1.3rem; font-weight: 800; margin-top: 4px; }
.dash-hero-chip-value small { font-size: .72rem; color: rgba(255,255,255,.6); font-weight: 600; }
.dash-hero-chip.is-day .dash-hero-chip-key { color: #fcd34d; }
.dash-hero-chip.is-night .dash-hero-chip-key { color: #c7d2fe; }

@media (max-width: 768px) {
  .dash-hero-top { flex-direction: column; }
  .dash-hero-number { font-size: 3.5rem; }
  .dash-hero-finish {
    text-align: left; width: 100%;
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid rgba(255,255,255,.14);
  }
  .dash-hero-chips { grid-template-columns: 1fr 1fr; }
}

/* Side-by-side with the activity card: sink progress + chips to the bottom so
   the hero fills the shared row height instead of leaving a gradient gap. */
@media (min-width: 769px) {
  .dash-hero-progress { margin-top: auto; }
}

/* ---- Activity card ---- */
.activity-card {
  display: flex;
  flex-direction: column;
  background: var(--activity-tint), var(--color-surface);
  border: 1px solid var(--activity-tint-border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  font-feature-settings: "tnum" 1;
}
.activity-card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--spacing-lg) calc(var(--spacing-unit) * 1.5) 0;
}
.activity-card-title { font-weight: 700; font-size: 1rem; color: var(--color-text); }
.activity-card-sub { font-size: .78rem; color: var(--color-text-light); font-weight: 600; }

.activity-card-body {
  flex: 1;
  display: flex; flex-direction: column; gap: var(--spacing-lg);
  padding: calc(var(--spacing-unit) * 1.125) calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 1.5);
}
.activity-top { flex: 1; display: flex; gap: calc(var(--spacing-unit) * 1.75); align-items: center; }
.activity-statement { flex: 1; min-width: 0; }
.activity-streak-number {
  font-family: var(--font-display);
  font-size: 5.5rem; font-weight: 800; line-height: .72; letter-spacing: -.02em;
  color: var(--streak-color);
}
.activity-streak-label { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--color-text-light); font-weight: 800; margin-top: 8px; }
.activity-streak-best { font-size: .8rem; color: var(--color-text-light); font-weight: 500; margin-top: 4px; }
.activity-streak-best b { color: var(--color-text-secondary); font-weight: 700; }
.activity-sentence { font-size: .88rem; color: var(--color-text-light); font-weight: 500; margin: 0; line-height: 1.5; white-space: nowrap; }
.activity-sentence b { color: var(--color-text-secondary); font-weight: 700; }

/* Full-width stat-chip row mirroring the hero's chip row for matched weight. */
.activity-ministats { display: flex; gap: var(--spacing-sm); }
.activity-ministat {
  flex: 1; min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  background: var(--color-background);
}
.activity-ministat-key { display: block; font-size: .6rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-light); font-weight: 700; white-space: nowrap; }
.activity-ministat-value { display: block; font-size: 1.05rem; font-weight: 800; color: var(--color-text); margin-top: 3px; white-space: nowrap; }
.activity-ministat-value small { font-size: .7rem; color: var(--color-text-light); font-weight: 600; }

.activity-cal { width: 182px; flex-shrink: 0; }
/* minmax(0, 1fr), not the default 1fr (= minmax(auto, 1fr)): the `auto` floor
   picks up the aspect-ratio cells' intrinsic width, which iOS leaves stale
   after an orientation change — on rotate-back to portrait it inflates the
   columns and pushes the 7th day off-screen. min-width:0 on the cell stops an
   item from spilling its track for the same reason. */
.activity-weekdays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 7px; margin-bottom: 7px; }
.activity-weekdays span { text-align: center; font-size: .6rem; color: var(--color-text-light); font-weight: 700; text-transform: uppercase; }
.activity-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 7px; }
.activity-cell {
  aspect-ratio: 1; border-radius: 7px; min-width: 0;
  background: var(--activity-empty-bg);
  border: 1px solid var(--activity-empty-border);
  cursor: pointer; transition: transform var(--duration-base) var(--ease-out), box-shadow var(--duration-base) ease, filter var(--duration-base) ease;
  /* Past days render as <button> so the grid is keyboard reachable; strip the
     UA button chrome so they look identical to the future-day divs. */
  padding: 0; margin: 0; appearance: none; font: inherit; color: inherit;
}
.activity-cell.state-day { background: var(--activity-day-fill); border-color: var(--recent-badge-day-fg); }
.activity-cell.state-night { background: var(--activity-night-fill); border-color: var(--recent-badge-night-fg); }
/* Night edge, not the sun: the gradient already opens amber, and an amber edge
   made this read as a plain day cell. */
.activity-cell.state-both { background: var(--activity-both-fill); border-color: var(--recent-badge-night-fg); }
.activity-cell.is-today { outline: 2px solid var(--activity-today-ring); outline-offset: 2px; }
.activity-cell.is-future { opacity: .5; cursor: default; }

.activity-legend { display: flex; gap: 13px; justify-content: center; margin-top: var(--spacing-md); font-size: .7rem; color: var(--color-text-light); font-weight: 700; }
.activity-legend span { display: inline-flex; align-items: center; gap: 5px; }
.activity-swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; border: 1px solid transparent; }
.activity-swatch.is-day { background: var(--activity-day-fill); border-color: var(--recent-badge-day-fg); }
.activity-swatch.is-night { background: var(--activity-night-fill); border-color: var(--recent-badge-night-fg); }
.activity-swatch.is-both { background: var(--activity-both-fill); border-color: var(--recent-badge-night-fg); }

@media (hover: hover) {
  /* The shadow only reads on a light surface, and the lift is dropped under
     reduced motion — brightness is what marks the cell in both cases. */
  .activity-cell:not(.is-future):hover {
    transform: scale(1.12);
    box-shadow: var(--shadow-md);
    filter: brightness(1.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  .activity-cell:not(.is-future):hover { transform: none; }
}
@media (max-width: 768px) {
  .activity-top { flex-direction: column; align-items: stretch; gap: var(--spacing-lg); }
  .activity-cal { width: 100%; }
  /* Inline the streak (number beside label) and center it on the narrow card. */
  .activity-streak { display: flex; align-items: center; justify-content: center; gap: var(--spacing-md); }
  .activity-streak-meta .activity-streak-label { margin-top: 0; }
  .activity-sentence { text-align: center; }
}

/* ---- Drive log kind filter ---- */
.kind-filter {
  display: flex;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-xs);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}
.kind-filter-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 var(--spacing-lg);
  border-radius: var(--border-radius-sm);
  font-size: .82rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease, transform var(--duration-base) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
@media (hover: hover) {
  .kind-filter-tab:hover { background: var(--color-border-light); color: var(--color-text); }
}
/* Stands in for the tap highlight suppressed above: on touch :hover never fires,
   so without this the tab has no press feedback at all. */
.kind-filter-tab:active { background: var(--color-border-light); transform: scale(.97); transition-duration: var(--duration-press); }
.kind-filter-tab.is-all.is-active { color: var(--color-white); background: var(--color-primary); }
.kind-filter-tab.is-day.is-active { background: var(--recent-badge-day-bg); color: var(--recent-badge-day-fg); }
.kind-filter-tab.is-night.is-active { background: var(--recent-badge-night-bg); color: var(--recent-badge-night-fg); }
.kind-filter-icon { display: block; }

/* Full width on mobile is the thumb target; on desktop, size to the labels. */
@media (min-width: 769px) {
  .kind-filter { display: inline-flex; }
  .kind-filter-tab { flex: 0 0 auto; }
}

/* ---- Drive rows (shared: dashboard recent drives + full drive log) ---- */
.drive-history-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--spacing-md); }
.drive-history-title { font-weight: 700; font-size: 1rem; margin: 0; }
.view-all-inline { font-size: .8rem; font-weight: 700; color: var(--color-primary); text-decoration: none; }

.drive-list {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--spacing-xs) var(--spacing-sm);
  font-feature-settings: "tnum" 1;
}
.drive-row {
  display: flex; align-items: center; gap: 13px; padding: 11px 12px; border-radius: var(--border-radius-sm);
  background: var(--drive-row-bg, transparent);
  transition: background-color var(--duration-fast) ease, opacity var(--duration-base) ease-out, transform var(--duration-base) ease-out;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.drive-row + .drive-row { border-top: 1px solid var(--color-border-light); }
@media (hover: hover) { .drive-row:hover { background: var(--drive-row-bg-hover, var(--color-background)); } }
/* Without the suppression the browser paints its own tap highlight in the gap
   before the modal opens; the :active tint is what replaces it. */
.drive-row:active { background: var(--drive-row-bg-active, var(--color-border-light)); transition-duration: var(--duration-press); }

/* drive_session_controller holds the submit for this long before deleting. */
.drive-row.fade-out {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

/* Set only on rows the broadcast appends, so the rows already rendered on page
   load don't all animate at once. */
.drive-row.is-entering { animation: driveRowIn var(--duration-base) var(--ease-out) both; }

@keyframes driveRowIn {
  from { opacity: 0; transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  .drive-row.is-entering { animation-name: none; }
}

/* The list renders even when empty so a broadcast has somewhere to land; once
   one does, the empty state is no longer true. */
.drive-list:has(> .drive-row) ~ .empty-state {
  display: none;
}

.drive-row-badge { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.drive-row-badge.is-day { background: var(--recent-badge-day-bg); color: var(--recent-badge-day-fg); }
.drive-row-badge.is-night { background: var(--recent-badge-night-bg); color: var(--recent-badge-night-fg); }
.drive-row-badge.is-mixed { background: var(--recent-badge-mixed-bg); color: var(--recent-badge-mixed-fg); }

.drive-row-main { flex: 1; min-width: 0; }
.drive-row-date { font-weight: 700; font-size: .92rem; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive-row-date-short { display: none; }
.drive-row-sub { font-size: .79rem; color: var(--color-text-light); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.drive-row-duration { text-align: right; flex-shrink: 0; }
.drive-row-duration-label { font-size: .62rem; color: var(--color-text-light); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.drive-row-duration-value { font-weight: 800; font-size: .98rem; color: var(--color-text); white-space: nowrap; }
.drive-row-duration-value .unit { font-size: .72em; color: var(--color-text-light); font-weight: 600; margin-left: 1px; }
@media (min-width: 769px) {
  .drive-row-duration-value { font-size: 1.2rem; }
}

.drive-row-actions { position: relative; display: flex; align-items: center; flex-shrink: 0; }

/* 350px is measured: below it "September 30, 2026" ellipsizes against the row's
   own content. auto-fill, not auto-fit, so two drives keep a card's width. */
@media (min-width: 900px) {
  .drive-list.drive-list-grid:has(> .drive-row) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: var(--spacing-md);
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    /* Inherited rather than set on the row, so the row's own :hover and :active
       still win without being restated at this selector's specificity. A card
       hovering toward the page colour would read as the card dissolving. */
    --drive-row-bg: var(--color-surface);
    --drive-row-bg-hover: var(--card-hover);
    --drive-row-bg-active: var(--card-active);
  }

  .drive-list.drive-list-grid > .drive-row {
    padding: var(--spacing-lg) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
  }
}

@media (max-width: 768px) {
  .drive-row-duration-label { display: none; }
  .drive-row { gap: 10px; padding: 11px 8px; }
  .drive-row-date-full { display: none; }
  .drive-row-date-short { display: inline; }
}
