:root {
  --bg: #171717;
  --surface: #1f1f1f;
  --raised: #2a2a2a;
  --hover: #303030;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eceae7;
  --secondary: #b6b2ad;
  --muted: #8d8984;
  --faint: #6b6864;
  --accent: #d97757;
  --danger: #c65b45;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.ico { width: 16px; height: 16px; flex: 0 0 16px; display: block; }

.app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-top {
  height: 48px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}
.side-top-spacer { flex: 1; }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--secondary);
  transition: background-color 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.tiny { width: 24px; height: 24px; }
.icon-btn.tiny .ico { width: 14px; height: 14px; flex-basis: 14px; }

.side-scroll { flex: 1; overflow-y: auto; padding: 12px 8px 20px; min-height: 0; }

.new-chat {
  width: 100%; height: 36px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--raised); color: var(--text);
  text-align: left;
  transition: background-color 120ms ease;
}
.new-chat:hover { background: var(--hover); }

.side-nav { margin-top: 16px; display: flex; flex-direction: column; gap: 2px; }
.nav-row {
  height: 32px; width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--secondary);
  text-align: left;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav-row:hover, .nav-row.active { background: var(--raised); color: var(--text); }
.nav-row .ico { color: var(--muted); }

.search-box { margin-top: 8px; padding: 0 4px; }
.search-box input {
  width: 100%; height: 32px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 0 10px; font-size: 13px;
}
.search-box input::placeholder { color: var(--faint); }

.chat-section { margin-top: 24px; }
.section-head {
  height: 28px; padding: 0 8px 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.section-head h2, .panel-head h2 {
  margin: 0; font-size: 12px; font-weight: 500; color: var(--muted);
}

.chat-list { list-style: none; margin: 4px 0 0; padding: 0; }
.chat-item {
  width: 100%; height: 32px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--secondary);
  text-align: left; font-size: 13px;
}
.chat-item:hover { background: var(--raised); }
.chat-item.active { background: var(--raised); color: var(--text); }
.chat-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item time { margin-left: auto; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.panel-empty { padding: 8px 12px; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.panel a { color: var(--accent); }

.panel { margin-top: 16px; padding: 12px; border-top: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel p { margin: 0 0 8px; color: var(--secondary); font-size: 13px; }
.panel .mini-list { list-style: none; margin: 0; padding: 0; }
.panel .mini-list li { padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--secondary); font-size: 13px; }
.panel .mini-list li:last-child { border-bottom: 0; }
.panel code { font-family: var(--mono); font-size: 12px; color: var(--text); }

.side-foot {
  position: relative;
  padding: 8px; border-top: 1px solid var(--line);
}
.user-btn {
  width: 100%; height: 40px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px; border: 0; border-radius: 8px;
  background: transparent; text-align: left;
}
.user-btn:hover { background: var(--raised); }
.avatar {
  width: 24px; height: 24px; flex: 0 0 24px;
  border-radius: 50%; background: var(--accent); color: #1a120e;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-meta strong { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { font-size: 11px; color: var(--muted); }

.user-menu {
  position: absolute; left: 8px; right: 8px; bottom: 56px;
  background: #232323; border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 30;
}
.user-menu button {
  width: 100%; height: 32px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--secondary); text-align: left; font-size: 13px;
}
.user-menu button:hover { background: var(--hover); color: var(--text); }
.user-menu button.danger { color: var(--danger); }

/* Workspace */

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

.main { flex: 1; min-height: 0; position: relative; display: flex; }

.top-note {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
}
.top-note button {
  border: 0; background: transparent; color: var(--secondary);
  padding: 0; font-size: 12px; text-decoration: underline;
  text-decoration-color: var(--line-strong); text-underline-offset: 3px;
}
.top-note button:hover { color: var(--text); }

.stage {
  flex: 1; min-height: 0; width: 100%;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 72px 24px 40px;
}

.greeting { text-align: center; margin-bottom: 32px; }
.greeting h1 {
  display: inline; margin: 0;
  font-family: var(--serif); font-size: 36px; font-weight: 400;
  letter-spacing: -0.01em; color: var(--text);
}

.composer {
  width: min(720px, 100%);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 12px 8px;
  flex: 0 0 auto;
}
.composer:focus-within { border-color: var(--line-strong); }
.composer textarea {
  display: block; width: 100%; min-height: 48px; max-height: 190px;
  resize: none; border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 15px; line-height: 1.5; padding: 4px 4px 0;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.composer-spacer { flex: 1; }

.model-btn {
  height: 28px; max-width: 260px;
  padding: 0 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--secondary); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-btn:hover { background: var(--hover); color: var(--text); }

.send-btn {
  width: 28px; height: 28px; flex: 0 0 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; background: var(--text); color: #171717;
}
.send-btn:hover { background: #fff; }
.send-btn.stop { background: var(--danger); color: #fff; }
.mic-btn { color: var(--muted); }

.model-menu {
  position: absolute; z-index: 25;
  width: min(340px, calc(100% - 48px));
  max-height: 360px; overflow-y: auto;
  background: #232323; border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 6px;
}
.model-menu .menu-title { padding: 8px 10px 4px; font-size: 11px; color: var(--muted); }
.model-menu button {
  width: 100%; min-height: 32px; padding: 6px 10px;
  display: flex; align-items: center; gap: 8px;
  border: 0; border-radius: 8px; background: transparent; color: var(--secondary);
  text-align: left; font-size: 13px;
}
.model-menu button:hover { background: var(--hover); color: var(--text); }
.model-menu button.selected { background: var(--raised); color: var(--text); }
.model-menu button small { margin-left: auto; color: var(--muted); font-size: 11px; }
.model-menu .menu-rule { height: 1px; background: var(--line); margin: 6px 4px; }

.quick { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 24px; }
.quick button {
  height: 32px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--secondary); font-size: 13px;
}
.quick button:hover { background: var(--raised); color: var(--text); }

/* Conversation */

.chat { display: none; width: min(760px, 100%); flex: 1; min-height: 0; overflow-y: auto; }
.stage.has-chat { justify-content: flex-start; padding-top: 72px; }
.stage.has-chat .greeting, .stage.has-chat .quick { display: none; }
.stage.has-chat .chat { display: block; }
.stage.has-chat .composer { margin-top: 16px; }

.msg { padding: 16px 0; border-bottom: 1px solid var(--line); }
.msg:last-child { border-bottom: 0; }
.msg.user .msg-body {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; display: inline-block; max-width: 100%;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .msg-body { color: var(--text); }
.msg.error .msg-body { color: var(--danger); }
.msg-body p { margin: 0 0 12px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }
.msg-body ul, .msg-body ol { margin: 8px 0; padding-left: 24px; }
.msg-body li { margin: 4px 0; }
.msg-body a { color: var(--accent); }
.msg-body blockquote { margin: 12px 0; padding-left: 14px; border-left: 2px solid var(--line-strong); color: var(--secondary); }
.msg-body hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.inline-code { font-family: var(--mono); font-size: 12px; background: var(--raised); border-radius: 4px; padding: 2px 5px; }

.code-block { margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #131313; }
.code-head { height: 32px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; border-bottom: 1px solid var(--line); }
.code-lang { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.code-copy { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.code-copy:hover { color: var(--text); }
.code-copy .ico { width: 13px; height: 13px; }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code-block code { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: #dcd9d5; }

.statusbar {
  height: 28px; flex: 0 0 28px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums;
}
.status-right { margin-left: auto; }

/* Dialogs */

.modal {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100vh - 48px); overflow-y: auto;
  border: 1px solid var(--line-strong); border-radius: 14px;
  background: #1c1c1c; color: var(--text); padding: 24px;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal h2 { margin: 0; font-size: 18px; font-weight: 500; }
.modal h3 { margin: 16px 0 6px; font-size: 13px; font-weight: 500; color: var(--secondary); }
.modal-lead { margin: 8px 0 20px; color: var(--muted); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--secondary); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select {
  width: 100%; height: 36px; padding: 0 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; color: var(--text);
}
.form-grid input::placeholder { color: var(--faint); }
.input-wrap { position: relative; display: flex; }
.input-wrap input { padding-right: 40px; }
.input-wrap .icon-btn { position: absolute; right: 4px; top: 2px; }
.provider-note { margin-top: 20px; font-size: 12px; color: var(--muted); }
.provider-note summary { cursor: pointer; color: var(--secondary); }
.provider-note div { padding-top: 8px; }
.provider-note code { font-family: var(--mono); color: var(--text); }
.form-error { margin: 16px 0 0; color: var(--danger); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.btn { height: 36px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--secondary); font-size: 13px; }
.btn:hover { background: var(--hover); color: var(--text); }
.btn.solid { background: var(--text); color: #171717; border-color: var(--text); }
.btn.solid:hover { background: #fff; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.install-block pre {
  margin: 0; padding: 12px 14px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; overflow-x: auto;
}
.install-block code { font-family: var(--mono); font-size: 12px; color: var(--text); white-space: pre; }

.toast {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%);
  z-index: 50; background: #2a2a2a; border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 8px 14px; color: var(--text); font-size: 13px;
}

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }

@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 21; transform: translateX(-100%); transition: transform 160ms ease; }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .stage { padding-left: 20px; padding-right: 20px; }
  .greeting h1 { font-size: 28px; }
  .top-note { top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}
