@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  color-scheme: light;
  --bg-start: #f5f8fb;
  --bg-end: #ecf1f5;
  --body-bg:
    radial-gradient(circle at 10% 10%, #ffffff 0%, rgba(255, 255, 255, 0) 28%),
    radial-gradient(circle at 90% 0%, #e3f0f8 0%, rgba(227, 240, 248, 0) 30%),
    linear-gradient(155deg, var(--bg-start), var(--bg-end));
  --panel: #ffffff;
  --panel-alt: #f6f9fc;
  --line: #d7e2ec;
  --line-strong: #c1cfdb;
  --text: #102132;
  --subtle: #5a6b7b;
  --title: #263748;
  --surface: #fbfdff;
  --active-bg: #e9f4fa;
  --header-bg: #edf4fa;
  --header-text: #334a5c;
  --row-stripe: #f9fcff;
  --primary: #155e75;
  --primary-strong: #0f4d5f;
  --good: #0f766e;
  --warn: #b45309;
  --bad: #be123c;
  --topbar-bg: linear-gradient(180deg, #f8fbff 0%, #f0f6fb 100%);
  --range-bg: #ffffff;
  --range-text: #334a5c;
  --range-active-bg: #e0f0f6;
  --range-active-border: #8eb9c8;
  --range-active-text: #0e4f64;
  --chart-grid: #e8eff4;
  --chart-text: #435568;
  --shadow: 0 10px 30px rgba(16, 33, 50, 0.08);
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg-start: #0b1320;
  --bg-end: #101b2d;
  --body-bg:
    radial-gradient(circle at 8% 12%, #17243a 0%, rgba(23, 36, 58, 0) 32%),
    radial-gradient(circle at 88% 4%, #173047 0%, rgba(23, 48, 71, 0) 28%),
    linear-gradient(160deg, var(--bg-start), var(--bg-end));
  --panel: #121d2c;
  --panel-alt: #152235;
  --line: #2a3b52;
  --line-strong: #355070;
  --text: #dbe6f4;
  --subtle: #93a9c2;
  --title: #e1ebf9;
  --surface: #122132;
  --active-bg: #1f3750;
  --header-bg: #193046;
  --header-text: #adc3da;
  --row-stripe: #16263a;
  --primary: #2aa1c0;
  --primary-strong: #1d8aa7;
  --good: #34d399;
  --warn: #f59e0b;
  --bad: #f43f5e;
  --topbar-bg: linear-gradient(180deg, #17263b 0%, #132236 100%);
  --range-bg: #132236;
  --range-text: #c8d8ec;
  --range-active-bg: #1d3850;
  --range-active-border: #316084;
  --range-active-text: #d3e8ff;
  --chart-grid: #24364d;
  --chart-text: #b0c3d8;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

@layer base {
  * {
    box-sizing: border-box;
  }

  body {
    @apply m-0 min-h-screen;
    font-family: 'Sora', 'Segoe UI', sans-serif;
    color: var(--text);
    background: var(--body-bg);
  }

  h2 {
    @apply mb-3 mt-0 text-lg;
    letter-spacing: -0.01em;
  }

  h3 {
    @apply mb-2 mt-0 text-sm;
    letter-spacing: 0.01em;
    color: var(--title);
  }
}

@layer components {
  .app-shell {
    @apply mx-auto my-4 p-3;
    width: min(1680px, calc(100vw - 2rem));
    max-width: 100%;
  }

  .layout {
    @apply grid gap-3;
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.375rem 0.5rem 0.625rem;
    margin-bottom: 0.625rem;
  }

  .top-bar h1 {
    @apply m-0;
    font-size: clamp(1.75rem, 2.4vw, 2.5rem);
    letter-spacing: -0.025em;
    font-weight: 700;
    color: var(--title);
    line-height: 1;
  }

  .brand {
    display: flex;
    align-items: baseline;
    gap: 0.625rem;
    min-width: 0;
  }

  .brand-live {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--subtle);
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  }

  .brand-live::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--good) 25%, transparent);
    animation: mv-pulse 2s ease-in-out infinite;
  }

  @keyframes mv-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
  }

  .top-actions {
    @apply flex items-center gap-2;
  }

  .theme-switch {
    display: inline-flex;
    align-items: center;
    padding: 2px;
    border-radius: 999px;
    background: var(--range-bg);
    border: 1px solid var(--line);
    gap: 0;
  }

  .theme-switch button {
    appearance: none;
    border: 0;
    background: transparent;
    cursor: pointer;
    width: 26px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: var(--subtle);
    font-family: inherit;
    transition: background 0.12s ease, color 0.12s ease;
    padding: 0;
  }

  .theme-switch button svg {
    width: 13px;
    height: 13px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .theme-switch button[aria-pressed='true'] {
    background: var(--panel);
    color: var(--title);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  }

  .panel {
    @apply rounded-2xl border p-4;
    background: var(--panel);
    border-color: var(--line-strong);
    box-shadow: var(--shadow);
    min-width: 0;
  }

  .analytics-head {
    @apply flex flex-wrap items-center justify-between gap-3;
    min-width: 0;
  }

  .range-group {
    @apply flex flex-wrap gap-2;
    min-width: 0;
  }

  .range-group button {
    @apply cursor-pointer rounded-md border px-2.5 py-1 text-xs;
    border-color: var(--line-strong);
    background: var(--range-bg);
    color: var(--range-text);
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  }

  .range-group button.active {
    background: var(--range-active-bg);
    border-color: var(--range-active-border);
    color: var(--range-active-text);
    font-weight: 700;
  }

  .chart-grid {
    @apply mt-2 grid gap-3;
    grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
    min-width: 0;
  }

  .chart-card {
    @apply flex min-h-[245px] flex-col rounded-xl border p-3;
    border-color: var(--line);
    background: var(--panel-alt);
    min-width: 0;
  }

  .chart-wrap {
    @apply relative h-[250px] w-full overflow-hidden;
    min-width: 0;
  }

  .chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
  }

  .muted {
    color: var(--subtle);
  }
}

@media (max-width: 980px) {
  .app-shell {
    width: calc(100vw - 1rem);
    margin-top: 0.5rem;
    padding: 0.25rem;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card {
    min-height: 210px;
  }

  .chart-wrap {
    height: 210px;
  }
}

@media (min-width: 1400px) {
  .layout {
    gap: 1rem;
  }

  .panel {
    padding: 1.05rem 1.1rem;
  }
}

/* ---------- Dense status strip (Health + Ingestor combined) ---------- */
.status-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.5rem 0.875rem;
  min-width: 0;
}

.ss-group {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  flex-wrap: wrap;
}

.ss-group-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  flex-shrink: 0;
}

.ss-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
  min-width: 0;
}

.ss-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  border-radius: 0.375rem;
  font-size: 0.75rem;
  line-height: 1.25;
  min-width: 0;
}

.ss-k {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.ss-v {
  color: var(--title);
  font-weight: 500;
  font-size: 0.75rem;
}

.ss-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

.ss-chip.ss-ok .ss-v {
  color: var(--good);
}

.ss-chip.ss-warn .ss-v {
  color: var(--warn);
}

.ss-chip.ss-bad .ss-v {
  color: var(--bad);
}

.ss-divider {
  width: 1px;
  height: 20px;
  background: var(--line-strong);
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .ss-divider {
    display: none;
  }
}

/* ---------- Session viewer ---------- */
.mv-root {
  font-family: 'Sora', 'Segoe UI', sans-serif;
  color: var(--text);
  min-width: 0;
}

.mono {
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.mv-section-title {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.mv-section-title h2 {
  margin: 0;
}

.mv-section-subtitle {
  font-size: 0.8125rem;
  color: var(--subtle);
}


.mv-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  border-radius: 0.75rem;
  margin-bottom: 0.75rem;
  min-width: 0;
}

.mv-search {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1 1 280px;
  min-width: 220px;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--line-strong);
  background: var(--range-bg);
  border-radius: 0.5rem;
  max-width: 100%;
}

.mv-search-icon {
  color: var(--subtle);
  font-size: 0.9375rem;
}

.mv-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
}

.mv-search-clear {
  border: 0;
  background: transparent;
  color: var(--subtle);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.mv-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
  flex: 1 1 auto;
  min-width: 0;
}

.mv-filter {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
}

.mv-filter-k {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-select {
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid var(--line-strong);
  background: var(--range-bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  max-width: 100%;
  min-width: 0;
}

.mv-filter-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--subtle);
}

.mv-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.mv-card {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  padding: 0.875rem 1rem;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  border-radius: 0.75rem;
  font: inherit;
  color: inherit;
  min-width: 0;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.12s ease,
    background 0.12s ease;
}

.mv-card:hover {
  border-color: var(--line-strong);
  background: var(--surface);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(16, 33, 50, 0.06);
}

.mv-card.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
  background: var(--surface);
}

.mv-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.375rem;
  min-width: 0;
}

.mv-card-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
}

.mv-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--title);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mv-card-time {
  font-size: 0.75rem;
  color: var(--subtle);
  flex-shrink: 0;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-card-prompt {
  font-size: 0.8125rem;
  color: var(--subtle);
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mv-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--subtle);
  min-width: 0;
}

.mv-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

.mv-meta-sep {
  color: var(--line-strong);
}

.mv-meta-item.mono,
.mv-card-time {
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.mv-status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.mv-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--panel-alt);
}

.mv-status-idle {
  opacity: 0.55;
}

.mv-status-pulse {
  animation: mv-glow 1.8s ease-in-out infinite;
}

.mv-status-label {
  display: none;
  font-size: 0.6875rem;
  text-transform: uppercase;
  color: var(--subtle);
  letter-spacing: 0.04em;
}

@keyframes mv-glow {
  0%, 100% {
    box-shadow:
      0 0 0 2px var(--panel-alt),
      0 0 0 4px rgba(34, 255, 136, 0.45),
      0 0 10px 2px rgba(34, 255, 136, 0.75);
  }
  50% {
    box-shadow:
      0 0 0 2px var(--panel-alt),
      0 0 0 6px rgba(34, 255, 136, 0.22),
      0 0 18px 5px rgba(34, 255, 136, 0.55);
  }
}

.mv-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.0625rem 0.4375rem;
  font-size: 0.6875rem;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  border-radius: 999px;
  background: var(--active-bg);
  color: var(--range-active-text);
  border: 1px solid var(--line);
  margin-right: 0.25rem;
}

.mv-chip-warn {
  background: rgba(180, 83, 9, 0.12);
  color: var(--warn);
  border-color: rgba(180, 83, 9, 0.3);
}

.mv-chip-bad {
  background: rgba(190, 18, 60, 0.12);
  color: var(--bad);
  border-color: rgba(190, 18, 60, 0.3);
}

.mv-iconbtn {
  width: 28px;
  height: 28px;
  border-radius: 0.5rem;
  border: 1px solid var(--line-strong);
  background: var(--range-bg);
  color: var(--subtle);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9375rem;
}

.mv-iconbtn:hover {
  background: var(--active-bg);
  color: var(--text);
}

.mv-tri {
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--subtle);
  font-size: 0.75rem;
}

.mv-tri[data-open='true'] {
  transform: rotate(90deg);
}

.mv-detail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.mv-detail-head {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.75rem;
  min-width: 0;
}

.mv-detail-titlerow {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
  flex-wrap: wrap;
  min-width: 0;
}

.mv-detail-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--title);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mv-viz-toggle {
  display: inline-flex;
  gap: 0.125rem;
  padding: 0.1875rem;
  border-radius: 0.5rem;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.mv-viz-toggle button {
  cursor: pointer;
  padding: 0.1875rem 0.5rem;
  border: 0;
  background: transparent;
  color: var(--subtle);
  border-radius: 0.375rem;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
}

.mv-viz-toggle button.is-active {
  background: var(--range-active-bg);
  color: var(--range-active-text);
  font-weight: 700;
}

.mv-detail-metagrid {
  display: grid;
  gap: 0.5rem 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
  font-size: 0.8125rem;
  min-width: 0;
}

.mv-meta-k {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-meta-v {
  color: var(--text);
  word-break: break-all;
}

.mv-turns {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: auto;
  min-width: 0;
}

.mv-turnblock {
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: var(--panel-alt);
  overflow: hidden;
}

.mv-turnblock-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

.mv-turnblock-head:hover {
  background: var(--active-bg);
}

.mv-turn-index {
  font-size: 0.75rem;
  color: var(--subtle);
  min-width: 24px;
}

.mv-turn-summary {
  flex: 1;
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.mv-turn-model {
  font-size: 0.8125rem;
  color: var(--title);
}

.mv-turn-stats {
  font-size: 0.75rem;
  color: var(--subtle);
}

.mv-turnblock-body {
  padding: 0.75rem 0.875rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.mv-flame {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.mv-flame-turn {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.mv-flame-prompt {
  border: 1px solid var(--line);
  background: var(--active-bg);
  border-radius: 0.625rem;
  padding: 0.625rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}

.mv-flame-prompt-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.mv-flame-prompt-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  font-weight: 700;
}

.mv-flame-prompt-meta {
  font-size: 0.6875rem;
  color: var(--subtle);
}

.mv-flame-prompt-text {
  font-size: 0.8125rem;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mv-flame-turn > .mv-turn-trace {
  padding: 0.25rem 0 0.5rem;
}

.mv-turn-chat {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.mv-bubble {
  border-radius: 0.625rem;
  padding: 0.625rem 0.8125rem;
  max-width: 90%;
}

.mv-bubble-user {
  background: var(--active-bg);
  border: 1px solid var(--line);
  align-self: flex-end;
}

.mv-bubble-assistant {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  align-self: flex-start;
}

.mv-bubble-role {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 0.25rem;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.mv-bubble-meta {
  text-transform: none;
  letter-spacing: 0;
  color: var(--subtle);
}

.mv-bubble-text {
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--text);
}

.mv-toolcall {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
  overflow: hidden;
}

.mv-toolcall.is-error {
  border-color: rgba(190, 18, 60, 0.4);
  background: rgba(190, 18, 60, 0.04);
}

.mv-toolcall-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4375rem 0.625rem;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

.mv-toolcall-head:hover {
  background: var(--active-bg);
}

.mv-toolcall-name {
  font-size: 0.8125rem;
  color: var(--primary);
  font-weight: 500;
}

.mv-toolcall-arg {
  font-size: 0.75rem;
  color: var(--subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.mv-toolcall-latency {
  font-size: 0.6875rem;
  color: var(--subtle);
}

.mv-toolcall-err {
  font-size: 0.6875rem;
  color: var(--bad);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-toolcall-body {
  padding: 0.5rem 0.625rem 0.625rem;
  border-top: 1px dashed var(--line);
  background: var(--panel-alt);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mv-tc-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mv-tc-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-tc-code {
  margin: 0;
  padding: 0.5rem 0.625rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
  max-width: 100%;
  min-width: 0;
}

.mv-turn-timeline {
  position: relative;
  padding-left: 1rem;
}

.mv-tl-spine {
  position: absolute;
  left: 0.625rem;
  top: 0.25rem;
  bottom: 0.25rem;
  width: 2px;
  background: var(--line);
  border-radius: 2px;
}

.mv-tl-node {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: 0.75rem;
  padding: 0.375rem 0;
  position: relative;
}

.mv-tl-dot {
  position: absolute;
  left: -0.4375rem;
  top: 0.5rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--primary);
}

.mv-tl-user .mv-tl-dot {
  border-color: var(--primary);
}

.mv-tl-assistant .mv-tl-dot {
  border-color: var(--good);
}

.mv-tl-tool_call .mv-tl-dot {
  background: var(--primary);
  border-color: var(--primary);
}

.mv-tl-node.is-error .mv-tl-dot {
  background: var(--bad);
  border-color: var(--bad);
}

.mv-tl-time {
  font-size: 0.6875rem;
  color: var(--subtle);
  padding-top: 0.25rem;
}

.mv-tl-body {
  min-width: 0;
}

.mv-tl-body-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.mv-tl-headrow {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.125rem;
}

.mv-tl-kind {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mv-tl-model {
  font-size: 0.6875rem;
  color: var(--subtle);
}

.mv-tl-text {
  font-size: 0.8125rem;
  color: var(--text);
  line-height: 1.55;
}

.mv-toolcall-body-inline {
  margin-top: 0.375rem;
  border-radius: 0.375rem;
  border: 1px solid var(--line);
}

.mv-turn-trace {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  min-width: 0;
}

.mv-tr-axis {
  position: relative;
  height: 18px;
  margin-left: 6.25rem;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 0.375rem;
}

.mv-tr-tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  color: var(--subtle);
  font-size: 0.6875rem;
}

.mv-tr-tick:first-child {
  transform: translateX(0);
}

.mv-tr-tick:last-child {
  transform: translateX(-100%);
}

.mv-tr-row {
  display: grid;
  grid-template-columns: 6.25rem 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.125rem 0;
  min-width: 0;
}

.mv-tr-label {
  font-size: 0.75rem;
  color: var(--subtle);
  text-align: right;
  padding-right: 0.5rem;
}

.mv-tr-track {
  position: relative;
  height: 20px;
  background: repeating-linear-gradient(to right, transparent 0, transparent 24px, var(--line) 24px, var(--line) 25px);
  border-radius: 0.25rem;
  min-width: 0;
}

.mv-tr-bar {
  position: absolute;
  top: 2px;
  bottom: 2px;
  min-width: 6px;
  border-radius: 0.25rem;
  border: 0;
  cursor: default;
  display: flex;
  align-items: center;
  padding: 0 0.4375rem;
  overflow: hidden;
  white-space: nowrap;
}

.mv-tr-bar-user {
  background: var(--primary);
  color: white;
}

.mv-tr-bar-assistant {
  background: var(--good);
  color: white;
}

.mv-tr-bar-duration {
  background: color-mix(in oklab, var(--primary) 60%, var(--good));
  box-shadow: inset 0 0 0 1px color-mix(in oklab, #fff 28%, transparent);
  color: white;
}

.mv-tr-bar-tool_call {
  background: var(--warn);
  color: #fff;
  cursor: pointer;
}

.mv-tr-bar.is-error {
  background: var(--bad);
}

.mv-tr-bar-text {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mv-tr-text {
  grid-column: 2;
  font-size: 0.75rem;
  color: var(--subtle);
  padding: 0.125rem 0 0.25rem;
  line-height: 1.5;
}

.mv-tr-expand {
  grid-column: 2;
  margin: 0.25rem 0 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  background: var(--panel-alt);
  padding: 0.5rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mv-turn-document {
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  line-height: 1.7;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mv-doc-line {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 0.625rem;
  padding: 0.25rem 0;
  border-bottom: 1px dotted var(--line);
}

.mv-doc-line:last-child {
  border-bottom: 0;
}

.mv-doc-speaker {
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  border-right: 1px solid var(--line);
  padding-right: 0.5rem;
  align-self: stretch;
}

.mv-doc-line-user .mv-doc-speaker {
  color: var(--primary);
}

.mv-doc-line-assistant .mv-doc-speaker {
  color: var(--good);
}

.mv-doc-text {
  color: var(--text);
}

.mv-doc-tool {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 0.25rem;
  margin: 0.25rem 0;
}

.mv-doc-tool-head {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  padding: 0.375rem 0.625rem;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

.mv-doc-marker {
  color: var(--warn);
  font-weight: 700;
}

.mv-doc-tool-name {
  color: var(--primary);
}

.mv-doc-tool-summary {
  color: var(--subtle);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mv-doc-tool-latency {
  color: var(--subtle);
  font-size: 0.6875rem;
}

.mv-doc-tool-body {
  padding: 0.5rem 0.625rem 0.625rem;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mv-v1 {
  position: relative;
}

.mv-v1-list {
  max-height: 72vh;
  overflow: auto;
  padding-right: 2px;
}

.mv-sidepanel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 40, 0.32);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: mv-fade 0.15s ease;
}

.mv-sidepanel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(780px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line-strong);
  box-shadow: -20px 0 60px rgba(16, 33, 50, 0.18);
  z-index: 41;
  display: flex;
  flex-direction: column;
  animation: mv-slide 0.22s cubic-bezier(0.22, 0.8, 0.25, 1);
}

.mv-sidepanel > .mv-detail {
  flex: 1;
  min-height: 0;
  padding: 1.25rem 1.5rem;
  overflow: auto;
}

@keyframes mv-slide {
  from {
    transform: translateX(12px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes mv-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.mv-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--subtle);
  font-size: 0.875rem;
  border: 1px dashed var(--line);
  border-radius: 0.75rem;
  background: var(--panel-alt);
}

@media (max-width: 980px) {
  .mv-sidepanel {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .top-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.5rem;
  }

  .top-actions,
  .theme-switch {
    width: 100%;
  }

  .theme-switch button {
    flex: 1 1 0;
  }

  .panel {
    padding: 0.875rem;
  }

  .analytics-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .range-group {
    width: 100%;
  }

  .range-group button {
    flex: 1 1 3rem;
  }

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

  .mv-search {
    flex-basis: auto;
    min-width: 0;
    width: 100%;
  }

  .mv-filters {
    width: 100%;
  }

  .mv-filter {
    flex: 1 1 8rem;
  }

  .mv-select {
    width: 100%;
  }

  .mv-filter-count {
    margin-left: 0;
    width: 100%;
  }

  .mv-sidepanel > .mv-detail {
    padding: 0.875rem;
  }

  .mv-viz-toggle {
    width: 100%;
  }

  .mv-viz-toggle button {
    flex: 1 1 0;
  }

  .mv-tr-axis {
    margin-left: 4.75rem;
  }

  .mv-tr-row {
    grid-template-columns: 4.75rem minmax(0, 1fr);
  }

  .mv-tr-label {
    overflow: hidden;
    padding-right: 0.25rem;
    text-overflow: ellipsis;
  }
}

[data-theme='dark'] .mv-chip {
  background: rgba(42, 161, 192, 0.15);
  border-color: rgba(42, 161, 192, 0.3);
  color: var(--range-active-text);
}

/* ---------- SessionNodes: flat vertical event timeline ---------- */
.mv-nodes {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.25rem 0 1rem;
}

.mv-nodes-spine {
  position: absolute;
  left: calc(60px + 0.625rem + 6px);
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--line-strong) 0.75rem,
    var(--line-strong) calc(100% - 0.75rem),
    transparent
  );
  pointer-events: none;
  z-index: 0;
}

.mv-node {
  position: relative;
  display: grid;
  grid-template-columns: 60px 12px 1fr;
  align-items: start;
  column-gap: 0.625rem;
  padding: 0.4375rem 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  z-index: 1;
}

.mv-node-time {
  font-size: 0.6875rem;
  color: var(--subtle);
  padding-top: 0.1875rem;
  text-align: right;
  letter-spacing: 0;
}

.mv-node-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 0.3125rem;
  background: var(--node-color, var(--primary));
  box-shadow: 0 0 0 3px var(--panel);
  flex-shrink: 0;
  justify-self: center;
}

.mv-node-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-top: 0.125rem;
}

.mv-node-user {
  --node-color: oklch(0.62 0.14 235);
}

.mv-node-assistant {
  --node-color: oklch(0.58 0.17 295);
}

.mv-node-tool {
  --node-color: oklch(0.68 0.15 70);
}

.mv-node-tool.is-error {
  --node-color: oklch(0.58 0.19 27);
}

.mv-node-boundary {
  --node-color: var(--subtle);
  padding: 0.625rem 0 0.5rem;
  border-top: 1px dashed var(--line);
  margin-top: 0.5rem;
}

.mv-node-boundary .mv-node-dot {
  width: 8px;
  height: 8px;
  margin-top: 0.5rem;
  background: var(--panel);
  box-shadow:
    0 0 0 3px var(--panel),
    inset 0 0 0 1.5px var(--subtle);
}

.mv-node-boundary .mv-node-body {
  flex-direction: row;
  align-items: baseline;
  gap: 0.5rem;
}

.mv-node-label {
  display: inline-block;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--node-color, var(--subtle));
  font-weight: 700;
  margin-right: 0.5rem;
}

.mv-node-text {
  display: block;
  color: var(--text);
  font-size: 0.8125rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.mv-node-meta {
  display: inline;
  color: var(--subtle);
  font-size: 0.6875rem;
}

.mv-node-toolhead {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.mv-node-toolhead:hover .mv-node-toolname {
  text-decoration: underline;
}

.mv-node-toolname {
  font-size: 0.8125rem;
  color: var(--title);
  font-weight: 600;
}

.mv-node-toolarg {
  font-size: 0.75rem;
  color: var(--subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  flex: 1;
  min-width: 0;
}

.mv-node-toollat {
  font-size: 0.6875rem;
  color: var(--subtle);
  background: var(--panel-alt);
  padding: 0.0625rem 0.375rem;
  border-radius: 0.25rem;
  border: 1px solid var(--line);
}

.mv-node-err {
  font-size: 0.6875rem;
  color: var(--bad);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mv-node-tri {
  font-size: 0.625rem;
  color: var(--subtle);
  transition: transform 0.15s;
  margin-left: auto;
}

.mv-node-tri[data-open='true'] {
  transform: rotate(90deg);
}

.mv-node-toolbody {
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.625rem;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.mv-node.is-open > .mv-node-dot {
  box-shadow:
    0 0 0 3px var(--panel),
    0 0 0 6px color-mix(in oklab, var(--node-color) 25%, transparent);
}
