:root {
  color-scheme: dark;
  --bg: #0d0f0b;
  --surface: #141812;
  --surface-2: #191e17;
  --surface-3: #20261d;
  --field: #0f120d;
  --line: #2b3328;
  --line-strong: #46523f;
  --text: #eef1eb;
  --muted: #a1aa99;
  --subtle: #707969;
  --green: #23c15f;
  --green-dark: #13783a;
  --gold: #c8b889;
  --danger: #d58a70;
  --shadow: 0 22px 60px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, .018) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px;
  color: var(--text);
  font: 14px/1.55 "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button, input, textarea { font: inherit; }
button {
  height: 38px;
  border: 1px solid var(--green-dark);
  border-radius: 6px;
  background: var(--green);
  color: #061009;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
}
button.secondary {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--line-strong);
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
  outline: none;
}
input { height: 38px; padding: 0 11px; }
textarea {
  min-height: 360px;
  padding: 12px;
  resize: vertical;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}
input:focus, textarea:focus {
  border-color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(35, 193, 95, .1);
}
label { display: grid; gap: 6px; }
label span, .eyebrow, .section-label { color: var(--muted); font-size: 12px; }
h1, h2, p { margin: 0; }
h1 { font-size: 25px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.25; }

.shell {
  display: grid;
  grid-template-columns: 344px minmax(520px, 1fr) 420px;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 12px;
  overflow: hidden;
}

.sidebar,
.workspace,
.terminal {
  min-width: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 24, 18, .96);
  box-shadow: var(--shadow);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 16px;
  padding: 16px;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #d7e5d8;
  color: #0c140d;
  font-weight: 850;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 2px; color: var(--subtle); font-size: 12px; }

.auth-card,
.config-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 13px;
}

.auth-card {
  display: grid;
  gap: 10px;
}

.section-label,
.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.connection {
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--field);
}
.connection.ok {
  color: var(--green);
  border-color: rgba(35, 193, 95, .55);
  background: rgba(35, 193, 95, .08);
}

.config-card {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 0;
  overflow: hidden;
}

.config-headline h2 {
  font-size: 15px;
  line-height: 1.1;
  white-space: nowrap;
}

.workspace {
  padding: 16px;
  overflow: auto;
}

.topbar,
.panel-head,
.inspector-head,
.terminal-head,
.top-actions,
.save-actions,
.terminal-actions {
  display: flex;
  align-items: center;
}
.topbar,
.panel-head,
.inspector-head,
.terminal-head {
  justify-content: space-between;
  gap: 16px;
}
.top-actions,
.save-actions,
.terminal-actions { gap: 8px; }

.config-card .inspector-head {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 10px;
}

.config-card .save-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.config-card .save-actions button {
  width: 100%;
  min-width: 0;
  padding: 0 8px;
}

.message {
  max-width: 360px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.message.ok { color: var(--green); }
.message.error { color: var(--danger); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 15px;
}
.metric-grid article {
  min-height: 118px;
  display: grid;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 13px;
}
.metric-grid span, .metric-grid small { color: var(--muted); }
.metric-grid strong { font-size: 30px; line-height: 1; }
.metric-grid small { font-size: 12px; }

.panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 15px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(35, 193, 95, .4);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--green);
  background: rgba(35, 193, 95, .07);
  font-size: 12px;
}
.badge.muted {
  color: var(--muted);
  border-color: var(--line-strong);
  background: #11150f;
}

.route-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.route-step {
  position: relative;
  min-height: 96px;
  display: grid;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #10140f;
  padding: 12px;
}
.route-step::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -9px;
  width: 9px;
  border-top: 1px solid var(--line-strong);
}
.route-step:last-child::after { display: none; }
.route-step.strong {
  border-color: rgba(35, 193, 95, .55);
  background: rgba(35, 193, 95, .08);
}
.route-step b { color: var(--text); }
.route-step span { color: var(--muted); font-size: 12px; }

.search-config {
  display: grid;
  grid-template-columns: 132px minmax(220px, 1fr) 96px 96px;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}
.switch-line {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--field);
  padding: 0 10px;
}
.switch-line input { width: auto; height: auto; }

.session-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  margin-top: 12px;
}
.session-item, .empty {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #10140f;
  padding: 10px 11px;
}
.session-item b {
  display: block;
  color: var(--text);
  font-weight: 650;
  word-break: break-all;
}
.session-item span, .session-meta, .empty {
  color: var(--muted);
  font-size: 12px;
}
.session-meta { white-space: nowrap; }

.tabs {
  display: flex;
  gap: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 4px;
}
.tab {
  flex: 1 1 0;
  min-width: 0;
  height: 34px;
  padding: 0 3px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
}
.tab.active {
  color: #061009;
  background: var(--green);
  border-color: var(--green-dark);
}

.provider-stack {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}
.provider-panel {
  display: none;
  gap: 11px;
}
.provider-panel.active { display: grid; }
.raw-panel.active { display: block; }

.terminal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 16px;
  overflow: auto;
}
.terminal-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.terminal-body {
  margin-top: 12px;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c0f0a;
  padding: 10px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}
.terminal-line {
  display: grid;
  grid-template-columns: 82px 56px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 6px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  color: var(--text);
}
.terminal-line:last-child { border-bottom: 0; }
.terminal-line span,
.terminal-line b {
  color: var(--muted);
  white-space: nowrap;
}
.terminal-line code {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.terminal-line.dim { color: var(--muted); }
.terminal-line.debug b { color: #a9b89a; }
.terminal-line.info b { color: var(--green); }
.terminal-line.warn b { color: #d8b26f; }
.terminal-line.error b { color: var(--danger); }

@media (max-width: 1320px) {
  body { overflow: auto; }
  .shell {
    grid-template-columns: 320px minmax(0, 1fr);
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .sidebar,
  .workspace,
  .terminal {
    height: auto;
    overflow: visible;
  }
  .terminal { grid-column: 1 / -1; min-height: 360px; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .sidebar,
  .workspace,
  .terminal {
    height: auto;
    overflow: visible;
  }
  .topbar, .inspector-head, .terminal-head {
    flex-direction: column;
    align-items: stretch;
  }
  .top-actions, .save-actions, .terminal-actions { justify-content: space-between; }
  .message { text-align: left; }
  .metric-grid, .route-flow, .search-config { grid-template-columns: 1fr 1fr; }
  .route-step::after { display: none; }
}
@media (max-width: 560px) {
  .shell { padding: 8px; }
  .metric-grid, .route-flow, .search-config { grid-template-columns: 1fr; }
  .session-item, .empty, .terminal-line { grid-template-columns: 1fr; }
}

/* custom scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(35, 193, 95, .55) #11150f; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: #11150f; }
*::-webkit-scrollbar-thumb { background: rgba(35, 193, 95, .45); border-radius: 999px; border: 2px solid #11150f; }
*::-webkit-scrollbar-thumb:hover { background: rgba(35, 193, 95, .62); }
