:root {
  --bg: #101211;
  --panel: #171b19;
  --panel-strong: #202520;
  --panel-soft: #252a26;
  --line: #374039;
  --line-strong: #526057;
  --text: #f2f5ef;
  --muted: #a9b5ad;
  --faint: #758178;
  --accent: #47c2a0;
  --accent-strong: #7ae2c6;
  --accent-ink: #06241c;
  --warm: #f0b263;
  --danger: #f27a7a;
  --shadow: 0 18px 50px rgb(0 0 0 / 32%);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgb(71 194 160 / 10%), transparent 32%),
    linear-gradient(300deg, rgb(240 178 99 / 10%), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  flex: 0 0 auto;
}

.sidebar {
  width: min(300px, 82vw);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: rgb(18 21 19 / 94%);
  transition: margin-left 180ms ease;
}

.sidebar.collapsed {
  margin-left: -300px;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand h1,
.dialog-header h2 {
  margin: 2px 0 0;
  font-size: 20px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--warm);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.server-pill,
.status {
  min-width: 74px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-soft);
  text-align: center;
  font-size: 12px;
  white-space: nowrap;
}

.server-pill.ready,
.status.ready {
  border-color: rgb(71 194 160 / 55%);
  color: var(--accent-strong);
}

.server-pill.warn,
.status.warn {
  border-color: rgb(240 178 99 / 55%);
  color: var(--warm);
}

.primary-action,
.secondary-action,
.sidebar-button,
.icon-button,
.send-button,
.chat-select,
.delete-chat {
  cursor: pointer;
}

.primary-action,
.sidebar-button,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  border-radius: var(--radius);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-action {
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 800;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.primary-action.compact,
.secondary-action {
  min-height: 38px;
  padding: 0 16px;
}

.secondary-action,
.sidebar-button {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

.secondary-action:hover,
.sidebar-button:hover {
  border-color: var(--line-strong);
  background: var(--panel-soft);
}

.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-right: 3px;
}

.chat-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
}

.chat-item:hover,
.chat-item.active {
  background: var(--panel-soft);
}

.chat-item.active {
  border-color: rgb(71 194 160 / 35%);
}

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-select {
  min-width: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.chat-item:hover .chat-select,
.chat-item.active .chat-select {
  color: var(--text);
}

.delete-chat {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--faint);
  background: transparent;
  border-radius: 6px;
}

.delete-chat:hover {
  color: var(--danger);
  background: rgb(242 122 122 / 12%);
}

.workspace {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgb(23 27 25 / 88%);
  backdrop-filter: blur(14px);
}

.icon-button,
.send-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-soft);
}

.icon-button:hover,
.send-button:hover {
  background: #303832;
}

.model-label {
  color: var(--muted);
  font-size: 14px;
}

.model-select {
  min-width: 180px;
  max-width: 420px;
  flex: 1;
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.model-select:focus,
textarea:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(71 194 160 / 18%);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 20px 22px;
}

.empty-state {
  min-height: 100%;
  max-width: 850px;
  margin: 0 auto;
  display: grid;
  align-content: center;
  gap: 24px;
}

.empty-copy h2 {
  margin: 0 0 10px;
  font-size: clamp(32px, 6vw, 64px);
  line-height: 0.96;
  letter-spacing: 0;
}

.empty-copy p {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
}

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

.suggestion {
  min-height: 76px;
  padding: 14px;
  color: var(--text);
  background: rgb(32 37 32 / 76%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
}

.suggestion:hover {
  border-color: rgb(71 194 160 / 60%);
  background: var(--panel-soft);
}

.thread {
  width: min(920px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 900;
}

.message.user .avatar {
  color: #1b1203;
  background: var(--warm);
}

.bubble {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(23 27 25 / 78%);
}

.message.user .bubble {
  background: rgb(47 42 31 / 74%);
}

.role {
  margin: 0 0 6px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.content {
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.content > :first-child {
  margin-top: 0;
}

.content > :last-child {
  margin-bottom: 0;
}

.content pre {
  overflow-x: auto;
  padding: 12px;
  border-radius: var(--radius);
  background: #0b0d0c;
}

.content code {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.content :not(pre) > code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgb(255 255 255 / 8%);
}

.thinking {
  margin-bottom: 10px;
  padding: 10px;
  border: 1px dashed rgb(240 178 99 / 45%);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgb(240 178 99 / 8%);
  white-space: pre-wrap;
}

.composer {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: rgb(16 18 17 / 88%);
}

.composer-shell {
  width: min(920px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

#prompt-input {
  min-height: 48px;
  max-height: 210px;
  resize: none;
  padding: 13px 14px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  line-height: 1.45;
}

.send-button {
  height: 48px;
  color: var(--accent-ink);
  background: var(--accent);
}

.send-button:hover {
  background: var(--accent-strong);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hint {
  width: min(920px, 100%);
  margin: 7px auto 0;
  color: var(--faint);
  font-size: 12px;
}

.settings-dialog {
  width: min(560px, calc(100vw - 30px));
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
}

.settings-dialog::backdrop {
  background: rgb(0 0 0 / 58%);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-soft);
  outline: none;
}

.field small {
  color: var(--faint);
  font-weight: 500;
  line-height: 1.4;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(430px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  z-index: 10;
}

/* ===== Mobile overlay backdrop ===== */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 760px) {
  body {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    box-shadow: var(--shadow);
  }

  /* Backdrop dims the page when sidebar is open on mobile */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgb(0 0 0 / 55%);
    opacity: 1;
    transition: opacity 180ms ease;
    pointer-events: auto;
  }

  .sidebar-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .workspace {
    height: 100%;
  }

  .topbar {
    gap: 8px;
    padding: 10px;
    min-height: 54px;
  }

  .model-label,
  .status {
    display: none;
  }

  .model-select {
    min-width: 0;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .empty-copy h2 {
    font-size: 34px;
  }

  .empty-copy p {
    font-size: 15px;
  }

  .messages {
    padding: 16px 12px;
  }

  .composer {
    padding: 10px 12px;
    /* Leave room for iOS Safari bottom toolbar */
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .hint {
    display: none;
  }

  .icon-button,
  .send-button {
    width: 38px;
    height: 38px;
  }

  .topbar .icon-button {
    flex: 0 0 auto;
  }

  .message {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
  }

  .avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .bubble {
    padding: 10px 12px;
  }

  .content {
    font-size: 14px;
  }

  .settings-panel {
    padding: 16px;
    gap: 14px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .sidebar {
    padding: 14px;
    gap: 12px;
  }
}