:root {
  --bg: #ffffff;
  --bg-sidebar: #f9f9f9;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #ececec;
  --bg-assistant: #f4f4f4;
  --text: #0d0d0d;
  --text-muted: #6b6b6b;
  --border: #e3e3e3;
  --accent: #0d0d0d;
  --accent-text: #ffffff;
  --radius: 14px;
  --sidebar-w: 260px;
  --font: "Segoe UI", Roboto, Helvetica, Arial, system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --bg-sidebar: #171717;
    --bg-elevated: #2f2f2f;
    --bg-input: #303030;
    --bg-hover: #2f2f2f;
    --bg-assistant: #2f2f2f;
    --text: #ececec;
    --text-muted: #9b9b9b;
    --border: #3a3a3a;
    --accent: #ffffff;
    --accent-text: #0d0d0d;
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

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

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left .2s ease;
}

.app.sidebar-collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); }

.sidebar-top { padding: 12px; }

.new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.new-chat:hover { background: var(--bg-hover); }
.new-chat .plus { font-size: 18px; line-height: 1; }

.history {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.history-label {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.history-item:hover { background: var(--bg-hover); }
.history-item.active { background: var(--bg-hover); }

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

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

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 5;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.title { font-weight: 600; font-size: 16px; }
.topbar-spacer { flex: 1; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover { background: var(--bg-hover); }

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

/* ---------- Welcome ---------- */

.welcome {
  max-width: 720px;
  margin: 8vh auto 0;
  text-align: center;
  padding: 0 8px;
}

.welcome-logo {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.welcome-sub {
  color: var(--text-muted);
  margin: 8px 0 28px;
}

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

.suggestion {
  padding: 14px 16px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.suggestion:hover { background: var(--bg-hover); }

/* ---------- Messages ---------- */

.msg {
  max-width: 760px;
  margin: 0 auto 22px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}

.user-avatar { background: #6b6bd6; color: #fff; }
.bot-avatar { background: #10a37f; color: #fff; }

.bubble {
  min-width: 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-user .bubble { background: var(--bg-input); border: 1px solid var(--border); }
.msg-bot .bubble { background: var(--bg-assistant); }

.msg-enter { animation: fade-up .18s ease-out; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Typing indicator ---------- */

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: .6; }
  .msg-enter { animation: none; }
  .thread { scroll-behavior: auto; }
}

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

.composer-wrap {
  padding: 8px 16px 14px;
  background: var(--bg);
}

.composer {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-input);
}

.composer:focus-within { border-color: var(--text-muted); }

.input {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 0;
}

.input::placeholder { color: var(--text-muted); }

.send {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.send:disabled { opacity: .25; cursor: default; }

.disclaimer {
  max-width: 760px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    margin-left: calc(var(--sidebar-w) * -1);
  }
  .app.sidebar-open .sidebar { margin-left: 0; }
  .suggestions { grid-template-columns: 1fr; }
  .welcome { margin-top: 6vh; }
}

@media (min-width: 769px) {
  .sidebar-backdrop { display: none; }
}
