:root {
  --sidebar: #171717;
  --main: #212121;
  --user: #323232;
  --line: #2f2f2f;
  --text: #ececec;
  --muted: #8f8f8f;
  --green: #10a37f;
  --danger: #ef4444;
  --composer: #2f2f2f;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; color-scheme: dark; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--main);
  color: var(--text);
}
.app { display: flex; height: 100%; }
.sidebar {
  width: 260px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-head .new-chat { flex: 1; min-width: 0; }
.sidebar-close,
.sidebar-backdrop { display: none; }
.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid #3d3d3d;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.new-chat:hover { background: #212121; }
.search, select, textarea {
  font: inherit;
  color: var(--text);
  background: #212121;
  border: 1px solid #3d3d3d;
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
}
.search { background: transparent; }
.chats { overflow: auto; flex: 1; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: #d5d5d5;
}
.chat-item:hover, .chat-item.active { background: #212121; }
.chat-item .name {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}
.chat-item .ops { display: none; }
.chat-item:hover .ops { display: flex; }
.chat-item .ops button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.userbox { display: flex; gap: 10px; align-items: center; }
.avatar, .who, .empty-logo {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; flex: none;
}
.who.user-who { background: #5436da; }
.user-meta { min-width: 0; }
.user-meta > div:first-child { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 12px; }
.foot-links { display: flex; justify-content: space-between; margin-top: 8px; }
.foot-links a, .foot-links button {
  color: var(--muted); background: none; border: 0; cursor: pointer; font: inherit; font-size: 13px;
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--main); }
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.grow { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; font-size: 16px; }
.model-select {
  position: relative;
}
.model-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(320px, 46vw);
  background: #2f2f2f;
  color: #ececec;
  border: 1px solid #4a4a4a;
  border-radius: 10px;
  padding: 8px 10px 8px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.model-trigger span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-trigger:hover { background: #3a3a3a; }
.model-select.open .model-trigger { border-color: #6f6f6f; }
.model-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 260px;
  max-width: min(420px, 90vw);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #2f2f2f;
  color: #ececec;
  border: 1px solid #4a4a4a;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  max-height: 360px;
  overflow: auto;
}
.model-menu[hidden] { display: none !important; }
.model-menu li { margin: 0; }
.model-menu button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #ececec;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}
.model-menu button:hover { background: #3f3f3f; }
.model-menu button.active { background: #444; font-weight: 600; }
.icon-btn {
  background: none; border: 0; color: var(--text); cursor: pointer; font-size: 20px;
}
.menu { display: none; }
.banner {
  margin: 0 20px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #3a2a12;
  color: #f3d7a4;
  display: none;
  gap: 10px;
  align-items: center;
}
.banner.is-on { display: flex; }
.banner[hidden] { display: none !important; }
.banner.error { background: #3f1d1d; color: #f5c2c2; }
.banner-close {
  margin-left: auto;
  flex: none;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
}
.thread { flex: 1; overflow: auto; padding: 12px 0 8px; }
.empty { max-width: 640px; margin: 18vh auto 0; text-align: center; color: var(--muted); }
.empty-logo { width: 56px; height: 56px; font-size: 24px; margin: 0 auto 16px; }
.empty h2 { color: var(--text); font-weight: 600; font-size: 28px; margin: 0 0 8px; }
.msg {
  width: min(768px, calc(100% - 40px));
  margin: 0 auto 22px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.msg.user {
  flex-direction: row-reverse;
}
.msg .col { flex: 1; min-width: 0; }
.msg.user .col { display: flex; flex-direction: column; align-items: flex-end; }
.msg .bubble { line-height: 1.7; font-size: 16px; }
.msg.user .bubble {
  background: var(--user);
  border-radius: 22px;
  padding: 10px 16px;
  white-space: pre-wrap;
  max-width: 80%;
}
.msg.assistant .bubble { padding: 2px 0; }
.bubble pre {
  background: #0d0d0d;
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
}
.bubble code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13.5px; }
.bubble p { margin: 0.55em 0; }
.bubble p:first-child { margin-top: 0; }
.actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
}
.msg.assistant:hover .actions, .msg.assistant:focus-within .actions, .actions.show { opacity: 1; }
.copy-btn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  padding: 6px;
  display: inline-flex;
}
.copy-btn:hover { background: #2f2f2f; color: var(--text); }
.composer-wrap {
  width: min(768px, calc(100% - 24px));
  margin: 0 auto;
  padding: 8px 0 16px;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--composer);
  border: 1px solid #444;
  border-radius: 28px;
  padding: 8px 8px 8px 18px;
}
.composer textarea {
  border: 0;
  background: transparent;
  resize: none;
  max-height: 180px;
  min-height: 28px;
  padding: 8px 0;
  line-height: 1.45;
}
.composer textarea:focus { outline: none; }
.composer-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #0d0d0d;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
  padding: 0;
}
.composer-btn svg { grid-area: 1 / 1; }
.composer-btn:not(:disabled):hover { background: #ececec; }
.composer-btn:disabled {
  background: #676767;
  color: #2f2f2f;
  cursor: default;
}
.composer-btn .icon-stop { visibility: hidden; }
.composer-btn.is-generating .icon-send { visibility: hidden; }
.composer-btn.is-generating .icon-stop { visibility: visible; }
.composer-btn.is-generating,
.composer-btn.is-generating:disabled {
  background: #fff;
  color: #0d0d0d;
  cursor: pointer;
}
.composer-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }
.typing { color: var(--muted); }
@media (max-width: 800px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30;
    width: min(280px, 86vw);
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .menu { display: inline-flex; }
  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: none;
    font-size: 28px;
    line-height: 1;
    border-radius: 10px;
  }
  .sidebar-close:hover { background: #212121; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(0, 0, 0, .45);
  }
  .sidebar-backdrop.is-on,
  .sidebar-backdrop:not([hidden]) {
    display: block;
  }
  .sidebar-backdrop[hidden] { display: none !important; }
  body.sidebar-open { overflow: hidden; }
}
