/* Insights view: the Lab's Drivers sub-page (#lab/drivers). Shared components (.panel, .tile, .tiles, .legend,
   .empty, .grid-wide) come from styles.css; only view-specific layout lives here,
   and every selector starts with .insights- so nothing leaks into other pages.
   Colors come from the tokens in styles.css. */

/* Grid children must be allowed to shrink, or wide SVGs force horizontal scroll. */
.insights-page,
.insights-page .panel,
.insights-chart {
  min-width: 0;
}

.insights-chart {
  width: 100%;
  min-height: 120px;
}

/* Headline finding: reads like the first lines of a research summary. */
.insights-intro {
  display: grid;
  gap: 6px;
  max-width: 72ch;
}

.insights-headline {
  margin: 0;
  font-size: 20px;
  font-stretch: 100%;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ink);
  text-wrap: pretty;
}

.insights-intro-fine {
  margin: 0;
}

/* Ranked driver list */
.insights-drivers {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.insights-driver-item {
  margin: 0;
  min-width: 0;
}

.insights-driver {
  --insights-row-bg: var(--surface);
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 14px 16px 14px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--insights-row-bg);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.insights-driver:hover {
  --insights-row-bg: var(--surface-2);
}

.insights-driver[aria-pressed="true"] {
  --insights-row-bg: var(--surface-2);
  border-color: var(--axis);
}

/* Selected marker: a short ink bar on the leading edge. */
.insights-driver[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: -1px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--ink);
}

.insights-driver:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.insights-rank {
  display: block;
  font-size: 20px;
  line-height: 1.1;
  text-align: right;
  color: var(--ink-3);
}

.insights-driver-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.insights-driver-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px 12px;
}

/* A long label ("Days after alcohol (from your notes)") wraps beside the meter. */
.insights-driver-label {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink-2);
}

.insights-driver-sentence {
  display: block;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  text-wrap: pretty;
}

.insights-driver[data-strength="none"] .insights-driver-sentence {
  color: var(--ink-2);
}

.insights-driver-fine {
  display: block;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-3);
}

/* Strength: direction arrow (ink) plus a meter of |r| out of 0.6. */
.insights-strength {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  color: var(--ink-2);
}

.insights-arrow-slot {
  display: inline-block;
  width: 14px;
  height: 14px;
}

.insights-meter {
  position: relative;
  display: block;
  width: 96px;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--hairline);
}

.insights-meter-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--w, 0%);
  border-radius: 0 3px 3px 0;
  background: var(--sw, var(--ink-3));
}

/* Notches at the weak / moderate / strong thresholds, cut in the row color. */
.insights-meter-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--insights-row-bg);
}

.insights-foot-note {
  margin: 8px 0 0;
}

/* Keep the scatter in view while scanning a long list on wide screens. */
@media (min-width: 900px) {
  .insights-scatter-panel {
    position: sticky;
    top: 24px;
    align-self: start;
  }
}

/* Weekday patterns */
.insights-weekday-summary {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
}

.insights-heat {
  width: 100%;
}

/* "7h 42m" should not break across two lines in a narrow cell; the table scrolls instead. */
.insights-heat td {
  white-space: nowrap;
}

.insights-disclaimer {
  margin: 0;
}

@media (max-width: 599px) {
  .insights-headline {
    font-size: 18px;
  }

  .insights-driver {
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 10px;
    padding: 12px 12px 12px 10px;
  }

  .insights-driver-sentence {
    font-size: 15px;
  }

  .insights-meter {
    width: 72px;
  }

  /* Five records on a two-up phone grid: the last one takes the full row, no orphan. */
  [data-chart="records"] .tiles > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .insights-driver {
    transition: none;
  }
}
