:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1929;
  --surface-2: #132236;
  --surface-3: #182b43;
  --border: #263b54;
  --text: #eef5fb;
  --muted: #93a8bb;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --warning: #f59e0b;
  --critical: #fb7185;
  --info: #60a5fa;
  --shadow: 0 24px 70px rgba(0, 0, 0, .25);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 85% 10%, #102a40 0, var(--bg) 34%); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px; border-right: 1px solid var(--border); background: rgba(6, 15, 27, .92); backdrop-filter: blur(18px); display: flex; flex-direction: column; gap: 30px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; color: #041512; background: linear-gradient(135deg, #5eead4, #14b8a6); box-shadow: 0 8px 28px rgba(45, 212, 191, .22); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 1rem; letter-spacing: .01em; }
.brand span { margin-top: 2px; color: var(--muted); font-size: .82rem; }
nav { display: grid; gap: 8px; }
.nav-item { width: 100%; padding: 11px 13px; border: 1px solid transparent; border-radius: 11px; text-align: left; color: var(--muted); background: transparent; }
.nav-item:hover, .nav-item.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.sidebar-spacer { flex: 1; }
.connection-card { border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: var(--surface); }
.status-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; margin-bottom: 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px rgba(245, 158, 11, .12); }
.status-dot.online { background: var(--accent); box-shadow: 0 0 0 4px rgba(45, 212, 191, .12); }
.status-dot.offline { background: var(--critical); box-shadow: 0 0 0 4px rgba(251, 113, 133, .12); }

main { min-width: 0; padding: 0 34px 40px; }
.topbar { min-height: 116px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid rgba(38, 59, 84, .72); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.55rem, 3vw, 2.2rem); letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 1.08rem; letter-spacing: -.015em; }
.eyebrow { margin-bottom: 7px; color: var(--accent); text-transform: uppercase; letter-spacing: .13em; font-size: .68rem; font-weight: 750; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.backend-label { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .8rem; }

.primary-button, .secondary-button { border-radius: 10px; padding: 9px 13px; font-weight: 700; }
.primary-button { border: 1px solid #43ddca; background: var(--accent); color: #04211d; }
.primary-button:hover { background: #5eead4; }
.secondary-button { width: 100%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 1.5rem; }

.view { display: none; padding-top: 28px; }
.view.active { display: block; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 15px; }
.metric-card, .panel { border: 1px solid var(--border); background: linear-gradient(160deg, rgba(19, 34, 54, .96), rgba(11, 25, 41, .96)); box-shadow: var(--shadow); }
.metric-card { border-radius: 15px; padding: 18px; }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card span { font-size: .78rem; }
.metric-card strong { display: block; margin: 9px 0 5px; font-size: 1.85rem; letter-spacing: -.04em; }
.metric-card small { font-size: .72rem; }
.content-grid { display: grid; gap: 15px; margin-bottom: 15px; }
.content-grid.two-thirds { grid-template-columns: minmax(0, 2fr) minmax(290px, 1fr); }
.content-grid.half { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { min-width: 0; border-radius: 16px; padding: 18px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.panel-heading .eyebrow { margin-bottom: 4px; }
select, input, textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #091625; color: var(--text); padding: 10px 11px; outline: none; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45, 212, 191, .1); }
select { width: auto; min-width: 160px; }
textarea { resize: vertical; line-height: 1.5; }
label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .8rem; font-weight: 650; }
form .primary-button { margin-top: 10px; }

.graph-container { min-height: 390px; border: 1px solid rgba(38, 59, 84, .65); border-radius: 13px; overflow: hidden; background: radial-gradient(circle at center, rgba(30, 64, 87, .28), rgba(5, 14, 25, .65)); }
.graph-container.large { min-height: 610px; }
.graph-container svg { display: block; width: 100%; height: 100%; min-height: inherit; }
.graph-edge { stroke: #516b82; stroke-opacity: .65; stroke-width: 1.25; }
.graph-edge.highlight { stroke: var(--accent); stroke-width: 2.4; stroke-opacity: 1; }
.graph-node { cursor: pointer; transition: opacity .2s ease; }
.graph-node circle { stroke: rgba(255,255,255,.32); stroke-width: 1.5; }
.graph-node text { fill: var(--text); font-size: 10px; pointer-events: none; paint-order: stroke; stroke: #07111f; stroke-width: 3px; stroke-linejoin: round; }
.graph-node.dimmed, .graph-edge.dimmed { opacity: .12; }
.legend { display: flex; flex-wrap: wrap; gap: 9px 14px; margin-top: 12px; color: var(--muted); font-size: .72rem; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 9px; height: 9px; border-radius: 50%; }

.stack-list { display: grid; gap: 10px; max-height: 430px; overflow: auto; }
.anomaly-item { border: 1px solid var(--border); border-left: 3px solid var(--warning); border-radius: 10px; padding: 12px; background: rgba(7, 17, 31, .55); }
.anomaly-item.critical { border-left-color: var(--critical); }
.anomaly-item header { display: flex; justify-content: space-between; gap: 10px; }
.anomaly-item strong { font-size: .86rem; }
.anomaly-item p { margin: 8px 0 0; color: var(--muted); font-size: .78rem; }
.badge { padding: 3px 7px; border-radius: 999px; background: rgba(245,158,11,.14); color: #fbbf24; font-size: .65rem; text-transform: uppercase; letter-spacing: .07em; }
.badge.critical { background: rgba(251,113,133,.14); color: #fda4af; }
.empty-state { color: var(--muted); padding: 20px 0; text-align: center; }

.table-wrap { overflow: auto; max-height: 360px; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid rgba(38, 59, 84, .65); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 650; position: sticky; top: 0; background: var(--surface-2); }
td:nth-child(3) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.result-box { min-height: 106px; max-height: 320px; overflow: auto; margin: 14px 0 0; padding: 13px; border: 1px solid var(--border); border-radius: 10px; background: #06101c; color: #b8cad9; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
.result-box.tall { max-height: 520px; }
.code-input { font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.result-table { min-height: 490px; overflow: auto; color: var(--muted); }
.result-table table { min-width: 520px; }
.answer-card { margin-top: 18px; padding: 15px; border: 1px solid rgba(45,212,191,.32); border-radius: 11px; background: rgba(45,212,191,.07); line-height: 1.55; }
.narrow-panel { max-width: 980px; margin: 0 auto; }
.full-height { min-height: calc(100vh - 170px); }
.inline-controls { display: flex; gap: 9px; width: min(500px, 55%); }
.inline-controls input { min-width: 0; }
.inspector { margin-top: 14px; padding: 13px; border: 1px solid var(--border); border-radius: 11px; color: var(--muted); background: rgba(7, 17, 31, .5); }
.muted { color: var(--muted); line-height: 1.55; }

#backend-dialog { width: min(540px, calc(100% - 30px)); border: 1px solid var(--border); border-radius: 16px; padding: 20px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
#backend-dialog::backdrop { background: rgba(1, 7, 14, .76); backdrop-filter: blur(6px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.dialog-actions .secondary-button { width: auto; }

@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid.two-thirds, .content-grid.half { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 15px; border-right: 0; border-bottom: 1px solid var(--border); flex-direction: row; align-items: center; overflow-x: auto; }
  .brand span, .sidebar-spacer, .connection-card { display: none; }
  nav { display: flex; gap: 6px; }
  .nav-item { width: auto; white-space: nowrap; }
  main { padding: 0 15px 25px; }
  .topbar { min-height: 96px; }
  .backend-label { display: none; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { padding: 14px; }
  .metric-card strong { font-size: 1.45rem; }
  .panel { padding: 14px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .inline-controls { width: 100%; }
  .graph-container { min-height: 330px; }
}
