:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdf9;
  --panel-muted: #f0ede6;
  --text: #191714;
  --muted: #6d6860;
  --soft: #958f84;
  --border: #dfd8cc;
  --border-strong: #c8beb0;
  --accent: #e06a4f;
  --accent-dark: #a63e2b;
  --blue: #3a7ca5;
  --green: #4f9d69;
  --shadow: 0 1px 2px rgba(32, 28, 22, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
table {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 160ms ease;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #171512;
  color: #f4efe6;
}

.sidebar-scroll {
  height: 100vh;
  overflow-y: auto;
  padding: 24px 22px 32px;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  min-height: 118px;
  padding: 8px 4px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #211f1b;
  color: #f4efe6;
  cursor: pointer;
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

.sidebar-toggle .expand-icon {
  display: none;
}

.sidebar-toggle:focus-visible {
  outline: 2px solid #d9d1c4;
  outline-offset: 2px;
}

.sidebar-kicker {
  margin: 0 0 8px;
  color: #a8a096;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sidebar-header h2 {
  margin: 0;
  color: #fffaf1;
  font-size: 27px;
  line-height: 1.05;
}

.sidebar-section {
  padding: 26px 4px 0;
}

.section-label,
.eyebrow {
  margin: 0 0 10px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar .section-label {
  color: #a8a096;
}

.dropdown-wrap {
  position: relative;
}

.project-select {
  width: 100%;
  min-height: 52px;
  padding: 12px 44px 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #22201c;
  color: #f4efe6;
  appearance: none;
  -webkit-appearance: none;
}

.project-select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.32);
  box-shadow: none;
}

.dropdown-icon {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: #a8a096;
  pointer-events: none;
}

.run-list {
  display: grid;
  gap: 10px;
}

.run-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 68px;
  padding: 13px 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: #201e1a;
  cursor: pointer;
}

.run-option.featured {
  border-color: rgba(255, 255, 255, 0.24);
  background: #24211d;
}

.run-option input {
  margin: 3px 0 0;
  accent-color: #d9d1c4;
}

.run-option-content strong,
.run-option-content span {
  display: block;
  min-width: 0;
}

.run-option-content strong {
  overflow-wrap: anywhere;
  color: #fffaf1;
  font-size: 14px;
  font-weight: 700;
}

.run-option-content span,
.empty-inline {
  color: #b7afa3;
  font-size: 12px;
  line-height: 1.45;
}

.main-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.navbar {
  display: flex;
  align-items: stretch;
  min-height: 50px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.nav-spacer {
  flex: 1 1 0;
}

.refresh-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  align-self: center;
  min-height: 34px;
  margin-right: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.refresh-button:hover:not(:disabled),
.refresh-button:focus-visible {
  border-color: var(--border-strong);
  color: var(--text);
}

.refresh-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.refresh-button svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.refresh-button.loading svg {
  animation: spin 0.8s linear infinite;
}

.nav-tabs {
  display: flex;
  padding-right: 14px;
}

.nav-link {
  padding: 12px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.nav-link.active {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 700;
}

.page {
  display: none;
  min-width: 0;
  padding: 26px 30px 38px;
}

.page.active {
  display: block;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 0;
  max-width: 900px;
  overflow-wrap: anywhere;
  font-size: 30px;
  line-height: 1.08;
}

.page-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.overview-stats,
.metric-spotlight {
  display: grid;
  grid-template-columns: repeat(5, minmax(112px, 1fr));
  gap: 10px;
}

.overview-stats:empty {
  display: none;
}

.metric-spotlight {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  margin-bottom: 18px;
}

.system-stats {
  grid-template-columns: repeat(4, minmax(130px, auto));
}

.stat,
.runtime-card,
.spotlight-card,
.metric-card,
.traces-table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat {
  padding: 10px 12px;
}

.runtime-card {
  min-width: 130px;
  padding: 10px 12px;
}

.stat span,
.runtime-card span,
.spotlight-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong,
.runtime-card strong,
.spotlight-card strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 20px;
  line-height: 1.1;
}

.runtime-card.wide {
  min-width: 170px;
}

.system-stats .stat.wide strong {
  font-size: 12px;
  line-height: 1.35;
}

.system-card .metric-card-head h3 {
  font-size: 16px;
}

.spotlight-card {
  min-width: 0;
  padding: 12px;
}

.mini-plot {
  margin-top: 8px;
}

.mini-plot svg {
  display: block;
  width: 100%;
  height: auto;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 16px;
}

.metric-card {
  min-width: 0;
  padding: 16px;
}

.metric-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto) 32px;
  gap: 10px;
  align-items: start;
}

.metric-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 17px;
}

.metric-card-head span,
.metric-empty {
  max-width: 360px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}

.metric-card-expand,
.chart-fullscreen-action {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.86);
  color: var(--muted);
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.metric-card-expand:hover,
.chart-fullscreen-action:hover {
  border-color: var(--border-strong);
  background: #fff8ef;
  color: var(--text);
  transform: translateY(-1px);
}

.metric-card-expand svg,
.chart-fullscreen-action svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plot-shell {
  position: relative;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffdf9, #f4f0e9);
}

.plot-shell svg {
  display: block;
  width: 100%;
  height: 260px;
}

.plot-interactive {
  position: relative;
  min-width: 0;
}

.plot-interactive.compact svg {
  height: auto;
}

.plot-axis {
  stroke: var(--border-strong);
  stroke-width: 1.35;
}

.plot-grid {
  stroke: rgba(109, 104, 96, 0.18);
  stroke-width: 1;
}

.plot-grid.vertical {
  stroke: rgba(109, 104, 96, 0.1);
}

.plot-x-label,
.plot-y-label,
.plot-axis-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.plot-y-label {
  text-anchor: end;
}

.plot-x-label,
.plot-axis-label.x {
  text-anchor: middle;
}

.plot-line {
  fill: none;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.plot-terminal {
  fill: var(--panel);
  stroke-width: 1.8;
  vector-effect: non-scaling-stroke;
}

.plot-hitbox {
  fill: transparent;
  cursor: crosshair;
  pointer-events: all;
}

.plot-hover {
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none;
}

.plot-hover.active {
  opacity: 1;
}

.plot-hover-line {
  stroke: rgba(25, 23, 20, 0.28);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  vector-effect: non-scaling-stroke;
}

.plot-hover-point {
  fill: var(--panel);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.plot-tooltip {
  position: absolute;
  z-index: 2;
  display: none;
  min-width: 132px;
  max-width: min(240px, calc(100% - 16px));
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.97);
  box-shadow: 0 8px 24px rgba(32, 28, 22, 0.14);
  color: var(--text);
  pointer-events: none;
}

.plot-tooltip.active {
  display: block;
}

.plot-tooltip strong,
.plot-tooltip span {
  display: block;
  overflow-wrap: anywhere;
}

.plot-tooltip strong {
  margin-bottom: 3px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
}

.plot-tooltip span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

body.chart-fullscreen-open {
  overflow: hidden;
}

.chart-fullscreen-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(25, 23, 20, 0.66);
  backdrop-filter: blur(8px);
}

.chart-fullscreen-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1180px, 100%);
  max-height: min(94vh, 920px);
  overflow: hidden;
  border: 1px solid rgba(255, 253, 249, 0.38);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(25, 23, 20, 0.34);
}

.chart-fullscreen-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.chart-fullscreen-heading {
  min-width: 0;
}

.chart-fullscreen-heading h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 20px;
  line-height: 1.2;
}

.chart-fullscreen-heading span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.chart-fullscreen-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.chart-fullscreen-actions .chart-fullscreen-action {
  width: 34px;
  height: 34px;
}

.chart-fullscreen-plot {
  min-width: 0;
  padding: 18px 34px 12px;
  cursor: grab;
  touch-action: none;
}

.chart-fullscreen-panel.is-panning .chart-fullscreen-plot {
  cursor: grabbing;
}

.chart-fullscreen-plot .plot-hitbox {
  cursor: grab;
}

.chart-fullscreen-panel.is-panning .plot-hitbox {
  cursor: grabbing;
}

.chart-fullscreen-plot .plot-interactive {
  min-height: 360px;
}

.chart-fullscreen-plot svg {
  display: block;
  width: 100%;
  height: min(62vh, 620px);
}

.chart-fullscreen-plot .plot-x-label,
.chart-fullscreen-plot .plot-y-label,
.chart-fullscreen-plot .plot-axis-label {
  font-size: 10px;
  font-weight: 650;
}

.chart-fullscreen-plot .plot-line {
  stroke-width: 2;
}

.chart-fullscreen-plot .plot-tooltip {
  z-index: 4;
  max-width: min(300px, calc(100% - 16px));
}

.chart-fullscreen-legend {
  max-height: 112px;
  overflow: auto;
  margin: 0;
  padding: 0 18px 16px;
}

.metric-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 12px;
}

.metric-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.metric-legend-item.primary {
  color: var(--accent-dark);
  font-weight: 700;
}

.metric-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.traces-table-wrap {
  overflow: auto;
}

.traces-table-wrap.loading {
  overflow: visible;
  border: none;
  background: transparent;
  box-shadow: none;
}

.traces-table-wrap.loading .traces-table thead {
  display: none;
}

.traces-table-wrap.loading .traces-table td {
  display: block;
  padding: 0;
  border: none;
}

.trace-loading-cell .empty-panel {
  width: 100%;
  min-height: 116px;
}

.traces-table {
  width: 100%;
  border-collapse: collapse;
}

.traces-table thead {
  background: var(--panel-muted);
}

.traces-table th,
.traces-table td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.traces-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trace-id {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.trace-request {
  max-width: 520px;
  overflow-wrap: anywhere;
}

.trace-detail {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.empty-row,
.empty-panel {
  color: var(--muted);
  text-align: center;
}

.empty-panel {
  grid-column: 1 / -1;
  padding: 44px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--panel);
}

.loading-panel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(109, 104, 96, 0.22);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 56px minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar-scroll {
  padding: 14px 10px;
  overflow: hidden;
}

body.sidebar-collapsed .sidebar-header {
  justify-content: center;
  min-height: auto;
  padding: 0;
  border-bottom: none;
}

body.sidebar-collapsed .sidebar-header > div,
body.sidebar-collapsed .sidebar-section {
  display: none;
}

body.sidebar-collapsed .sidebar-toggle .collapse-icon {
  display: none;
}

body.sidebar-collapsed .sidebar-toggle .expand-icon {
  display: block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .overview-stats,
  .metric-spotlight {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

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

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  body.sidebar-collapsed .sidebar {
    display: none;
  }

  .sidebar-scroll {
    height: auto;
  }

  .page {
    padding: 18px;
  }

  .page-header {
    display: block;
  }

  .overview-stats,
  .metric-spotlight {
    grid-template-columns: 1fr;
    margin-top: 16px;
  }

  .metric-card-head {
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .metric-card-head span {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: none;
    text-align: left;
  }

  .chart-fullscreen-backdrop {
    padding: 10px;
  }

  .chart-fullscreen-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .chart-fullscreen-actions {
    justify-content: flex-end;
  }

  .chart-fullscreen-plot {
    padding: 12px 14px;
  }

  .chart-fullscreen-plot .plot-interactive {
    min-height: 300px;
  }
}
