/* Cards, statistics, timeline, chart, tables, states, tooltip. */

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.card__title { font-size: var(--fs-16); font-weight: 500; }
.card__sub { margin-top: 2px; font-size: var(--fs-12); color: var(--text-secondary); }
.card__actions { display: flex; align-items: center; gap: var(--sp-2); }
.card__body { padding: var(--sp-5); }
.card__body--flush { padding: 0; }

/* ── Statistic cards ──────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(212px, 1fr));
  gap: var(--sp-4);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.stat--accent { border-top-color: var(--accent); }
.stat--cheap { border-top-color: var(--band-very-cheap); }
.stat--expensive { border-top-color: var(--band-very-expensive); }
.stat--muted { border-top-color: var(--border); }

.stat__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.stat__label {
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.stat__value {
  font-family: var(--font-mono);
  font-size: var(--fs-28);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat__value--sm { font-size: var(--fs-22); }
.stat__unit { font-size: var(--fs-13); font-weight: 400; color: var(--text-secondary); }

.stat__meta { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }
.stat__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--fs-12);
  color: var(--text-secondary);
}
.stat__row dt { color: var(--text-muted); }
.stat__row dd { margin: 0; font-family: var(--font-mono); color: var(--text); }
.stat__note { font-size: var(--fs-12); color: var(--text-muted); }

/* ── Band pill: colour plus text, never colour alone ──────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 1px var(--sp-2);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill--negative { background: var(--band-negative); color: var(--band-negative-text); }
.pill--very-cheap { background: var(--band-very-cheap); color: var(--band-very-cheap-text); }
.pill--cheap { background: var(--band-cheap); color: var(--band-cheap-text); }
.pill--average { background: var(--band-average); color: var(--band-average-text); }
.pill--expensive { background: var(--band-expensive); color: var(--band-expensive-text); }
.pill--very-expensive { background: var(--band-very-expensive); color: var(--band-very-expensive-text); }
.pill--outline { background: var(--surface-sunken); border-color: var(--border); color: var(--text-secondary); }

/* ── Legend ───────────────────────────────────────────────────────────────── */
.legend__title {
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.legend__list { display: flex; flex-direction: column; gap: var(--sp-1); margin-top: var(--sp-2); }
.legend__list li {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-12);
  color: var(--text-secondary);
}
.legend__range { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.legend__note { margin-top: var(--sp-2); font-size: var(--fs-11); color: var(--text-muted); line-height: 1.35; }

.swatch {
  flex: 0 0 auto;
  width: 12px; height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 2px;
}
.swatch--negative { background: var(--band-negative); background-image: var(--stripes); }
.swatch--very-cheap { background: var(--band-very-cheap); }
.swatch--cheap { background: var(--band-cheap); }
.swatch--average { background: var(--band-average); }
.swatch--expensive { background: var(--band-expensive); }
.swatch--very-expensive { background: var(--band-very-expensive); }

/* ── Timeline ─────────────────────────────────────────────────────────────── */
:root {
  --stripes: repeating-linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.28) 0 4px,
    rgba(255, 255, 255, 0) 4px 8px
  );
}

.day-panel { display: flex; flex-direction: column; gap: var(--sp-4); }

.timeline { display: flex; flex-direction: column; gap: var(--sp-3); }

.timeline__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: var(--fs-12);
  color: var(--text-secondary);
}
.timeline__stats { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.timeline__stat strong { font-family: var(--font-mono); font-weight: 600; color: var(--text); }

/* Horizontal scroll container keeps segments legible on narrow screens. */
.timeline__scroll { overflow-x: auto; overflow-y: hidden; padding-bottom: var(--sp-1); }
/* Top padding reserves room for the "Now" flag, which would otherwise be clipped
   by the scroll container. */
.timeline__inner { position: relative; min-width: var(--timeline-min-w); padding-top: 16px; }

.timeline__track {
  position: relative;
  height: 72px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-sunken);
}

/* Positioned on the calendar-day time axis, not packed as flex items, so a
   colour at 14:00 sits under the 14:00 tick even when periods are missing. */
.seg {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.55);
  background: var(--band-average);
  color: var(--band-average-text);
  font: inherit;
  overflow: hidden;
  cursor: pointer;
  transition: filter 0.1s ease;
}
.seg:first-child { box-shadow: none; }
.seg:hover { filter: brightness(0.94); }
.seg:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; z-index: 2; }

.seg--negative { background: var(--band-negative); background-image: var(--stripes); color: var(--band-negative-text); }
.seg--very-cheap { background: var(--band-very-cheap); color: var(--band-very-cheap-text); }
.seg--cheap { background: var(--band-cheap); color: var(--band-cheap-text); }
.seg--average { background: var(--band-average); color: var(--band-average-text); }
.seg--expensive { background: var(--band-expensive); color: var(--band-expensive-text); }
.seg--very-expensive { background: var(--band-very-expensive); color: var(--band-very-expensive-text); }

/* Cheapest slot of the day: teal fill plus a star, so it is not just another
   shade of "very cheap". Negative cheapest keeps the stripe pattern. */
.seg--cheapest:not(.seg--negative) {
  background: var(--cheapest);
  color: var(--cheapest-text);
}
.seg__star {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  font-size: 11px;
  line-height: 1;
  color: var(--cheapest-star);
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.seg--cheapest.seg--negative .seg__star { color: var(--cheapest-star); }
.seg--vertical .seg__star { top: 2px; }
.seg--tick .seg__star { font-size: 9px; top: 1px; }

.seg__price {
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  font-weight: 600;
  line-height: 1.15;
  white-space: nowrap;
}
.seg__range {
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  line-height: 1.15;
  white-space: nowrap;
  opacity: 0.82;
}
.seg__count {
  font-size: var(--fs-11);
  line-height: 1.15;
  white-space: nowrap;
  opacity: 0.72;
}

/* JS applies these once it knows the rendered pixel width of each segment. */
.seg--hide-count .seg__count { display: none; }
.seg--hide-range .seg__range { display: none; }
.seg--hide-price .seg__price { display: none; }

/* A 30-minute segment is too narrow for a horizontal price, but the track is tall
   enough to read one rotated, so every period can still show its own value. */
.seg--vertical .seg__price {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: var(--fs-11);
  font-weight: 500;
  letter-spacing: -0.02em;
}
.seg--tick::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: currentColor;
  opacity: 0.5;
}

.seg.is-selected { outline: 2px solid var(--text); outline-offset: -2px; z-index: 3; }
.seg.is-selected::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}

/* Merged segments are also marked with an edge notch so duration reads without colour. */
.seg--merged::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: currentColor;
  opacity: 0.45;
}

/* Axis of proportional hour ticks under the track. */
.timeline__axis {
  position: relative;
  height: 18px;
  margin-top: var(--sp-1);
}
.timeline__tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  padding-top: var(--sp-1);
  border-left: 1px solid var(--border);
  padding-left: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--text-muted);
  white-space: nowrap;
}
.timeline__tick span { display: block; transform: translateX(2px); }
/* Midnight sits on the track's left edge, so centring would clip its label. */
.timeline__tick:first-child { transform: none; }

/* "Now" marker, only drawn when the visible day contains the current instant. */
.timeline__now {
  position: absolute;
  top: 14px;
  bottom: 20px;
  width: 2px;
  background: var(--chart-now);
  pointer-events: none;
  z-index: 4;
}
.timeline__now::before {
  content: "Now";
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 4px;
  border-radius: 2px;
  background: var(--chart-now);
  color: var(--text-inverse);
  font-size: var(--fs-11);
  font-weight: 600;
  line-height: 14px;
}

/* ── SVG chart ────────────────────────────────────────────────────────────── */
.chart { margin-top: var(--sp-5); }
.chart__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.chart__title { font-size: var(--fs-13); font-weight: 600; color: var(--text-secondary); }
.chart__hint { font-size: var(--fs-12); color: var(--text-muted); }
.chart__scroll { overflow-x: auto; overflow-y: hidden; }
.chart__svg { display: block; width: 100%; touch-action: pan-y; }

.chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis-line { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-zero-line { stroke: var(--chart-zero); stroke-width: 1; stroke-dasharray: 4 3; }
.chart-now-line { stroke: var(--chart-now); stroke-width: 1.5; stroke-dasharray: 3 2; }
.chart-axis-text {
  fill: var(--chart-axis-text);
  font-family: var(--font-mono);
  font-size: 10px;
}
.chart-axis-title {
  fill: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.chart-area { fill: url(#chartAreaGradient); }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 1.75; stroke-linejoin: round; }
.chart-neg-area { fill: rgba(11, 93, 143, 0.18); }
.chart-hover-band { fill: var(--text); opacity: 0.06; }
.chart-cursor-line { stroke: var(--text-secondary); stroke-width: 1; stroke-dasharray: 3 2; }
.chart-dot { fill: var(--surface-card); stroke: var(--chart-line); stroke-width: 2; }
.chart-sel-band { fill: var(--accent); opacity: 0.12; }
.chart-sel-line { stroke: var(--accent); stroke-width: 1.5; }

/* ── Tooltip ──────────────────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 60;
  min-width: 148px;
  max-width: 260px;
  padding: var(--sp-2) var(--sp-3);
  background: #202124;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  color: #fff;
  font-size: var(--fs-12);
  line-height: 1.45;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.1s ease;
}
.tooltip.is-visible { opacity: 1; visibility: visible; }
.tooltip__time {
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  font-weight: 600;
}
.tooltip__price {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: var(--fs-14);
}
.tooltip__row {
  margin-top: 2px;
  color: #dadce0;
  font-size: var(--fs-11);
}
.tooltip__row--cheapest { color: var(--cheapest-star); font-weight: 600; }
.tooltip__band {
  display: inline-block;
  margin-top: var(--sp-1);
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-11);
  font-weight: 600;
}

/* ── Data table ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
}
.data-table th,
.data-table td {
  padding: var(--sp-2) var(--sp-4);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr.is-selected { background: var(--surface-active); }
.data-table tbody tr.is-now { box-shadow: inset 3px 0 0 var(--chart-now); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table caption {
  padding: var(--sp-2) var(--sp-4);
  text-align: left;
  font-size: var(--fs-12);
  color: var(--text-muted);
}

/* Long tables scroll within the card so the page header stays reachable. */
.rates-scroll { max-height: 600px; overflow: auto; }

.kv-table { width: 100%; border-collapse: collapse; font-size: var(--fs-13); }
.kv-table th,
.kv-table td {
  padding: var(--sp-2) var(--sp-5);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
.kv-table th { width: 220px; font-weight: 500; color: var(--text-secondary); }
.kv-table td { font-family: var(--font-mono); }
.kv-table tr:last-child th, .kv-table tr:last-child td { border-bottom: 0; }

/* ── Application states ───────────────────────────────────────────────────── */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
}
.state__title { font-size: var(--fs-14); font-weight: 500; }
.state__text { max-width: 46ch; font-size: var(--fs-13); color: var(--text-secondary); }
.state__detail {
  max-width: 60ch;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--text-secondary);
  word-break: break-word;
}
.state--error .state__title { color: var(--danger); }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  background: var(--warn-subtle);
  font-size: var(--fs-12);
  color: #5c3c00;
}
.banner svg { flex: 0 0 auto; width: 16px; height: 16px; margin-top: 1px; }

.placeholder { padding: var(--sp-6) 0; }
.placeholder__title { font-size: var(--fs-14); font-weight: 500; }
.placeholder__text { max-width: 68ch; margin-top: var(--sp-2); font-size: var(--fs-13); color: var(--text-secondary); }
.placeholder__text code {
  padding: 1px 4px;
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  background: var(--surface-sunken);
  font-size: var(--fs-12);
}

/* ── Price history heatmap ────────────────────────────────────────────────── */
.history { display: flex; flex-direction: column; gap: 2px; overflow-x: auto; }
.history-axis {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-4);
  min-height: 18px;
  padding: 0 0 var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--text-muted);
}
.history-axis__meta { flex: 0 0 220px; }
.history-axis__hours { position: relative; flex: 1 1 auto; min-width: 0; height: 16px; }
.history-axis__tick { position: absolute; transform: translateX(-50%); }
.history-axis__tick:first-child { transform: none; }
.history-axis__tick:last-child { transform: translateX(-100%); }

.history-row {
  display: flex;
  align-items: stretch;
  gap: var(--sp-4);
  padding: var(--sp-1) 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.history-row:hover { background: var(--surface-hover); }
.history-row:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.history-row__meta { flex: 0 0 220px; min-width: 0; padding: 2px 0; }
.history-row__date { font-size: var(--fs-13); font-weight: 500; }
.history-row__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-2);
  margin-top: 2px;
  font-size: var(--fs-11);
  color: var(--text-secondary);
}
.history-stat__value.pill { font-size: 10px; padding: 0 5px; }

.heat-strip {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  gap: 1px;
  padding: 1px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--border);
  overflow: hidden;
}
.heat-cell { flex: 1 1 0; min-width: 0; background: var(--band-average); }
.heat-cell--empty { background: var(--surface-sunken); }
.heat-cell--negative { background: var(--band-negative); }
.heat-cell--very-cheap { background: var(--band-very-cheap); }
.heat-cell--cheap { background: var(--band-cheap); }
.heat-cell--average { background: var(--band-average); }
.heat-cell--expensive { background: var(--band-expensive); }
.heat-cell--very-expensive { background: var(--band-very-expensive); }

@media (max-width: 840px) {
  .history-axis__meta,
  .history-row__meta { flex-basis: 160px; }
}

@media (max-width: 560px) {
  .stat__value { font-size: var(--fs-22); }
  .card__body { padding: var(--sp-4); }
  .history-axis,
  .history-row { flex-direction: column; gap: var(--sp-1); }
  .history-axis__meta,
  .history-row__meta { flex-basis: auto; }
}
