/* ============================================================
   Debug — log viewer
   Reuses unified.css tokens + the Headlines row/batch vocabulary.
   Columns: time · stage · asset · message  (newest cycle on top)
   ============================================================ */

:root {
  /* time | stage(+asset) | message */
  --dlog-grid: 100px 132px 1fr;
  --dlog-gap: 16px;
}

/* ---------- Filter bar (sits under the toolbar) ---------- */

.dlog-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 18px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
}
.dlog-fgroup {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.dlog-fgroup > .glabel {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
  white-space: nowrap;
}
.dlog-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.dlog-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  background: var(--bg-1);
  color: var(--fg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5px 7px;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.01em;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
}
.dlog-chip:hover { background: var(--bg-2); color: var(--fg); }
.dlog-chip .ct {
  font-size: 9.5px;
  color: var(--fg-5);
  font-variant-numeric: tabular-nums;
}
.dlog-chip.on {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: var(--blue-border-strong);
}
.dlog-chip.on .ct { color: var(--blue); opacity: 0.65; }
/* When a group has an active selection, dim the un-picked chips. */
.dlog-fgroup.has-sel .dlog-chip:not(.on) { opacity: 0.5; }

/* Type chips carry their semantic color when active. */
.dlog-chip.sev-warn.on  { background: var(--yellow-bg); color: var(--yellow); border-color: var(--yellow); }
.dlog-chip.sev-warn.on .ct { color: var(--yellow); }
.dlog-chip.sev-error.on { background: var(--red-bg); color: var(--red); border-color: var(--red-bright); }
.dlog-chip.sev-error.on .ct { color: var(--red); }

.dlog-reset {
  margin-left: auto;
  color: var(--fg-4);
  font-size: 11.5px;
  padding: 3px 4px;
  white-space: nowrap;
}
.dlog-reset:hover { color: var(--fg-2); }
.dlog-reset:disabled { color: var(--fg-5); cursor: default; }

/* ---------- Column header strip ---------- */

.dlog-cols {
  display: grid;
  grid-template-columns: var(--dlog-grid);
  gap: var(--dlog-gap);
  padding: 8px 4px 7px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fg-4);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

/* ---------- List + cycle batches ---------- */

.dlog-list { padding-bottom: 24px; }

.dlog-batch {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 4px 4px;
  border-top: 1px solid var(--line);
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
}
.dlog-batch:first-child { margin-top: 0; border-top: 0; }
.dlog-batch .tick { color: var(--fg-2); }
.dlog-batch .tick b { color: var(--fg); font-weight: 600; }
.dlog-batch .zone { color: var(--fg-5); margin-left: 4px; }
.dlog-batch .meta { color: var(--fg-5); display: inline-flex; align-items: center; gap: 8px; }
.dlog-batch .meta .sep { color: var(--fg-5); }
.dlog-batch .meta .inc {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--fg-3);
}
.dlog-batch .meta .inc .d {
  width: 6px; height: 6px; border-radius: 50%;
}
.dlog-batch .meta .inc .d.warn  { background: var(--yellow); }
.dlog-batch .meta .inc .d.error { background: var(--red); }
.dlog-batch .live {
  margin-left: 2px;
  color: var(--green);
}

/* ---------- Rows ---------- */

.dlog-row {
  display: grid;
  grid-template-columns: var(--dlog-grid);
  gap: var(--dlog-gap);
  align-items: baseline;
  padding: 1.5px 4px 1.5px 6px;
  border-left: 2px solid transparent;
}
.dlog-row:hover { background: rgba(255,255,255,0.02); }

.dlog-row .time {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-4);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* stage token, written the way the raw log does: scrape[crude] */
.dlog-row .src {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-3);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dlog-row .src .ast { color: var(--fg-5); }

.dlog-row .msg {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--fg-2);
  line-height: 1.35;
  word-break: break-word;
}
.dlog-row .msg .num { color: var(--fg); }

/* severity treatments */
.dlog-row.sev-warn  { border-left-color: var(--yellow); }
.dlog-row.sev-warn .msg { color: var(--yellow); }

.dlog-row.sev-error { border-left-color: var(--red-bright); background: rgba(255,68,68,0.04); }
.dlog-row.sev-error .msg { color: var(--red); }
.dlog-row.sev-error .src { color: var(--red); }

/* expandable traceback */
.dlog-trace-toggle {
  grid-column: 3 / span 1;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-4);
  margin-top: 2px;
  width: fit-content;
}
.dlog-trace-toggle:hover { color: var(--red); }
.dlog-trace {
  grid-column: 3 / span 1;
  margin-top: 5px;
  margin-bottom: 3px;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 2px solid var(--red-bright);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--fg-2);
  white-space: pre;
  overflow-x: auto;
}
.dlog-row.sev-error.expanded,
.dlog-row.sev-error:has(.dlog-trace) { grid-template-rows: auto auto auto; }

/* ---------- Layout: log + inspector rail ---------- */

.dlog-layout { display: flex; align-items: flex-start; }
.dlog-main { flex: 1; min-width: 0; }

.dlog-cycle { transition: background .1s; }
.dlog-cycle.active { background: rgba(125,180,255,0.045); }
.dlog-batch { cursor: pointer; }
.dlog-batch.pinned .tick b { color: var(--blue); }
.dlog-batch.pinned::after {
  content: "pinned";
  font-size: 9px; color: var(--blue);
  border: 1px solid var(--blue-border); border-radius: 3px;
  padding: 0 5px; margin-left: 2px;
}

/* ---------- Window inspector ---------- */

.dlog-inspector {
  flex: 0 0 300px;
  align-self: flex-start;
  position: sticky;
  top: 0;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  margin-left: 20px;
  padding-left: 18px;
  padding-bottom: 16px;
  border-left: 1px solid var(--line);
}
.ins-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 8px;
  position: sticky; top: 0; background: var(--bg); z-index: 1;
}
.ins-head .ins-title { font-size: 13px; color: var(--fg); font-weight: 500; }
.ins-head .x { color: var(--fg-4); font-size: 17px; line-height: 1; padding: 0 2px; }
.ins-head .x:hover { color: var(--fg); }

.ins-empty { color: var(--fg-4); font-family: var(--mono); font-size: 11.5px; line-height: 1.6; padding: 12px 0; }

.ins-when {
  display: flex; align-items: baseline; gap: 7px;
  font-family: var(--mono);
  padding-bottom: 9px;
}
.ins-when .t { font-size: 15px; color: var(--fg); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.ins-when .zone { font-size: 9.5px; color: var(--fg-5); }
.ins-when .utc { font-size: 10.5px; color: var(--fg-4); margin-left: auto; }
.ins-when .pin { font-size: 9px; color: var(--blue); border: 1px solid var(--blue-border); border-radius: 3px; padding: 1px 5px; }

.ins-controls {
  display: flex; flex-direction: column; gap: 6px;
  padding-bottom: 8px;
}
.ins-seg-row { display: flex; align-items: center; gap: 10px; }
.ins-seg-row .lab {
  font-family: var(--mono); font-size: 9.5px;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-4); width: 36px;
}
.ins-seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ins-seg button {
  padding: 2px 10px; font-size: 11px; font-family: var(--mono);
  color: var(--fg-3); border-right: 1px solid var(--line);
  transition: background .12s, color .12s;
}
.ins-seg button:last-child { border-right: 0; }
.ins-seg button:hover { color: var(--fg); }
.ins-seg button.on { background: var(--bg-1); color: var(--fg); }

.ins-meta {
  display: flex; gap: 18px;
  font-family: var(--mono); font-size: 11px;
  padding: 8px 0 9px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.ins-meta i { color: var(--fg-4); font-style: normal; margin-right: 5px; }
.ins-meta span { color: var(--fg); font-variant-numeric: tabular-nums; }

.ins-section {
  font-family: var(--mono); font-size: 9.5px;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-4); margin: 14px 0 6px;
}
.ins-metric { padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.ins-metric .m-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ins-metric .m-label { font-size: 12px; color: var(--fg-2); }
.ins-metric .m-val {
  font-family: var(--mono); font-size: 14px; color: var(--fg);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.ins-metric .m-bot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 5px; }
.ins-spark { display: block; flex-shrink: 0; }
.ins-spark .line { fill: none; stroke: var(--fg-4); stroke-width: 1; }
.ins-spark .mean { stroke: var(--fg-5); stroke-width: 1; stroke-dasharray: 2 2; }
.ins-spark .cur { fill: var(--blue); stroke: var(--bg); stroke-width: 1; }
.ins-metric .m-delta {
  font-family: var(--mono); font-size: 11px;
  display: inline-flex; align-items: baseline; gap: 6px;
  white-space: nowrap; text-align: right;
}
.ins-metric .m-delta .ar { font-size: 8.5px; }
.ins-metric .m-delta .base { color: var(--fg-5); font-size: 9.5px; }
.m-delta.q  { color: var(--fg-4); }
.m-delta.n  { color: var(--fg-2); }
.m-delta.hi { color: var(--warm); }

/* ---- stage cards: multi-series chart + legend ---- */
.ins-stage { padding: 6px 0 7px; border-bottom: 1px solid var(--line-soft); }
.ins-stage .st-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: var(--mono); margin-bottom: 1px;
}
.st-head .st-name { font-size: 11px; color: var(--fg-2); letter-spacing: 0.02em; }
.st-head .st-base { font-size: 9px; color: var(--fg-5); }

.ins-mspark { display: block; width: 100%; height: 34px; margin: 2px 0 6px; }
.ins-mspark .line { fill: none; stroke-width: 1.2; }
.ins-mspark .cur  { stroke: var(--bg); stroke-width: 1; }
.ins-mspark .ser-fig  .line { stroke: var(--blue); }
.ins-mspark .ser-fig  .cur  { fill: var(--blue); }
.ins-mspark .ser-lat  .line { stroke: var(--warm); }
.ins-mspark .ser-lat  .cur  { fill: var(--warm); }
.ins-mspark .ser-cost .line { stroke: var(--green); }
.ins-mspark .ser-cost .cur  { fill: var(--green); }

.ins-leg { display: flex; flex-direction: column; gap: 2px; }
.leg-row { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 10.5px; }
.leg-row .sw { width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; background: var(--fg-5); }
.leg-row .sw.ser-fig  { background: var(--blue); }
.leg-row .sw.ser-lat  { background: var(--warm); }
.leg-row .sw.ser-cost { background: var(--green); }
.leg-row .leg-lbl { color: var(--fg-3); width: 52px; }
.leg-row .leg-val { color: var(--fg); font-variant-numeric: tabular-nums; }
.leg-row .leg-avg { color: var(--fg-5); font-variant-numeric: tabular-nums; }
.leg-row .leg-d {
  margin-left: auto; font-size: 10.5px;
  display: inline-flex; align-items: baseline; gap: 3px;
}
.leg-d .ar { font-size: 8px; }
.leg-d.q  { color: var(--fg-4); }
.leg-d.n  { color: var(--fg-2); }
.leg-d.hi { color: var(--warm); }

/* narrative breakdown grid */
.ins-narr-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 2px 14px; margin-top: 6px;
  font-family: var(--mono); font-size: 10.5px;
}
.ins-narr-grid .cell { display: flex; justify-content: space-between; gap: 8px; }
.ins-narr-grid .k { color: var(--fg-4); }
.ins-narr-grid .v { color: var(--fg-2); font-variant-numeric: tabular-nums; }
.ins-narr-legacy { color: var(--fg-5); font-family: var(--mono); font-size: 11px; padding: 4px 0 8px; line-height: 1.5; }

/* empty state */
.dlog-empty {
  padding: 40px 4px;
  text-align: center;
  color: var(--fg-4);
  font-family: var(--mono);
  font-size: 12px;
}
