:root {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --surface: #f4f4f4;
  --surface-hover: #ececec;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --text-muted: #6b6b6b;
  --text-faint: #9b9b9b;
  --accent: #10a37f;
  --send-bg: #0d0d0d;
  --send-fg: #ffffff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.06);
  --shimmer-a: #9b9b9b;
  --shimmer-b: #0d0d0d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --sidebar: #171717;
    --surface: #303030;
    --surface-hover: #2a2a2a;
    --border: #3a3a3a;
    --text: #ececec;
    --text-muted: #b4b4b4;
    --text-faint: #8f8f8f;
    --send-bg: #ececec;
    --send-fg: #0d0d0d;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
    --shimmer-a: #7a7a7a;
    --shimmer-b: #f5f5f5;
  }
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

a { color: inherit; text-decoration: none; }

/* ---------- Sidebar ---------- */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  padding: 8px;
  transition: margin-left 0.25s ease, transform 0.25s ease;
}

body.sidebar-collapsed .sidebar { margin-left: -260px; }

.sidebar-top {
  display: flex;
  justify-content: space-between;
  padding: 2px 2px 6px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.new-chat:hover { background: var(--surface-hover); }

.logo-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.logo-mark svg { width: 16px; height: 16px; stroke-width: 2.8; }
.logo-mark.small { width: 24px; height: 24px; }
.logo-mark.small svg { width: 14px; height: 14px; }

.history {
  flex: 1;
  overflow-y: auto;
  margin-top: 12px;
}

.history-group { margin-bottom: 18px; }

.history-group h3 {
  margin: 0 0 4px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
}

.history-group a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-group a:hover { background: var(--surface-hover); }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.upgrade {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.3;
}
.upgrade:hover { background: var(--surface-hover); }
.upgrade small { display: block; color: var(--text-faint); font-size: 12px; }
.upgrade strong { font-weight: 500; }

.upgrade-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
}
.upgrade-icon svg { width: 15px; height: 15px; }

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font-size: 14px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #7c5cff;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.scrim { display: none; }

/* ---------- Main ---------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 56px;
  padding: 0 12px;
  flex-shrink: 0;
}

#openSidebar { display: none; }
body.sidebar-collapsed #openSidebar { display: grid; }

.model-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 500;
}
.model-picker:hover { background: var(--surface-hover); }
.model-picker .model-version { color: var(--text-muted); }
.model-picker svg { width: 16px; height: 16px; color: var(--text-muted); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
}
.share-btn svg { width: 16px; height: 16px; }
.share-btn:hover { background: var(--surface-hover); }

/* ---------- Thread ---------- */

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 24px;
}

.main.empty .thread { display: none; }

.msg {
  max-width: 768px;
  margin: 0 auto 28px;
}

.msg.user {
  display: flex;
  justify-content: flex-end;
}

.msg.user .bubble {
  max-width: 70%;
  padding: 10px 18px;
  border-radius: 22px;
  background: var(--surface);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant .content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.75); opacity: 0.6; }
  50% { transform: scale(1); opacity: 1; }
}

.shimmer {
  background: linear-gradient(90deg, var(--shimmer-a) 0%, var(--shimmer-a) 35%, var(--shimmer-b) 50%, var(--shimmer-a) 65%, var(--shimmer-a) 100%);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 2s linear infinite;
  font-weight: 500;
}

.shimmer.enter { animation: shimmer 2s linear infinite, fadeIn 0.3s ease; }

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0% 0; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.thoughts {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.thoughts summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}
.thoughts summary::-webkit-details-marker { display: none; }
.thoughts summary:hover { color: var(--text); }
.thoughts summary svg { width: 15px; height: 15px; transition: transform 0.2s; }
.thoughts[open] summary svg { transform: rotate(90deg); }

.thoughts ol {
  margin: 8px 0 4px;
  padding: 0 0 0 14px;
  border-left: 2px solid var(--border);
  list-style: none;
}
.thoughts li { padding: 3px 0; }

.cursor {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 2px;
  border-radius: 50%;
  background: var(--text);
  vertical-align: middle;
  animation: pulse 1s ease-in-out infinite;
}

.actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  margin-left: -8px;
  animation: fadeIn 0.3s ease;
}

.actions button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
}
.actions button:hover { background: var(--surface-hover); color: var(--text); }
.actions svg { width: 17px; height: 17px; }

/* ---------- Composer ---------- */

.composer-wrap {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 16px 8px;
  flex-shrink: 0;
}

.main.empty .composer-wrap {
  margin: auto;
  padding-bottom: 12vh;
}

.greeting {
  display: none;
  margin: 0 0 28px;
  text-align: center;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.main.empty .greeting { display: block; }

.composer {
  background: var(--bg);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 12px 12px 10px 18px;
}

@media (prefers-color-scheme: dark) {
  .composer { background: var(--surface); }
}

.composer textarea {
  width: 100%;
  max-height: 200px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 4px 0;
}
.composer textarea::placeholder { color: var(--text-faint); }

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  margin-left: -8px;
}

.composer-tools { display: flex; gap: 4px; }

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-width: 36px;
  justify-content: center;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 14px;
}
.tool-btn.pill { padding: 0 12px; border: 1px solid var(--border); }
.tool-btn:hover { background: var(--surface-hover); color: var(--text); }
.tool-btn svg { width: 18px; height: 18px; }

.send-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--send-bg);
  color: var(--send-fg);
  transition: opacity 0.15s;
}
.send-btn:disabled { opacity: 0.25; cursor: default; }
.send-btn svg { stroke-width: 2.4; }
.send-btn .i-stop { display: none; fill: currentColor; stroke: none; }
.send-btn.generating .i-send { display: none; }
.send-btn.generating .i-stop { display: block; }

.suggestions {
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}
.main.empty .suggestions { display: flex; }

.suggestions button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text-muted);
}
.suggestions button:hover { background: var(--surface-hover); color: var(--text); }

.disclaimer {
  margin: 8px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}
.main.empty .disclaimer { display: none; }

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    margin-left: 0 !important;
  }
  body.sidebar-open .sidebar { transform: none; }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  body.sidebar-open .scrim { opacity: 1; pointer-events: auto; }

  #openSidebar { display: grid; }
  .share-btn { display: none; }
  .msg.user .bubble { max-width: 85%; }
  .greeting { font-size: 24px; }
  .tool-btn.pill span, .tool-btn.pill { font-size: 13px; }
}
