/* SX SHELL console - "technical instrument" design language.
   Dark-first, high contrast, monospace for data, restrained motion. */

:root {
  --bg: #08090b;
  --surface: #0e1014;
  --surface-2: #12151a;
  --line: #1c2029;
  --line-soft: #161a21;
  --text: #e7eaf0;
  --dim: #8a92a2;
  --faint: #5d6472;
  --accent: #5eead4;
  --accent-dim: #2b6b60;
  --warn: #ffb86b;
  --danger: #ff6b6b;
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

/* Faint engineering grid - signals "instrument", stays out of the way. */
.grid-bg {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(ellipse 90% 60% at 50% 0%, #000 20%, transparent 75%);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 9, 11, 0.8);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.mark { color: var(--accent); font-size: 18px; line-height: 1; }
.wordmark { font-weight: 600; letter-spacing: 0.14em; font-size: 13px; }
.wordmark .dim { color: var(--faint); margin-left: 2px; }

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: 500 12.5px/1 var(--sans);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pill:hover { border-color: var(--accent-dim); background: var(--surface-2); }
.pill.ghost { color: var(--faint); }
.pill kbd {
  font: 500 10.5px/1 var(--mono);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 5px;
  color: var(--dim);
  background: var(--bg);
}
.chev { color: var(--faint); font-size: 10px; }

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.08);
}
.dot[data-state="online"] { background: var(--accent); }
.dot[data-state="busy"] { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.dot[data-state="offline"] { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }

.stat {
  display: flex; align-items: baseline; gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.stat .k { color: var(--faint); }
.stat .v { color: var(--text); }

/* ---------------------------------------------------------------- stage */
.stage {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 0fr;
  min-height: 0;
  transition: grid-template-columns 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.stage:has(.inspector[data-open="true"]) { grid-template-columns: 1fr 320px; }

.thread {
  overflow-y: auto;
  padding: 28px 20px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.thread::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

/* ---------------------------------------------------------------- welcome */
.welcome { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.welcome h1 {
  font-size: clamp(26px, 4.4vw, 40px);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.welcome h1 em { font-style: normal; color: var(--accent); }
.welcome p { color: var(--dim); margin: 0 0 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--dim);
  font: 500 12.5px/1 var(--sans);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--accent-dim); }

/* ---------------------------------------------------------------- messages */
.msg { max-width: 780px; margin: 0 auto 22px; }
.msg-role {
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 8px;
}
.msg.user .msg-body {
  border-left: 2px solid var(--accent-dim);
  padding-left: 14px;
  color: var(--text);
}
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 1px 5px;
}
.msg-body pre {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
}
.msg-body pre code { background: none; border: none; padding: 0; }

/* Reasoning trace - the differentiator: thinking is shown, not hidden. */
.trace {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface) 0%, rgba(14, 16, 20, 0.4) 100%);
  overflow: hidden;
}
.trace summary {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  cursor: pointer;
  font: 500 11.5px/1 var(--mono);
  color: var(--dim);
  letter-spacing: 0.04em;
  list-style: none;
}
.trace summary::-webkit-details-marker { display: none; }
.trace summary::before {
  content: "\25B8";
  color: var(--accent);
  transition: transform 0.18s ease;
}
.trace[open] summary::before { transform: rotate(90deg); }
.trace .trace-body {
  padding: 0 13px 13px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  color: var(--faint);
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
  border-top: 1px solid var(--line-soft);
  padding-top: 11px;
}
.trace .live { color: var(--accent); font-size: 10.5px; letter-spacing: 0.1em; }

.cursor {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------------- inspector */
.inspector {
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.inspector[data-open="false"] { display: none; }
.inspector-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.inspector-head .label {
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}
.x {
  background: none; border: none; color: var(--faint);
  font-size: 18px; cursor: pointer; line-height: 1;
}
.x:hover { color: var(--text); }

.panel { padding: 14px; border-bottom: 1px solid var(--line-soft); }
.panel.grow { flex: 1; }
.panel-title {
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 10px;
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; font-size: 12.5px; }
.kv dt { color: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 11.5px; color: var(--text); }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- composer */
.composer {
  position: relative;
  z-index: 2;
  border-top: 1px solid var(--line);
  background: rgba(8, 9, 11, 0.9);
  backdrop-filter: blur(12px);
  padding: 14px 20px 16px;
}
.composer form {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 10px 10px 14px;
  transition: border-color 0.15s ease;
}
.composer form:focus-within { border-color: var(--accent-dim); }
#input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font: 400 14.5px/1.6 var(--sans);
  max-height: 200px;
}
#input::placeholder { color: var(--faint); }

.send {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--accent-dim);
  background: rgba(94, 234, 212, 0.1);
  color: var(--accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 15px;
  transition: background 0.15s ease;
}
.send:hover:not(:disabled) { background: rgba(94, 234, 212, 0.18); }
.send:disabled { opacity: 0.5; cursor: not-allowed; }
.send-busy { display: none; width: 13px; height: 13px; border: 2px solid var(--accent-dim); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
body[data-busy="true"] .send-idle { display: none; }
body[data-busy="true"] .send-busy { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer-meta {
  max-width: 780px;
  margin: 8px auto 0;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--faint);
}
.mono { font-family: var(--mono); }
.linkish { background: none; border: none; color: var(--faint); cursor: pointer; font-size: 11px; text-decoration: underline dotted; }
.linkish:hover { color: var(--accent); }

/* ---------------------------------------------------------------- palette */
.palette {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 5, 7, 0.6);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: start center;
  padding-top: 14vh;
}
.palette[hidden] { display: none; }
.palette-box {
  width: min(560px, 92vw);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#paletteInput {
  width: 100%;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font: 400 15px/1 var(--sans);
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.palette-list { max-height: 320px; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}
.palette-item[data-active="true"] { background: var(--surface-2); }
.palette-item .hint { font-family: var(--mono); font-size: 11px; color: var(--faint); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .stage:has(.inspector[data-open="true"]) { grid-template-columns: 1fr; }
  .inspector {
    position: fixed; inset: auto 0 0 0; z-index: 40;
    height: 62vh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: var(--shadow);
  }
  .stat { display: none; }
  .welcome { margin-top: 5vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- rag */
.meta-right { display: inline-flex; align-items: center; gap: 12px; }

.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--faint);
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.toggle:hover { color: var(--text); }
.toggle-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint);
  transition: background .15s, box-shadow .15s;
}
.toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-dim); }
.toggle[aria-pressed="true"] .toggle-dot {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(94, 234, 212, .6);
}

.cites {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.cite {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font: 400 11px/1 var(--mono);
  color: var(--dim);
}
.cite .n { color: var(--accent); }
.cite .sc { color: var(--faint); font-size: 10px; }
