:root {
  color-scheme: dark;
  --bg-deep: #060913;
  --bg-mid: #0c1324;
  --glass-1: rgba(15, 23, 42, 0.56);
  --glass-2: rgba(24, 36, 62, 0.62);
  --glass-3: rgba(17, 26, 46, 0.84);
  --border-spec: rgba(255, 255, 255, 0.14);
  --border-subtle: rgba(148, 163, 184, 0.16);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-indigo: #6366f1;
  --accent-wood: #d4a373;
  --grad-primary: linear-gradient(135deg, #2563eb 0%, #0ea5e9 55%, #38bdf8 100%);
  --grad-accent: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --grad-wood: linear-gradient(135deg, #c69c6d 0%, #e6b88a 100%);
  --grad-surface: linear-gradient(160deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.015) 100%);
  --shadow-elev-1: 0 12px 32px -8px rgba(2, 6, 23, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  --shadow-elev-2: 0 16px 36px -10px rgba(2, 6, 23, 0.72), 0 2px 8px rgba(14, 165, 233, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  --shadow-elev-3: 0 28px 64px -12px rgba(0, 0, 0, 0.86), 0 0 40px rgba(56, 189, 248, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

* {
  box-sizing: border-box;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 15%, #131f3b 0%, var(--bg-mid) 45%, var(--bg-deep) 100%);
  color: var(--text-main);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Level 0: Atmospheric Canvas Gradients */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(90px);
  opacity: 0.36;
}

.orb-1 {
  width: 520px;
  height: 520px;
  top: -140px;
  left: -100px;
  background: radial-gradient(circle, #0ea5e9 0%, rgba(14, 165, 233, 0) 70%);
}

.orb-2 {
  width: 560px;
  height: 560px;
  bottom: -180px;
  right: -100px;
  background: radial-gradient(circle, #6366f1 0%, rgba(99, 102, 241, 0) 70%);
}

.orb-3 {
  width: 380px;
  height: 380px;
  top: 38%;
  left: 44%;
  background: radial-gradient(circle, rgba(198, 156, 109, 0.55) 0%, rgba(198, 156, 109, 0) 70%);
}

/* Elevation & Glass Tiers */
.glass-panel {
  background: var(--grad-surface), var(--glass-1);
  backdrop-filter: blur(18px) saturate(145%);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
  border: 1px solid var(--border-spec);
  border-radius: 18px;
}

.glass-card {
  background: var(--grad-surface), var(--glass-2);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
}

.glass-modal {
  background: var(--grad-surface), var(--glass-3);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 20px;
}

.elev-1 { box-shadow: var(--shadow-elev-1); }
.elev-2 { box-shadow: var(--shadow-elev-2); }
.elev-3 { box-shadow: var(--shadow-elev-3); }

/* Workspace Grid */
.workspace {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px minmax(360px, 1.05fr) minmax(420px, 1.15fr);
  gap: 14px;
  height: 100vh;
  padding: 14px;
}

/* Buttons & Inputs */
.btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--grad-primary);
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.3);
}

.btn-accent {
  background: var(--grad-accent);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.btn-danger {
  background: linear-gradient(135deg, #b91c1c 0%, #ef4444 100%);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.full-width { width: 100%; }

input, textarea, .glass-select {
  background: rgba(6, 10, 22, 0.68);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, .glass-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

/* Login Overlay */
.overlay-screen {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 410px;
  padding: 28px;
}

.brand-header h1 {
  margin: 10px 0 4px;
  font-size: 24px;
  background: linear-gradient(90deg, #f8fafc 0%, #bae6fd 65%, #e6b88a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.9px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--grad-wood);
  color: #0f172a;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: #cbd5e1;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 14px;
  min-height: 0;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

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

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.09);
  transform: translateY(-1px);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.45), rgba(99, 102, 241, 0.35));
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.2);
}

.nav-hint {
  font-size: 10.5px;
  font-weight: 500;
  color: #bae6fd;
  opacity: 0.85;
}

.sidebar-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.conv-item {
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.conv-item:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.conv-item.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.34), rgba(14, 165, 233, 0.2));
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.16);
}

.conv-item-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-pill {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #bae6fd;
}

.usage-text {
  font-size: 11px;
  color: var(--text-muted);
}

.footer-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Chat & Inspector Panes */
.chat-pane, .inspector-pane {
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  min-height: 0;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.pane-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

.chat-stream {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.msg-bubble {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.55) 0%, rgba(14, 165, 233, 0.42) 100%);
  border: 1px solid rgba(56, 189, 248, 0.38);
  box-shadow: var(--shadow-elev-2);
}

.msg-assistant {
  align-self: flex-start;
  background: var(--grad-surface), rgba(30, 41, 59, 0.65);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-elev-2);
}

.chat-composer {
  display: flex;
  gap: 10px;
  padding: 10px;
  align-items: flex-end;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
}

/* Inspector Stage */
.gate-card {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.gate-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}

.status-PASS { background: rgba(21, 128, 61, 0.85); color: #fff; }
.status-WARN { background: rgba(180, 83, 9, 0.88); color: #fff; }
.status-FAIL { background: rgba(185, 28, 28, 0.88); color: #fff; }

.tab-bar {
  display: flex;
  gap: 6px;
  background: rgba(6, 10, 22, 0.48);
  padding: 5px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn.active {
  background: var(--grad-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.28);
}

.inspector-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
}

.empty-stage {
  margin: auto;
  max-width: 380px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  padding: 20px;
}

.artifact-frame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 12px;
}

.svg-viewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 12px;
  background: rgba(248, 250, 252, 0.96);
  border-radius: 12px;
}

.svg-viewport img {
  max-width: 100%;
  height: auto;
  display: block;
}

.report-preview {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 14px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: #e2e8f0;
}

.download-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Modals & Admin Table */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-box {
  width: 100%;
  max-width: 440px;
  padding: 22px;
}

.modal-wide {
  max-width: 860px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.banner-error {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  background: rgba(185, 28, 28, 0.28);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

.banner-ok {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  background: rgba(21, 128, 61, 0.28);
  border: 1px solid rgba(74, 222, 128, 0.45);
  color: #bbf7d0;
}

.settings-pane {
  grid-column: 2 / 4;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  min-height: 0;
}

.settings-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}

.settings-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title-row h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.card-title-row p {
  margin: 0;
}

.llm-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.llm-actions {
  display: flex;
  justify-content: flex-end;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1.3fr 1.1fr 1.1fr 0.7fr 0.65fr 0.65fr auto;
  gap: 10px;
  align-items: end;
}

.admin-table-wrap {
  max-height: 45vh;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.admin-table th, .admin-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.admin-table th {
  background: rgba(15, 23, 42, 0.85);
  color: var(--text-muted);
  position: sticky;
  top: 0;
}

@media (max-width: 1120px) {
  body { overflow: auto; }
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }
  .settings-pane { grid-column: 1; }
  .chat-pane, .inspector-pane { min-height: 520px; }
  .admin-grid, .llm-grid { grid-template-columns: 1fr 1fr; }
}
