/* ==========================================================================
   Screen layouts — composition of components; no colors defined here
   ========================================================================== */

/* ---------- Login ---------- */

.login-page {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  min-height: 100%;
  padding: var(--space-4);
}

.login-card {
  position: relative;
  z-index: 1; /* always above the hero artwork */
  grid-column: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-8);
  min-width: 360px;
  padding: var(--space-8);
  border-radius: var(--radius-lg);
}

.login-card .logo {
  position: absolute;
  top: var(--space-8);
  left: 50%;
  height: 28px;
  aspect-ratio: 485.67 / 164.98; /* riff wordmark */
  transform: translateX(-50%);
}

.login-card h1 {
  text-align: center;
}

.login-card .login-help {
  position: absolute;
  bottom: var(--space-8);
  left: 0;
  right: 0;
  text-align: center;
  font-size: var(--text-sm, 12px);
  color: var(--color-text-secondary);
}

.login-help a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.login-help a:hover {
  color: var(--color-text-label);
}

.login-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

/* riff symbol with the glowing heatmap shader, as on the landing page (js/login-hero.js) */
.login-hero {
  grid-column: 2 / -1;
  position: relative;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Square stage centered in the hero, both ways. The shader draws the symbol at 65% of the
   stage width (the symbol is wider than tall, so its height is 65% × 143.78/166.78 ≈ 56% of
   the stage), leaving room around it for the outer glow. 250px stage → symbol 140px tall. */
.login-hero-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 250px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
}

/* Soft purple glow behind the symbol that slowly breathes and drifts, so the mark feels alive.
   Two layers out of step with each other, so the motion never looks like a simple loop. */
.login-hero-mark::before,
.login-hero-mark::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(24px);
}

.login-hero-mark::before {
  inset: 12%;
  background: radial-gradient(closest-side, var(--hero-glow-strong), transparent);
  animation: hero-glow-breathe 7s ease-in-out infinite;
}

.login-hero-mark::after {
  inset: 22% 28% 22% 18%;
  background: radial-gradient(closest-side, var(--hero-glow-soft), transparent);
  animation: hero-glow-drift 11s ease-in-out infinite;
}

@keyframes hero-glow-breathe {
  0%, 100% { opacity: 0.55; transform: scale(0.92); }
  50%      { opacity: 1;    transform: scale(1.06); }
}

@keyframes hero-glow-drift {
  0%, 100% { opacity: 0.4; transform: translate(-6%, 3%) scale(0.95); }
  50%      { opacity: 0.9; transform: translate(8%, -4%) scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .login-hero-mark::before,
  .login-hero-mark::after {
    animation: none;
  }
}

.login-hero-shader {
  position: absolute;
  inset: 0;
  /* Paper's canvas is z-index:-1; keep it inside this box instead of behind the page */
  isolation: isolate;
  /* Pre-processing the symbol takes a moment; fade in once the first frame is ready */
  opacity: 0;
  transition: opacity 0.8s ease;
}

.login-hero-shader.is-ready {
  opacity: 1;
}

/* The shader leaves stray dark pixels on the canvas's outermost edge, which show on the light
   theme. The glow never reaches the edge, so trim it. Clipped on the canvas itself, not an
   ancestor, so Chrome keeps drawing the WebGL layer. */
.login-hero-shader canvas {
  clip-path: inset(2%);
  /* Glow that hugs the symbol itself: drop-shadows follow the shader's own shape, and pulse
     slowly so the light feels like it comes from the mark */
  filter: drop-shadow(0 0 2px var(--hero-halo-near)) drop-shadow(0 0 8px var(--hero-halo-far));
  animation: hero-halo-pulse 5s ease-in-out infinite;
}

@keyframes hero-halo-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 1.5px var(--hero-halo-near)) drop-shadow(0 0 6px var(--hero-halo-far));
  }
  50% {
    filter: drop-shadow(0 0 3px var(--hero-halo-near)) drop-shadow(0 0 14px var(--hero-halo-far));
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-hero-shader canvas {
    animation: none;
  }
}

/* Static fallback when WebGL is unavailable */
.login-hero-fallback {
  position: absolute;
  inset: 17.5%; /* the symbol at 65% of the stage, like the shader */
  background-color: var(--color-text-disabled);
  -webkit-mask: url("../assets/logo-mark.svg") center / contain no-repeat;
  mask: url("../assets/logo-mark.svg") center / contain no-repeat;
  opacity: 0.25;
}

@media (max-width: 900px) {
  .login-page {
    grid-template-columns: 1fr;
  }

  .login-card {
    min-width: 0;
    padding: var(--space-7);
  }

  .login-hero {
    display: none;
  }
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  gap: var(--space-4);
  min-height: 100%;
  padding: var(--space-4);
}

.sidebar {
  position: sticky;
  top: var(--space-4);
  flex: 0 0 280px;
  height: calc(100vh - 2 * var(--space-4));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-8);
  padding: var(--space-5);
  border-radius: var(--radius-md);
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

.sidebar .logo {
  height: 22px;
  aspect-ratio: 485.67 / 164.98; /* riff wordmark */
  align-self: flex-start;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.user-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
}

.user-name {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-medium);
}

.user-org {
  color: var(--color-text-secondary);
}

.user-name,
.user-org {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* The page title's letters start level with the top of the riff logo in the sidebar
     (logo ink at 21px; the title's line box adds 6px of leading above its capitals) */
  padding-top: 6px;
}

.content {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

/* ---------- Page header ---------- */

.page-header {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.page-header-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-subtitle {
  color: var(--color-text-secondary);
}

/* ---------- Placeholder pages (Dashboard, Insights & Actions) ---------- */

.page-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-8) var(--space-6);
  text-align: center;
}

.page-empty .icon-tile {
  margin-bottom: var(--space-2);
}

.page-empty-title {
  font-weight: var(--font-medium);
}

.page-empty-text {
  max-width: 360px;
  color: var(--color-text-secondary);
}

/* ---------- Home: metrics ---------- */

.content-dashboard {
  max-width: 1040px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-6);
}

.metric-card-wide {
  grid-column: 1 / -1;
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.metric-title {
  font-size: var(--text-md);
  line-height: var(--leading-md);
  font-weight: var(--font-medium);
}

.metric-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  flex: 1;
}

.metric-figure {
  display: flex;
  flex-direction: column;
}

/* Big numbers: same sans, proportional figures */
.metric-value {
  font-size: 32px;
  line-height: 40px;
  font-weight: var(--font-medium);
  letter-spacing: -0.01em;
}


.metric-caption,
.metric-sub {
  color: var(--color-text-secondary);
}

.metric-sub {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}

.metric-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5) var(--space-8);
}

/* The headline card: three numbers side by side, all the same size as the other cards */
.metric-stats-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-6);
}

.metric-stats-3 .metric-figure + .metric-figure {
  padding-left: var(--space-6);
  border-left: 1px solid var(--divider);
}

@container (max-width: 560px) {
  .metric-stats-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .metric-stats-3 .metric-figure + .metric-figure {
    padding: var(--space-6) 0 0;
    border-left: 0;
    border-top: 1px solid var(--divider);
  }
}

.metric-value-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

/* Change vs. the previous period: arrow + number, tinted by whether the move is good */
.change-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 22px;
  padding: 0 var(--space-3) 0 var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-medium);
  white-space: nowrap;
  cursor: default;
}

.change-chip.is-good {
  background: var(--change-good-bg);
  color: var(--change-good-text);
}

.change-chip.is-bad {
  background: var(--change-bad-bg);
  color: var(--change-bad-text);
}

.change-chip.is-flat {
  background: var(--divider);
  color: var(--color-text-secondary);
}

.change-icon {
  width: 14px;
  height: 14px;
}

/* Info icon, top right: the card's explanation in a tooltip */
.metric-info {
  width: 28px;
  height: 28px;
  margin: calc(-1 * var(--space-2)) calc(-1 * var(--space-3)) calc(-1 * var(--space-2)) 0;
  padding: var(--space-2);
  color: var(--color-text-secondary);
}

/* ---------- Home: chart marks ---------- */

.bar-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 168px) minmax(0, 1fr);
  align-items: center;
  gap: var(--space-5);
}

.bar-label {
  min-width: 0;
  color: var(--color-text-secondary);
}

/* The bar grows from the left baseline; its value sits just past the tip */
.bar-track {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  padding-right: 64px; /* room for the longest value label */
}

.bar {
  flex: none;
  height: 16px;
  min-width: 2px;
  border-radius: 0 4px 4px 0; /* square at the baseline, rounded data end */
  outline-offset: 2px;
}

.bar-value {
  flex: none;
  font-weight: var(--font-medium);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.is-riff { background: var(--viz-riff); }
.is-base { background: var(--viz-base); }
.is-cat1 { --series: var(--viz-cat1); }
.is-cat2 { --series: var(--viz-cat2); }
.is-cat3 { --series: var(--viz-cat3); }
.is-cat4 { --series: var(--viz-cat4); }
.is-cat5 { --series: var(--viz-cat5); }
.is-cat6 { --series: var(--viz-cat6); }
.viz-key[class*="is-cat"],
.line-key,
.viz-tooltip-key { background: var(--series); }

/* ---------- Home: donut ---------- */

.donut {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

/* The card's own width decides the ring size; the legend always stays beside it */
.metric-card {
  container-type: inline-size;
}

.donut-chart {
  width: 184px;
  height: 184px;
}

@container (max-width: 520px) {
  .donut {
    gap: var(--space-6);
  }

  .donut-chart {
    width: 144px;
    height: 144px;
  }

  .donut-center .metric-value {
    font-size: var(--text-xl);
    line-height: var(--leading-xl);
  }
}
.donut-ring {
  position: relative;
  flex: none;
}

.donut-chart {
  display: block;
}

.donut-seg {
  stroke: var(--series);
  outline: none;
  cursor: default;
}

.donut-seg.is-hovered {
  filter: brightness(1.12);
}

.donut-seg:focus-visible {
  stroke-width: 30;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  pointer-events: none;
}

.donut-center .change-chip {
  pointer-events: auto;
}

.viz-legend.viz-legend-list {
  flex: 1;
  max-width: 340px;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  font-size: var(--text-md);
  line-height: var(--leading-md);
}

.viz-legend.viz-legend-list li {
  display: grid;
  align-items: center;
  grid-template-columns: 10px minmax(0, 1fr) auto 40px;
  gap: var(--space-4);
}

/* Legend text stays on one line; a cut label shows the full text on hover (js/home.js) */
.is-truncated {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The same legend laid out in one row: key, name, count and share together, side by side */
.viz-legend.viz-legend-list.is-inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  max-width: none;
  gap: var(--space-2) var(--space-8);
}

.viz-legend.viz-legend-list.is-inline li {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.is-inline .legend-value,
.is-inline .legend-share {
  text-align: left;
}

.is-inline .legend-value {
  margin-left: var(--space-2);
}

.legend-value {
  font-weight: var(--font-medium);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.legend-share {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- Home: line chart ---------- */

.line-legend {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.line-legend li {
  display: flex;
  gap: var(--space-4);
  min-width: 0;
}

.line-legend .metric-figure {
  min-width: 0;
}

/* Legends mirror the mark: a short line for a line series */
.line-key {
  flex: none;
  width: 14px;
  height: 3px;
  margin-top: 19px;
  border-radius: 2px;
}

.line-chart {
  min-width: 0;
}

.line-chart-svg {
  display: block;
  overflow: visible;
}

.line-chart-svg .grid,
.line-chart-svg .axis {
  stroke: var(--divider);
  stroke-width: 1;
}

.line-chart-svg .axis {
  stroke: var(--surface-card-border);
}

.line-chart-svg .tick {
  font-size: var(--text-xs);
  fill: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.line-chart-svg .line {
  fill: none;
  stroke: var(--series);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* Dots carry a 2px ring in the card surface so they read where lines cross */
.line-chart-svg .dot {
  fill: var(--series);
  stroke: var(--surface-card);
  stroke-width: 2;
}

.line-chart-svg .crosshair {
  stroke: var(--color-text-secondary);
  stroke-width: 1;
}

.line-chart-svg .hit {
  fill: transparent;
  outline: none;
}

.line-chart-svg .hit:focus-visible {
  stroke: var(--color-text);
  stroke-width: 1;
}

.bar.is-hovered,
.seg.is-hovered {
  filter: brightness(1.12);
}

.bar:focus-visible,
.seg:focus-visible {
  outline: 2px solid var(--color-text);
}

/* Tall segmented bar: one whole split into parts, 2px surface gap between parts */
.split {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.seg-bar {
  position: relative;
  display: flex;
  gap: 2px;
  height: 28px;
}

.seg {
  min-width: 0;
  border-radius: 4px;
  outline-offset: 2px;
}

/* Target: a hairline across the bar, in text ink */
.seg-target {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--color-text);
  pointer-events: none;
}

.viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--color-text-secondary);
}

.viz-legend li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}

.viz-key {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.viz-key.is-target {
  width: 2px;
  height: 14px;
  border-radius: 1px;
  background: var(--color-text);
}

.viz-tooltip {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-4);
  border-radius: 6px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  pointer-events: none;
}

.viz-tooltip strong {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.viz-tooltip-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.viz-tooltip-row > span:last-child {
  opacity: 0.75;
}

/* Tooltip rows key their series with a short line */
.viz-tooltip-key {
  width: 10px;
  height: 2px;
  border-radius: 1px;
}

.viz-tooltip.is-note {
  max-width: 280px;
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-sm);
  line-height: 18px;
}

@media (max-width: 900px) {
  .metrics-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .bar-row {
    grid-template-columns: minmax(0, 120px) minmax(0, 1fr);
  }

  .line-legend {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Insights & Actions ---------- */

.insights-section h2,
.insights-section h3,
.insights-section p {
  margin: 0;
}

.insights-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.insights-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-lg);
  line-height: var(--leading-lg);
  font-weight: var(--font-medium);
}

.insights-count {
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--divider);
  font-size: var(--text-sm);
  line-height: 20px;
  color: var(--color-text-secondary);
}

/* Themes: bubble chart on the left, the selected theme on the right */
.themes-card {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  overflow: hidden;
}

.themes-chart {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-5);
  padding: var(--space-6);
  border-right: 1px solid var(--divider);
  /* A soft glow behind the cluster */
  background: radial-gradient(60% 55% at 50% 45%, color-mix(in srgb, var(--viz-cat1) 10%, transparent), transparent);
}

.bubble-chart {
  display: block;
  width: 100%;
  height: auto;
  max-height: 400px;
  overflow: visible;
}

/* Each bubble floats gently, out of step with its neighbours */
.bubble-float {
  animation: bubble-float 7s ease-in-out infinite;
  animation-delay: calc(var(--i) * -1.3s);
}

@keyframes bubble-float {
  0%, 100% { transform: translate(0, 0); }
  50%      { transform: translate(0, -4px); }
}

.bubble {
  cursor: pointer;
  outline: none;
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.25s var(--ease-out);
}

/* First draw: bubbles pop in one after another */
.is-entering .bubble {
  animation: bubble-in 0.6s var(--ease-out) both;
  animation-delay: calc(var(--i) * 70ms);
}

@keyframes bubble-in {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.bubble:hover {
  transform: scale(1.05);
}

.bubble circle {
  stroke: color-mix(in srgb, var(--series) 70%, #ffffff);
  stroke-width: 1.5;
}

/* Unselected bubbles step back a little; the selected one is full strength, ringed and glowing */
.bubble:not(.is-selected) {
  opacity: 0.82;
}

.bubble:hover {
  opacity: 1;
}

.bubble.is-selected {
  transform: scale(1.04);
  filter: drop-shadow(0 6px 18px color-mix(in srgb, var(--series) 55%, transparent));
}

.bubble.is-selected circle {
  stroke: var(--color-text);
  stroke-width: 2.5;
}

.bubble:focus-visible circle {
  stroke: var(--color-text);
  stroke-width: 3;
}

/* White on the bubble's fill, the same in both themes */
.bubble-label,
.bubble-count {
  fill: #ffffff;
  pointer-events: none;
}

.bubble-count {
  font-weight: var(--font-medium);
  letter-spacing: -0.01em;
}

.bubble-label {
  font-size: 12px;
  font-weight: var(--font-medium);
}

.bubble-legend {
  justify-content: center;
}

@media (prefers-reduced-motion: reduce) {
  .bubble-float,
  .is-entering .bubble {
    animation: none;
  }

  .bubble {
    transition: none;
  }
}

/* Selected theme: short head, one-line insight, action cards, sources collapsed */
.theme-detail {
  padding: var(--space-6);
}

.theme-detail-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  transition: opacity 0.28s ease, transform 0.28s ease, filter 0.28s ease;
}

/* Switching themes: the old content fades out, the new one fades and settles in */
.theme-detail-body.is-leaving {
  opacity: 0;
  transform: translateY(-4px);
  filter: blur(2px);
}

.theme-detail-body.is-entering {
  animation: theme-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes theme-in {
  from { opacity: 0; transform: translateY(10px); filter: blur(3px); }
  to   { opacity: 1; transform: none; filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-detail-body,
  .theme-detail-body.is-entering {
    animation: none;
    transition: none;
  }
}

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

.theme-domain {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--color-text-secondary);
}

.theme-title {
  font-size: var(--text-lg);
  line-height: var(--leading-lg);
  font-weight: var(--font-medium);
}

.theme-insight {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--viz-cat1) 9%, transparent);
}

.theme-action-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Each suggested action is its own card: title and one line, then the expand chevron and Run,
   centered on the card; the chevron reveals what riff will do */
.theme-action {
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
  border: 1px solid var(--surface-card-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.theme-action-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.theme-action-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.theme-action-title {
  font-weight: var(--font-medium);
}

.theme-action-detail {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--color-text-secondary);
}

.theme-action-title,
.theme-action-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Expanded: the full title and description */
.theme-action.is-open .theme-action-title,
.theme-action.is-open .theme-action-detail {
  white-space: normal;
}

.theme-action-toggle {
  flex: none;
  color: var(--color-text-secondary);
}

.theme-action-toggle .icon,
.theme-sources summary .icon,
.alert-toggle .icon {
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.theme-action.is-open .theme-action-toggle .icon {
  transform: rotate(180deg);
}

/* Spacing lives on the inner box, so the animated outer box can shrink all the way to 0 */
.theme-action-more-inner {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--divider);
}

.theme-action-more[hidden] {
  display: none;
}

.theme-action-more-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
}

.theme-action-steps {
  margin: 0;
  padding-left: var(--space-6);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}

.theme-action-steps li + li {
  margin-top: var(--space-2);
}

.insight-cta {
  flex: none;
}

/* A clicked call to action becomes a confirmation */
.insight-done {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  height: var(--control-height);
  font-weight: var(--font-medium);
  color: var(--color-success);
}

.theme-sources summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
  cursor: pointer;
  list-style: none;
}

.theme-sources summary::-webkit-details-marker {
  display: none;
}

.theme-sources summary .icon {
  transform: rotate(-90deg);
}

.theme-sources.is-open summary .icon {
  transform: none;
}

.theme-sources-body {
  display: flow-root; /* keeps the children's margins inside the animated box */
}

.theme-quotes {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-3);
  padding: 0 0 0 var(--space-5);
  border-left: 2px solid var(--divider);
  list-style: none;
}

.theme-quotes li {
  display: flex;
  flex-direction: column;
}

.theme-quote-text {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}

.theme-quote-who,
.theme-sources-line {
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  color: var(--color-text-secondary);
}

/* Alerts: severity + date, title, two lines of description; the rest on "Read more" */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.alert-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
}

.alert-top {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Severity always carries an icon and a word, never color alone */
.alert-severity {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 22px;
  padding: 0 var(--space-3) 0 var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-medium);
}

.alert-severity.is-high {
  background: var(--change-bad-bg);
  color: var(--change-bad-text);
}

.alert-severity.is-medium {
  background: var(--severity-medium-bg);
  color: var(--severity-medium-text);
}

.alert-severity.is-low {
  background: var(--divider);
  color: var(--color-text-secondary);
}

.alert-date {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--color-text-secondary);
}

.alert-dismiss {
  margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-3)) calc(-1 * var(--space-3)) auto;
  color: var(--color-text-secondary);
}

.alert-title {
  font-size: var(--text-md);
  line-height: var(--leading-md);
  font-weight: var(--font-medium);
}

.alert-text {
  color: var(--color-text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.alert-card.is-expanded .alert-text,
.alert-card.is-collapsing .alert-text {
  display: block;
  overflow: visible;
}

.alert-text code {
  padding: 1px var(--space-2);
  border-radius: 4px;
  background: var(--divider);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
}

.alert-more {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding-top: var(--space-1);
}

.alert-more[hidden] {
  display: none;
}

.alert-meta,
.alert-sources {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--color-text-secondary);
}

/* The secondary link in the expanded details: a text link flush with the text above it */
.alert-secondary.btn {
  height: auto;
  margin-top: var(--space-2);
  padding: 0;
  border: 0;
  background: none;
  gap: var(--space-2);
  color: var(--color-text);
}

.alert-secondary.btn:hover {
  background: none;
  color: var(--color-text-secondary);
}

.alert-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-5);
  margin-top: var(--space-2);
}

.alert-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
  cursor: pointer;
}

.alert-card.is-expanded .alert-toggle .icon {
  transform: rotate(180deg);
}

.alert-toggle:hover {
  color: var(--color-text);
}

@media (max-width: 1100px) {
  .themes-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .themes-chart {
    border-right: 0;
    border-bottom: 1px solid var(--divider);
  }
}

/* ---------- Connectors ---------- */

/* Header search: an icon button that expands into a field at the end of the title row */
.page-search {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  flex: none;
  width: var(--control-height);
  transition: width var(--duration-fast) var(--ease-out);
}

.page-search.is-open {
  width: min(280px, 50vw);
}

.page-search-input {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  height: var(--control-height);
  padding-block: 0;
  padding-left: calc(var(--space-6) + 20px);
  padding-right: var(--control-height);
  opacity: 0;
  pointer-events: none;
}

.page-search-input::-webkit-search-cancel-button {
  display: none;
}

.page-search-toggle,
.page-search-clear {
  position: relative;
  z-index: 1;
}

.page-search-clear {
  display: none;
}

.page-search.is-open .page-search-input {
  opacity: 1;
  pointer-events: auto;
}

/* Open: the magnifier sits inside the field as its leading icon, the x closes it */
.page-search.is-open .page-search-toggle {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.page-search.is-open .page-search-toggle[data-tooltip]::after {
  display: none;
}

.page-search.is-open .page-search-clear {
  display: inline-flex;
  width: 28px;
  height: 28px;
  margin-right: var(--space-2);
  padding: var(--space-2);
}

.connector-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

.connector-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.section-title {
  font-size: var(--text-md);
  line-height: var(--leading-md);
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
}

.connector-empty {
  padding: var(--space-6) 0;
}

/* A multi-account card with accounts takes the full row, so its neighbour isn't stretched */
.connector[data-multiple="true"]:has(.account-list) {
  grid-column: 1 / -1;
}

/* Connected: a green check in place of the + button */
.connected-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--control-height);
  height: var(--control-height);
  color: var(--color-success);
}

.connected-check .icon {
  width: 22px;
  height: 22px;
}

.connector-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.connector {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5);
}

.connector-header {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

/* A header with a Connect button is clickable as a whole; the button is the keyboard target */
.connector-header[data-clickable] {
  cursor: pointer;
}

.connector-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.connector-name {
  font-weight: var(--font-medium);
}

.connector-description {
  color: var(--color-text-secondary);
  /* Two lines at most in the two-column grid */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* One column on narrow screens */
@media (max-width: 760px) {
  .connector-list {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Connected accounts listed inside a multi-account card (e.g. AWS) */
.account-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  margin: 0;
  padding: var(--space-5) 0 0;
  border-top: 1px solid var(--divider);
  list-style: none;
}

.account-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.account-name {
  flex: 1;
  min-width: 0;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Delete buttons appear only while hovering their item (whole card for single-connection
   sources, the account row for multi-account ones) or when focused via keyboard */
.reveal-on-hover {
  opacity: 0;
  transition: opacity var(--duration-fast) ease;
}

.connector[data-multiple="false"]:hover .reveal-on-hover,
.account-row:hover .reveal-on-hover,
.reveal-on-hover:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .reveal-on-hover {
    opacity: 1;
  }
}

/* ---------- Governance ---------- */

/* Three sections read better with more air between them */
.content-wide-gap {
  gap: var(--space-8);
}

/* No overflow clipping: the mode menu opens over the card's edge */
.permission-card {
  overflow: visible;
}

.permission-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.permission-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-6);
}

.permission-row + .permission-row {
  border-top: 1px solid var(--divider);
}

.permission-row .connector-info {
  flex: 1 1 240px;
}

/* ---------- Settings ---------- */

/* Rows separated by dividers; the body's own gap is replaced by row padding */
.settings-list {
  gap: 0;
  padding-top: var(--space-4);
  padding-bottom: var(--space-4);
}

.settings-row + .settings-row {
  border-top: 1px solid var(--divider);
}

.settings-row {
  padding: var(--space-6) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
}

.settings-row-text {
  display: flex;
  flex-direction: column;
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    flex: none;
    height: auto;
  }

  /* Stacked under the sidebar: give the header some air again */
  .main {
    padding-top: var(--space-6);
  }

  .banner {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Room under the content so the floating mode switch never covers it */
.app-shell .main {
  padding-bottom: 96px;
}
