/* ============================================================
   Narrative Stack view — small-multiples grid of every thread's
   trajectory. Ported from the cleanup redesign (styles.css stack
   section). Selectors resolve tokens from the .nv-root scope in
   narrative.css; loaded after it so its rules layer on top.
   ============================================================ */
.stack-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.stack-strip {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 26px; border-bottom: 1px solid var(--line); background: var(--bg-1);
  flex-wrap: wrap;
}
.stack-strip-left { display: inline-flex; align-items: baseline; gap: 14px; min-width: 0; }
.stack-strip-right { display: inline-flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.stack-strip .sub-title { font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg-2); font-weight: 600; }
.stack-strip .sub-axis { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; color: var(--fg-4); display: inline-flex; align-items: center; gap: 8px; }
.stack-strip .touched-pill { font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); background: var(--accent-faint); border-radius: var(--radius); padding: 1px 6px; }

.stack-control { display: inline-flex; align-items: center; gap: 8px; }
.stack-control-lbl { font-family: var(--mono); font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-4); }
.stack-control-grp { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stack-pill { padding: 4px 10px; font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; background: transparent; color: var(--fg-3); border: 0; border-right: 1px solid var(--line); cursor: pointer; transition: color .12s, background .12s; white-space: nowrap; }
.stack-pill:last-child { border-right: 0; }
.stack-pill:hover { color: var(--fg-2); }
.stack-pill.on { color: var(--fg); background: var(--bg-2); }
.stack-topic-select {
  font: inherit; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg); background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 24px 4px 8px; cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-3) 50%), linear-gradient(135deg, var(--fg-3) 50%, transparent 50%);
  background-position: calc(100% - 10px) 50%, calc(100% - 7px) 50%; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
}

.stack-grid {
  flex: 1 1 auto; min-height: 0; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px;
  padding: 16px 26px 36px; align-content: start;
}
.stack-empty { grid-column: 1 / -1; text-align: center; font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-4); padding: 60px 0; }

.stack-card {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px 11px; display: flex; flex-direction: column; gap: 8px;
  cursor: pointer; transition: background .12s, border-color .12s; position: relative; outline: none;
}
.stack-card:hover { background: var(--bg-2); border-color: var(--line-strong); }
.stack-card:focus-visible { border-color: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent-dim); }
.stack-card.active { border-color: var(--accent-dim); background: var(--bg-2); }
.stack-card.active::before { content: ""; position: absolute; top: 8px; bottom: 8px; left: -1px; width: 2px; background: var(--accent); }
.stack-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.stack-card-id { display: inline-flex; align-items: baseline; gap: 8px; min-width: 0; flex: 1 1 auto; }
.stack-card-id .ago { flex: 0 0 auto; font-family: var(--mono); font-size: 10px; color: var(--fg-4); font-variant-numeric: tabular-nums; }
.stack-card.touched .stack-card-id .ago { color: var(--accent); }
.stack-card-label { font-size: 12.5px; font-weight: 500; color: var(--fg); letter-spacing: -0.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stack-card-score { text-align: right; font-family: var(--mono); display: inline-flex; flex-direction: column; align-items: flex-end; gap: 1px; flex-shrink: 0; }
.stack-card-score .score { font-size: 15px; color: var(--fg); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; }
.stack-card.touched .stack-card-score .score { color: var(--accent); }
.stack-card-score .score-delta { font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; color: var(--fg-3); }
.stack-card-score .score-delta .arrow { font-size: 7px; }
.stack-card-score .score-delta.up { color: var(--accent); }
.stack-card-score .score-delta.down { color: var(--fg-2); }
.stack-card-score .score-delta.flat { color: var(--fg-4); }
.stack-card-topic { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-3); align-self: flex-start; }
.stack-card-chart { height: 70px; position: relative; margin: 2px 0; }
.stack-spark { width: 100%; height: 100%; display: block; }
.stack-spark.empty { background: repeating-linear-gradient(45deg, transparent 0 6px, var(--line-soft) 6px 7px); opacity: 0.5; }
.stack-spark .stack-grid.dashed { stroke: var(--line-strong); stroke-width: 0.8; stroke-dasharray: 2 3; opacity: 0.45; fill: none; }
.stack-spark .stack-grid.zero { stroke: var(--line-strong); stroke-width: 0.8; fill: none; }
.stack-spark .stack-line { fill: none; stroke: var(--fg); stroke-width: 1.2; stroke-linejoin: round; stroke-linecap: round; opacity: 0.85; }
.stack-spark .stack-wash.esc path { fill: var(--esc-color); opacity: 0.18; }
.stack-spark .stack-wash.desc path { fill: var(--desc-color); opacity: 0.14; }
.stack-spark .stack-mile.escalation { fill: var(--esc-color); }
.stack-spark .stack-mile.deescalation { fill: var(--desc-color); }
.stack-spark .stack-end.esc { fill: var(--esc-color); stroke: var(--bg-1); stroke-width: 1.5; }
.stack-spark .stack-end.desc { fill: var(--desc-color); stroke: var(--bg-1); stroke-width: 1.5; }
.stack-card.active .stack-spark .stack-end { stroke: var(--bg-2); }
.stack-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack-card-meta { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-4); font-variant-numeric: tabular-nums; }
.stack-card-meta b { color: var(--fg-2); font-weight: 500; }
.stack-card-meta .sep { margin: 0 4px; color: var(--fg-faint); }
.stack-card-tag { font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; padding: 2px 6px; border-radius: var(--radius); background: var(--bg-2); color: var(--fg-3); border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 4px; }
.stack-card-tag.d-escalation { color: var(--esc-color); border-color: color-mix(in srgb, var(--esc-color) 35%, var(--line)); background: color-mix(in srgb, var(--esc-color) 10%, var(--bg-1)); }
.stack-card-tag.d-deescalation { color: var(--desc-color); border-color: color-mix(in srgb, var(--desc-color) 35%, var(--line)); background: color-mix(in srgb, var(--desc-color) 10%, var(--bg-1)); }
.stack-card-tag .m { font-size: 10px; line-height: 1; }
.stack-card-last { font-size: 11.5px; color: var(--fg-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; padding-top: 6px; border-top: 1px dashed var(--line-soft); }
