/* Explore drawer tabs and the four graph views (Flame, Trace, Pods, Agent).
   Hex colour literals appear only in the three categorical palette blocks below.
   Everywhere else colour comes from the tokens in style.css or from the palette tones.
   --accent and --accent-soft are used only on borders, outlines, bars, dots and
   thin underlines, never as the background of text. Every panel display rule is
   scoped with :not([hidden]) so that tabs.js can hide inactive panels. Motion lives
   only inside the reduced-motion query. */

/* ---- categorical palette: strong tones for bars, dots, swatches and borders;
        soft opaque tints for backgrounds behind text ---- */

:root {
  --g1: #2563eb; --g2: #7c3aed; --g3: #0f766e; --g4: #b45309;
  --g5: #be123c; --g6: #0369a1; --g7: #4d7c0f; --g8: #a21caf;
  --g1s: #dbe7fd; --g2s: #e9defd; --g3s: #d5efe9; --g4s: #fbe8d0;
  --g5s: #fbdde5; --g6s: #d6e9f6; --g7s: #e3efd2; --g8s: #f6dcf8;
}

html[data-theme="dark"] {
  --g1: #60a5fa; --g2: #a78bfa; --g3: #2dd4bf; --g4: #fbbf24;
  --g5: #fb7185; --g6: #38bdf8; --g7: #a3e635; --g8: #e879f9;
  --g1s: #1b2a4a; --g2s: #2b2245; --g3s: #123a36; --g4s: #3d2e0f;
  --g5s: #40202a; --g6s: #11344a; --g7s: #2c3a12; --g8s: #3a1f40;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --g1: #60a5fa; --g2: #a78bfa; --g3: #2dd4bf; --g4: #fbbf24;
    --g5: #fb7185; --g6: #38bdf8; --g7: #a3e635; --g8: #e879f9;
    --g1s: #1b2a4a; --g2s: #2b2245; --g3s: #123a36; --g4s: #3d2e0f;
    --g5s: #40202a; --g6s: #11344a; --g7s: #2c3a12; --g8s: #3a1f40;
  }
}

.tone-1 { --tone: var(--g1); --tone-soft: var(--g1s); }
.tone-2 { --tone: var(--g2); --tone-soft: var(--g2s); }
.tone-3 { --tone: var(--g3); --tone-soft: var(--g3s); }
.tone-4 { --tone: var(--g4); --tone-soft: var(--g4s); }
.tone-5 { --tone: var(--g5); --tone-soft: var(--g5s); }
.tone-6 { --tone: var(--g6); --tone-soft: var(--g6s); }
.tone-7 { --tone: var(--g7); --tone-soft: var(--g7s); }
.tone-8 { --tone: var(--g8); --tone-soft: var(--g8s); }

/* ---- tab strip (pinned under the drawer head; never wraps, scrolls sideways) ---- */

.explore-tabs {
  display: flex; flex: 0 0 auto; flex-wrap: nowrap; gap: 0.25rem;
  overflow-x: auto; overscroll-behavior-x: contain;
  background: var(--bg); border-bottom: 1px solid var(--border);
}

.explore-tabs [role="tab"] {
  flex: 0 0 auto; min-height: 44px; margin: 0; padding: 0.5rem 0.9rem;
  border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  background: transparent; color: var(--muted); font: inherit; font-weight: 500;
  white-space: nowrap; cursor: pointer;
}

.explore-tabs [role="tab"]:hover { background: var(--hover); }

.explore-tabs [role="tab"][aria-selected="true"] {
  border-bottom-color: var(--accent); color: var(--text); font-weight: 700;
}

.explore-tabs [role="tab"]:focus-visible,
.explore-panel:focus-visible,
button.span-head:focus-visible {
  /* Inset ring: the tab strip and panels scroll, so an outside ring would be clipped. */
  outline: 2px solid var(--accent); outline-offset: -2px;
}

/* ---- panels: only the active (not hidden) panel is shown and scrolls ---- */

.explore-panel[hidden] { display:none; }

.explore-panel {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 0.75rem 0.25rem 1rem; overflow-wrap: anywhere;
}

.explore-panel h3 { margin: 0.5rem 0 0.25rem; font-size: 1.05rem; }

.graph { margin: 0; }

.graph-note { margin: 0.25rem 0 0.75rem; color: var(--muted); font-size: 0.9rem; }

.graph-error {
  margin: 0.5rem 0; padding: 0.4rem 0.6rem; color: var(--text); font-weight: 700;
  border-left: 0.25rem solid var(--accent);
}

.graph-loading { margin: 0.5rem 0; color: var(--muted); font-style: italic; }

.graph-empty-text { margin: 0.5rem 0; color: var(--muted); }

/* ---- flame: height of a frame = number of listed leaf rows; colour = category ---- */

.flame {
  display: grid; grid-auto-rows: minmax(1.75rem, auto);
  grid-template-columns: 1.75rem 1.75rem minmax(4rem, 7rem) 1fr;
  gap: 0.25rem; align-items: stretch;
}

.frame {
  box-sizing: border-box; min-width: 0; margin: 0; padding: 0.2rem 0.35rem;
  border: 1px solid var(--border); border-left: 4px solid var(--tone, var(--border));
  background: var(--surface); color: var(--text);
  font-size: 0.85rem; line-height: 1.3; overflow-wrap: anywhere;
}

.frame-d0,
.frame-d1 { writing-mode: vertical-rl; font-weight: 700; text-align: center; }

.frame-d0 { background: var(--bg); }

.frame-d1 { background: var(--hover); }

.frame-d2 { font-weight: 600; overflow-wrap: break-word; } /* category names split only when one word cannot fit */

.frame-d2,
.frame-d3 { background: var(--tone-soft, var(--surface)); }

.frame-label { display: block; }

/* ---- trace: a waterfall. Each row is a label column and a lane column; the axis
        and every row head share one grid so bars line up with the ticks. ---- */

.trace-summary { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.85rem; }

.trace-axis,
.span-head {
  display: grid; grid-template-columns: minmax(7rem, 38%) 1fr; column-gap: 0.5rem;
  padding: 0 0.5rem; box-sizing: border-box; width: 100%;
}

.trace-axis { margin: 0 0 0.25rem; border-bottom: 1px solid var(--border); }

.span-head {
  align-items: stretch; margin: 0; background: transparent; color: var(--text);
  font: inherit; text-align: left; border: 0; border-radius: 0;
}

button.span-head { min-height: 44px; cursor: pointer; }

.trace-list .span-head:hover { background: var(--hover); }

.span-meta,
.trace-spacer { grid-column: 1; min-width: 0; }

.span-meta {
  display: flex; flex-wrap: wrap; align-items: center; align-content: center;
  gap: 0.2rem 0.5rem; padding: 0.4rem 0; overflow-wrap: anywhere;
}

.span-swatch {
  width: 0.7rem; height: 0.7rem; flex: none; border-radius: 2px;
  background: var(--tone, var(--muted));
}

/* The title may shrink and wrap beside its swatch; the date and badge wrap below only when they must. */
.span-title { flex: 1 1 4rem; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }

.span-root .span-title { font-weight: 700; }

.span-year .span-title { font-weight: 600; }

.span-date { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.span-count { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.span-private {
  padding: 0 0.4rem; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 0.75rem;
}

.trace-lane,
.span-track,
.trace-ticks { grid-column: 2; position: relative; min-width: 0; }

.trace-lane { margin-right: 0.4rem; overflow: visible; }

.span-track { height: auto; align-self: stretch; min-height: 1.6rem; margin-right: 0.4rem; overflow: visible; }

.trace-ticks { height: 1.2rem; margin-right: 0.4rem; }

.span-bar {
  position: absolute; top: 50%; transform: translateY(-50%);
  height: 0.9rem; min-width: 0.4rem; border-radius: 2px; box-sizing: border-box;
  background: var(--tone, var(--muted));
}

/* A parent bar reads as a bracket: soft fill with a strong outline over its children. */
.span-bar-group {
  background: var(--tone-soft, var(--surface));
  border: 2px solid var(--tone, var(--muted)); box-sizing: border-box;
}

.trace-tick {
  position: absolute; top: 0; bottom: 0; padding-left: 0.2rem;
  border-left: 1px solid var(--border); color: var(--muted);
  font-size: 0.75rem; line-height: 1; white-space: nowrap;
}
@media (max-width: 720px) {
  /* Narrow lanes cannot fit six year labels: keep the tick lines, label every other one. */
  .trace-tick:nth-child(even) { font-size: 0; padding: 0; }
  /* The last label hangs to the left of its tick so it never pushes past a narrow lane's right edge. */
  .trace-tick:last-child {
    padding-left: 0; padding-right: 0.2rem; border-left: 0;
    border-right: 1px solid var(--border); transform: translateX(-100%);
  }
}

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

.trace-list > li { margin: 0; border-bottom: 1px solid var(--border); }

/* Tree guides: a thin rule marks each nesting level in the label column. */
.span-d1 .span-meta { padding-left: 0.9rem; border-left: 1px solid var(--border); }

.span-d2 .span-meta { margin-left: 0.6rem; padding-left: 0.9rem; border-left: 1px solid var(--border); }

.span-details {
  list-style: none; margin: 0; padding: 0.4rem 0.5rem 0.4rem 1.2rem; border: 1px solid var(--border);
  border-top: 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere;
}

.span-details[hidden] { display: none; }

.trace-undated { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.85rem; }

/* ---- pods: a Kubernetes-style dashboard. Namespaces are cards with a coloured top
        edge; pods are tiles in a grid inside their namespace. ---- */

.cluster { display: grid; gap: 0.75rem; }

.cluster-cmd {
  margin: 0; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem; overflow-wrap: anywhere;
}

.cluster-stats { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.stat {
  display: grid; gap: 0.1rem; min-width: 6.5rem; box-sizing: border-box;
  margin: 0; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}

.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }

.stat-label { color: var(--muted); font-size: 0.8rem; }

.ns {
  display: grid; gap: 0.6rem; margin: 0; padding: 0.6rem 0.7rem 0.7rem;
  border: 1px solid var(--border); border-top: 4px solid var(--tone, var(--border));
  border-radius: 6px; background: var(--surface); color: var(--text); overflow-wrap: anywhere;
}

.ns-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.5rem;
}

.ns-icon {
  flex: none; width: 1rem; height: 1.1rem; background: var(--tone, var(--muted));
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.ns-title { margin: 0; font-size: 0.95rem; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }

.ns-slug {
  color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem; overflow-wrap: anywhere;
}

.ns-count {
  margin-left: auto; padding: 0 0.45rem; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums;
}

.pods {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.4rem; list-style: none; margin: 0; padding: 0;
}

.pod {
  display: grid; grid-template-columns: auto 1fr; align-items: start; column-gap: 0.4rem;
  min-width: 0; margin: 0; padding: 0.4rem 0.5rem;
  border: 1px solid var(--border); border-left: 3px solid var(--tone, var(--border));
  border-radius: 4px; background: var(--tone-soft, var(--surface)); color: var(--text);
  font-size: 0.85rem; overflow-wrap: anywhere;
}

.pod-dot {
  grid-row: span 2; width: 0.5rem; height: 0.5rem; margin-top: 0.3rem;
  border-radius: 50%; background: var(--tone, var(--muted));
}

.pod-name { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }

.pod-slug {
  min-width: 0; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem; overflow-wrap: anywhere;
}

/* ---- loop: a simplified cycle with its quoted steps ---- */

.loop { display: grid; justify-items: center; gap: 0.75rem; margin: 0; }

.loop-svg { display: block; width: 100%; max-width: 15rem; height: auto; }

.loop-node circle,
.loop-node rect { fill: var(--surface); stroke: var(--muted); stroke-width: 1.5; }

.loop-node text {
  fill: var(--text); font-size: 13px; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle;
}

.loop-arrow { stroke: var(--muted); stroke-width: 1.5; fill: none; }

.loop-dot { fill: var(--accent); stroke: var(--link); stroke-width: 1; transform-box: view-box; transform-origin: 120px 120px; }

.loop-steps {
  width: 100%; box-sizing: border-box; margin: 0; padding: 0.5rem 0.5rem 0.5rem 2rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.loop-steps li { margin: 0.35rem 0; overflow-wrap: anywhere; }

.loop-steps strong { font-weight: 700; }

.loop-steps span { display: block; color: var(--muted); font-style: italic; }

@media (prefers-reduced-motion: no-preference) {
  .loop-dot { animation: loop-travel 8s linear infinite; }

  @keyframes loop-travel {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }
}

/* ---- narrow screens: tighter padding and columns, nothing wider than the drawer ---- */

@media (max-width: 720px) {
  .explore-tabs [role="tab"] { padding: 0.5rem 0.7rem; }

  .explore-panel { padding: 0.5rem 0.15rem 0.75rem; }

  .flame { grid-template-columns: 1.75rem 1.75rem 6.25rem 1fr; gap: 0.2rem; }

  .frame { padding: 0.15rem 0.25rem; }

  .trace-axis,
  .span-head { column-gap: 0.4rem; }

  .span-d1 .span-meta { padding-left: 0.6rem; }

  .span-d2 .span-meta { margin-left: 0.35rem; padding-left: 0.6rem; }

  .ns { padding: 0.4rem 0.45rem 0.5rem; }

  .pods { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); }

  .loop-steps { padding-left: 1.6rem; }
}
