:root {
  --bg: #06070c;
  --bg-2: #0a0c15;
  --panel: #0f1220;
  --panel-2: #141830;
  --line: rgba(148, 163, 184, 0.12);
  --line-strong: rgba(148, 163, 184, 0.22);
  --ink: #e9ecf5;
  --ink-2: #c7cde0;
  --muted: #8b93ab;
  --muted-2: #6b7390;
  --accent: #6366f1;
  --violet: #8b5cf6;
  --accent-2: #22d3ee;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #22d3ee 110%);
  --grad-soft: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(34, 211, 238, 0.15));
  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 20px 50px -24px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  color: var(--ink);
  background: radial-gradient(120% 80% at 10% -10%, #121735 0%, transparent 55%),
    radial-gradient(100% 80% at 110% 10%, #0a1830 0%, transparent 55%),
    var(--bg);
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

/* ---------- background decoration ---------- */

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(120px);
  opacity: 0.55;
  z-index: 0;
  pointer-events: none;
}

.orb-a {
  width: 560px;
  height: 560px;
  background: radial-gradient(closest-side, #6366f1 0%, transparent 70%);
  top: -160px;
  left: -120px;
}

.orb-b {
  width: 620px;
  height: 620px;
  background: radial-gradient(closest-side, #22d3ee 0%, transparent 70%);
  bottom: -220px;
  right: -180px;
  opacity: 0.35;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(148, 163, 184, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 20%, black 40%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 20%, black 40%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

/* ---------- shell ---------- */

.shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: 0;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px;
  background: linear-gradient(180deg, rgba(15, 18, 32, 0.85), rgba(10, 12, 21, 0.92));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--grad);
  color: #0a0c15;
  box-shadow: 0 10px 30px -10px rgba(99, 102, 241, 0.7);
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-text strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.brand-text span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
}

.nav button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav button span {
  font-size: 14px;
  font-weight: 500;
}

.nav button:hover {
  color: var(--ink);
  background: rgba(148, 163, 184, 0.06);
}

.nav button.active {
  color: var(--ink);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(34, 211, 238, 0.08));
  border-color: rgba(99, 102, 241, 0.35);
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.1);
}

.sidebar-spacer {
  flex: 1;
}

.status-card {
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(15, 18, 32, 0.65);
  border: 1px solid var(--line);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.status-card strong {
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
}

.status-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- main ---------- */

.main {
  min-width: 0;
  padding: 26px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 4px;
}

.topbar-title h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.015em;
  background: linear-gradient(180deg, #ffffff 0%, #c7cde0 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar-title p {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

.connection {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.connection input {
  padding: 9px 12px;
  background: rgba(15, 18, 32, 0.7);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  min-width: 220px;
  font-size: 13px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.connection input::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

.connection input:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.6);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

/* ---------- workspace strip ---------- */

.workspace-strip {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(15, 18, 32, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.field > span {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field select,
.field input,
.field textarea,
select,
input,
textarea {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(10, 12, 21, 0.7);
  color: var(--ink);
  font-size: 13.5px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea {
  resize: vertical;
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  line-height: 1.55;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%238b93ab' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M3 4.5l3 3 3-3'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

#toast {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--accent-2);
  min-height: 18px;
}

/* ---------- buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(15, 18, 32, 0.6);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  white-space: nowrap;
}

.button svg {
  width: 16px;
  height: 16px;
}

.button:hover {
  border-color: rgba(148, 163, 184, 0.4);
  background: rgba(20, 24, 48, 0.8);
}

.button:active {
  transform: translateY(1px);
}

.button.primary {
  background: var(--grad);
  border-color: transparent;
  color: #0a0c15;
  font-weight: 650;
  box-shadow: 0 10px 28px -12px rgba(99, 102, 241, 0.75);
}

.button.primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 14px 34px -10px rgba(99, 102, 241, 0.85);
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-2);
}

.button.ghost:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.button.small {
  padding: 7px 12px;
  font-size: 12.5px;
}

.button.full {
  width: 100%;
}

/* ---------- views & grid ---------- */

.view {
  display: none;
  flex-direction: column;
  gap: 18px;
}

.view.active {
  display: flex;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 1100px) {
  .grid.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .grid.two,
  .grid.three {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- panels ---------- */

.panel {
  position: relative;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(15, 18, 32, 0.82), rgba(10, 12, 21, 0.82));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.35), rgba(34, 211, 238, 0.15) 45%, transparent 80%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  opacity: 0.6;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.panel-sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- form grid ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

.form-grid .field,
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-grid .full {
  grid-column: 1 / -1;
}

/* ---------- chat ---------- */

.chat-panel {
  min-height: 540px;
}

.chat-log {
  flex: 1;
  min-height: 280px;
  max-height: 440px;
  overflow-y: auto;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(6, 7, 12, 0.7);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.2) transparent;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 999px;
}

.chat-log:empty::before {
  content: "Messages will appear here.";
  color: var(--muted-2);
  font-size: 13px;
  margin: auto;
}

.message {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--grad);
  color: #0a0c15;
  border-bottom-right-radius: 5px;
  font-weight: 500;
}

.message.assistant {
  align-self: flex-start;
  background: rgba(20, 24, 48, 0.8);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-form textarea {
  flex: 1;
  min-height: 60px;
  max-height: 200px;
}

/* ---------- list items ---------- */

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 540px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.18) transparent;
}

.list.compact {
  max-height: 420px;
}

.list::-webkit-scrollbar {
  width: 6px;
}

.list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.18);
  border-radius: 999px;
}

.list .item {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(10, 12, 21, 0.7);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.list .item strong {
  color: var(--ink);
  font-weight: 600;
  font-size: 13.5px;
}

.list .item p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  word-break: break-word;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(16, 185, 129, 0.14);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.pill.warn {
  background: rgba(245, 158, 11, 0.14);
  color: var(--warn);
  border-color: rgba(245, 158, 11, 0.28);
}

.list .item > .button {
  align-self: flex-start;
  margin-top: 4px;
}

/* empty placeholder rendered via `empty()` helper */
.list > p.item {
  color: var(--muted);
  font-style: normal;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 18px;
}

/* ---------- output pre ---------- */

.output {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: rgba(6, 7, 12, 0.8);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 420px;
  overflow-y: auto;
}

/* ---------- metric grid ---------- */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

@media (max-width: 560px) {
  .metric-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.metric {
  position: relative;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(15, 18, 32, 0.82), rgba(10, 12, 21, 0.82));
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(34, 211, 238, 0.14) 55%, transparent);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  opacity: 0.5;
}

.metric-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 500;
}

.metric strong {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.metric-sub {
  font-size: 12px;
  color: var(--muted-2);
}

/* ---------- responsive sidebar ---------- */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 16px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 0;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
  }

  .nav button {
    padding: 8px 11px;
  }

  .nav button span {
    display: none;
  }

  .sidebar-spacer {
    display: none;
  }

  .status-card {
    flex: 1 1 100%;
  }

  .main {
    padding: 18px 16px 36px;
  }

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

  .connection input {
    min-width: 0;
    flex: 1;
  }
}

/* ---------- scrollbars globally ---------- */

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.18) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.18);
  border-radius: 999px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}
