:root {
  --ink: #121a16;
  --muted: #5c6b63;
  --line: #d7e0da;
  --panel: #ffffff;
  --rail: #f4f7f4;
  --accent: #1f6b4a;
  --accent-hover: #185539;
  --ok: #1f6b4a;
  --bad: #9b2c2c;
  --ok-bg: #e5f3eb;
  --bad-bg: #f8e8e8;
  --user-bg: #e8f0eb;
  --bot-bg: #ffffff;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: #e9eee9;
}

.shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--panel);
  border-inline: 1px solid var(--line);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
}

.brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn-deploy {
  display: inline-flex;
  line-height: 0;
}

.btn-deploy img {
  display: block;
  height: 28px;
  width: auto;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--rail);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.rail-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail label {
  display: grid;
  gap: 0.28rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.rail input,
.rail select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font: 500 0.82rem/1.3 var(--mono);
}

.rail select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.7rem;
}

.rail input:focus,
.rail select:focus,
.composer textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, white);
  border-color: var(--accent);
}

.custom-model[hidden] {
  display: none !important;
}

.model-status {
  margin: -0.2rem 0 0;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--muted);
}

.rail-status {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.75rem;
}

.status-pill .dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #9aab9f;
  flex-shrink: 0;
}

.status-pill.ok {
  background: var(--ok-bg);
}

.status-pill.ok .dot {
  background: var(--ok);
}

.status-pill.bad {
  background: var(--bad-bg);
}

.status-pill.bad .dot {
  background: var(--bad);
}

.pill-label {
  font-weight: 600;
  color: var(--muted);
}

.pill-value {
  margin-left: auto;
  font: 500 0.72rem/1 var(--mono);
  color: var(--ink);
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
}

.rail-footer a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.rail-footer a:hover {
  color: var(--accent);
}

.sep {
  margin: 0 0.3rem;
  color: #a0aea6;
}

.chat {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fbfcfb;
}

.thread {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 1rem 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.empty {
  margin: auto;
  max-width: 28rem;
  text-align: center;
  color: var(--muted);
}

.empty h1 {
  margin: 0 0 0.45rem;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.empty p {
  margin: 0;
  line-height: 1.5;
  font-size: 0.95rem;
}

.empty code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--ink);
}

.bubble {
  max-width: min(680px, 92%);
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bg);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bot-bg);
}

.bubble-latency {
  position: absolute;
  top: 0.35rem;
  right: 0.55rem;
  font: 500 0.68rem/1 var(--mono);
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.bubble.assistant:hover .bubble-latency {
  opacity: 1;
}

.bubble-body {
  padding-right: 2.5rem;
}

.bubble.error {
  align-self: flex-start;
  background: var(--bad-bg);
  border-color: color-mix(in srgb, var(--bad) 25%, white);
  color: var(--bad);
}

.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 0.85rem 1rem 1rem;
  display: grid;
  gap: 0.55rem;
}

.composer textarea {
  width: 100%;
  resize: none;
  min-height: 72px;
  max-height: 180px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafcfb;
  color: var(--ink);
  font: 500 0.95rem/1.45 var(--sans);
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.composer-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.composer button {
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: 600 0.9rem/1.2 var(--sans);
  cursor: pointer;
}

.composer button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.composer button:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .rail {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }

  .shell {
    border-inline: none;
  }
}
