/* ---- "When the money moved, hour by hour" — the per-hour sector panel -------
   The second homepage panel, directly under "Where the money moved". It
   reuses the .sh card (views/landing.css) and adds its own layout here: the
   hour chart, the selected hour's diverging sector bars and the summary
   line.

   The chart is DOM, not a canvas: one <button> per hour, so the hour is
   focusable, announces its state and works with a keyboard for free. The
   bars use the same tokens as the panel above (--up / --down), so the two
   panels read as one system.

   Every colour is a token; this file paints nothing of its own. */

.sh-hours {
  /* The card itself comes from views/landing.css (.sh). */
  gap: var(--space-4);
}

.sh-hours-head {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sh-hours .sh-kicker {
  margin: 0;
}

/* The panel's title: a section heading, never the page's h1 — that is the
   sector sentence above it. */
.sh-hours-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.008em;
  font-weight: var(--fw-semibold);
  color: var(--text);
  text-wrap: balance;
}

/* The generated summary: one line about where the trading went. It is
   quieter than the sector headline above it, but still the panel's own
   sentence. */
.sh-hours-summary {
  margin: 0;
  max-width: 44em;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-soft);
  text-wrap: pretty;
}

.sh-hours-summary:empty {
  display: none;
}

/* The basket's own name, from the server: the panel measures the 11 sector
   funds combined and says so. */
.sh-hours-basket {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.sh-hours-basket:empty {
  display: none;
}

/* Which session the figures are from. It is shown whenever the panel falls
   back to the last completed session, so a previous session's hours are
   never read as today's. */
.sh-hours-session {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.sh-hours-session[hidden] {
  display: none;
}

/* The hours that are not on the chart, and why. The gap is named, never
   hidden. */
.sh-hours-excluded {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.sh-hours-excluded[hidden] {
  display: none;
}

/* ---- the chart ---------------------------------------------------------------- */

.sh-hours-chart {
  margin-top: var(--space-2);
}

/* The plot: the bars' area. The "usual" line is positioned against the
   same scale as the bars (--usual is 1 / the chart's scale). */
.sh-hours-plot {
  position: relative;
  height: 148px;
  border-bottom: 1px solid var(--border);
}

.sh-hours-usual {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--usual, 1) * 100%);
  border-top: 1px dashed var(--border-subtle);
}

.sh-hours-cols {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  height: 100%;
}

/* One hour: a button whose height is the bar's. */
.sh-hour {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.sh-hour:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* The bar: its height is the hour's volume against the chart's scale. */
.sh-hour-fill {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 0;
  height: calc(var(--r, 0) * 100%);
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: var(--chart-axis);
}

/* The busiest hour of the session is the one the summary names: it takes
   the accent, and the selected hour takes a ring. */
.sh-hour.is-busy .sh-hour-fill {
  background: var(--chart-accent);
}

/* The hour that is still running (issue #178): a lighter bar — its tick
   carries the "13:30 so far (25 min)" label in text, so the lighter paint
   is never the only thing saying the hour is partial. */
.sh-hour.is-partial .sh-hour-fill {
  opacity: 0.45;
}

.sh-hour.is-selected .sh-hour-fill {
  box-shadow: 0 0 0 2px var(--accent);
}

/* The value sits just above its own bar. */
.sh-hour-value {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--r, 0) * 100% + 3px);
  text-align: center;
  font-size: var(--fs-label);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.sh-hour.is-busy .sh-hour-value {
  color: var(--text);
  font-weight: var(--fw-medium);
}

/* The hour labels under the plot. */
.sh-hours-ticks {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.sh-hour-tick {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: var(--fs-label);
  color: var(--text-muted);
  white-space: nowrap;
}

/* The running hour's tick is the long one ("13:30 so far (25 min)"): it may
   wrap rather than squeeze its neighbours off the chart. */
.sh-hour-tick.is-partial {
  white-space: normal;
}

/* The legend under the chart: the dashed line is the usual hour. */
.sh-hours-legend {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
  font-size: var(--fs-label);
  color: var(--text-muted);
}

.sh-hours-legend-line {
  display: inline-block;
  width: 18px;
  border-top: 1px dashed var(--border-subtle);
}

/* Loading: quiet skeleton bars — no spinner, no colour. */
.sh-hour.is-skeleton {
  background: var(--surface-2);
  border-radius: 3px 3px 0 0;
  height: 60%;
  align-self: flex-end;
}

/* ---- the selected hour's sectors --------------------------------------------- */

.sh-hours-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.sh-hours-detail[hidden] {
  display: none;
}

.sh-hours-detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0;
}

.sh-hours-detail-hour {
  font-size: 15px;
  font-weight: var(--fw-medium);
  color: var(--text);
}

.sh-hours-detail-ratio {
  font-size: var(--fs-small);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.sh-hours-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* One row: the sector name and ticker, then the diverging bar from the
   centred zero line — the same construction as the panel above. */
.sh-hours-row {
  --sh-span: 30%;
  --sh-gap: calc(var(--space-2) + 2px);
  --r: 0;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  align-items: center;
  column-gap: var(--space-4);
  min-height: var(--hit-min);
  appearance: none;
  margin: 0;
  padding: 0 var(--space-2);
  width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
}

.sh-hours-row:hover { background: var(--surface-2); }
.sh-hours-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sh-hours-pop {
  max-height: calc(100dvh - var(--space-6));
  overflow-y: auto;
}

.sh-hours-row-label {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: var(--space-2);
  min-width: 0;
  text-align: right;
}

.sh-hours-row-name {
  font-size: 14px;
  color: var(--text);
}

.sh-hours-row-ticker {
  font-size: var(--fs-label);
  color: var(--text-muted);
  white-space: nowrap;
}

.sh-hours-row-track {
  display: block;
  position: relative;
  height: var(--sector-row-track-height);
}

.sh-hours-row-track::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.sh-hours-row-fill {
  position: absolute;
  inset-block: var(--sector-row-bar-inset);
  width: calc(var(--r, 0) * var(--sh-span));
  border-radius: 3px;
}

.sh-hours-row-fill.is-up {
  left: 50%;
  background: var(--up);
}

.sh-hours-row-fill.is-down {
  right: 50%;
  background: var(--down);
}

.sh-hours-row-fill.is-flat {
  left: calc(50% - (var(--space-1) / 2));
  width: var(--space-1);
  background: var(--text-muted);
}

/* The value at the bar's end, with a sign and tabular figures. */
.sh-hours-row-value {
  position: absolute;
  inset-block: 0;
  display: flex;
  align-items: center;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

.sh-hours-row-value.is-up {
  left: calc(50% + var(--r, 0) * var(--sh-span) + var(--sh-gap));
  color: var(--pos);
}

.sh-hours-row-value.is-down {
  right: calc(50% + var(--r, 0) * var(--sh-span) + var(--sh-gap));
  color: var(--neg);
}

.sh-hours-row-value.is-flat {
  left: calc(50% + var(--sh-gap));
}

.sh-hours-row.is-unknown .sh-hours-row-name {
  color: var(--text-muted);
}

.sh-hours-detail-note {
  margin: 0;
  font-size: var(--fs-label);
  color: var(--text-muted);
}

/* ---- the states ---------------------------------------------------------------- */

.sh-hours-state[hidden] {
  display: none;
}

.sh-hours-loading {
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.sh-hours-stale {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.sh-hours-stale[hidden] {
  display: none;
}

/* ---- phones -------------------------------------------------------------------- */

@media (max-width: 479.98px) {
  .sh-hours-title {
    font-size: 19px;
  }

  .sh-hours-plot {
    height: 116px;
  }

  .sh-hours-cols,
  .sh-hours-ticks {
    gap: var(--space-1);
  }

  .sh-hour-value {
    font-size: var(--fs-2xs);
  }

  .sh-hour-tick {
    font-size: var(--fs-2xs);
  }

  /* The name column shrinks: the bar area keeps the room. */
  .sh-hours-row {
    grid-template-columns: 118px minmax(0, 1fr);
    column-gap: var(--space-3);
  }

  .sh-hours-row-name {
    font-size: 13px;
  }

  .sh-hours-row-ticker {
    display: none;
  }

  .sh-hours-detail-head {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }
}
