:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar h1 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.sidebar h2,
.sidebar h3 {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.95rem;
}

.caption {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 0.75rem;
}

.sidebar-footer {
  margin-top: 1.5rem;
  word-break: break-word;
}

.view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.view-btn,
.tab,
.run-btn,
.filter-btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
}

.view-btn {
  padding: 0.45rem 0.5rem;
}

.view-btn.active,
.tab.active,
.run-btn.active {
  background: color-mix(in srgb, var(--accent) 12%, white);
  border-color: color-mix(in srgb, var(--accent) 35%, white);
  color: var(--accent);
  font-weight: 600;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.filter-btn {
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  border-radius: 999px;
}

.filter-btn.active {
  background: color-mix(in srgb, var(--accent) 12%, white);
  border-color: color-mix(in srgb, var(--accent) 35%, white);
  color: var(--accent);
}

.run-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.run-picker-row {
  display: grid;
  grid-template-columns: 0.75rem 1fr;
  gap: 0.45rem;
  align-items: center;
}

.run-btn {
  text-align: left;
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
  word-break: break-word;
}

.run-status-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  display: inline-block;
}

.run-status-legend {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #475569;
  margin-bottom: 0.5rem;
}

.run-status-legend span {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.run-status-pill {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.run-meta {
  margin: 0.75rem 0;
  font-size: 0.85rem;
}

.run-meta dt {
  font-weight: 600;
  margin-top: 0.35rem;
}

.run-meta dd {
  margin: 0.1rem 0 0;
  color: var(--muted);
}

.main {
  padding: 1.5rem;
  max-width: 1100px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.panel.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.hidden {
  display: none !important;
}

.trace-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.trace-header h2 {
  margin: 0;
}

.run-path {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.35rem 0 0;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.45rem 0.85rem;
}

.tab-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}

.metric-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 600;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data-table th,
table.data-table td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

table.data-table th {
  background: #f1f5f9;
}

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

.msg-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent, #334155);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin: 0.65rem 0 1rem;
}

.role-pill {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
  margin-right: 0.5rem;
}

.msg-index {
  color: #94a3b8;
  font-size: 0.8rem;
}

.tool-chip {
  display: inline-block;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

pre.code {
  white-space: pre-wrap;
  font-size: 0.85rem;
  background: #f8fafc;
  padding: 0.5rem;
  border-radius: 6px;
  overflow-x: auto;
}

pre.code.warn {
  background: #fffbeb;
  border: 1px solid #fde68a;
}

details {
  margin: 0.35rem 0;
}

.bar-chart {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 3rem 1fr 4rem;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.82rem;
}

.bar-track {
  background: #f1f5f9;
  border-radius: 4px;
  height: 0.65rem;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.model-section {
  margin-bottom: 1.5rem;
}

.model-section h3 {
  margin: 0 0 0.25rem;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 82%, white);
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.auth-card {
  width: min(100%, 22rem);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}

.auth-card h2 {
  margin: 0 0 0.35rem;
}

.auth-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.75rem 0 0.35rem;
}

.auth-input {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-submit {
  width: 100%;
  margin-top: 0.85rem;
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, white);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
  cursor: pointer;
}

.auth-error {
  margin: 0.5rem 0 0;
  color: #b91c1c;
  font-size: 0.82rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

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