:root {
  --bg: #0f1117;
  --bg-sidebar: #171a21;
  --bg-input: #1f232d;
  --bg-user: #2a3f5f;
  --bg-assistant: #1a1e27;
  --border: #262b36;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --accent: #0ea5a3;
  --accent-hover: #0d8f8d;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

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

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  transition: transform 0.25s ease;
  z-index: 30;
}

.sidebar-header { display: flex; align-items: center; justify-content: space-between; }

.brand { display: flex; align-items: center; gap: 10px; }

.brand-logo {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px; color: #fff;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-input); color: var(--text); }

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: #262b36; }

.history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }

.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-dim);
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
  transition: background 0.12s;
}
.history-item:hover { background: var(--bg-input); color: var(--text); }
.history-item.active { background: var(--bg-input); color: var(--text); }
.history-item .h-icon { flex-shrink: 0; opacity: 0.8; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge {
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(14, 165, 163, 0.12);
  color: #3cc9c7;
  border: 1px solid rgba(14, 165, 163, 0.25);
}
.footnote { font-size: 11px; color: var(--text-dim); }

.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
  display: none;
}

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

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar-title { font-size: 13.5px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.welcome { margin: auto 0; text-align: center; padding: 40px 0; }
.welcome-icon {
  width: 56px; height: 56px;
  margin: 0 auto 18px;
  background: rgba(14,165,163,0.12);
  border: 1px solid rgba(14,165,163,0.3);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.welcome h1 { font-size: 24px; font-weight: 650; margin-bottom: 8px; }
.welcome-sub { color: var(--text-dim); max-width: 520px; margin: 0 auto 28px; font-size: 14px; }

.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 640px; margin: 0 auto; }
@media (max-width: 600px) { .suggestions { grid-template-columns: 1fr; } }

.suggestion {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.suggestion:hover { border-color: var(--accent); background: #232936; }
.sug-icon { font-size: 16px; line-height: 1.3; }

/* ---------- Messages ---------- */
.msg { display: flex; gap: 14px; max-width: 100%; }
.msg .avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  margin-top: 2px;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--accent); color: #fff; }
.msg.assistant .avatar { background: #2d3443; color: #8ecfcf; }

.msg .bubble {
  max-width: calc(100% - 44px);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  overflow-wrap: break-word;
}
.msg.user .bubble { background: var(--bg-user); }
.msg.assistant .bubble { background: var(--bg-assistant); border: 1px solid var(--border); }

.bubble p { margin-bottom: 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 8px 0 10px 22px; }
.bubble li { margin-bottom: 4px; }
.bubble strong { font-weight: 650; }
.bubble code {
  background: #0d1117;
  border: 1px solid var(--border);
  padding: 1.5px 6px;
  border-radius: 5px;
  font-size: 13px;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
}
.bubble pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: none; border: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 13.5px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.bubble th { background: var(--bg-input); font-weight: 600; }
.bubble a { color: #4cc9c7; text-decoration: none; }
.bubble a:hover { text-decoration: underline; }

.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- Composer ---------- */
.composer-wrap { padding: 12px 20px 14px; background: var(--bg); }
.composer {
  max-width: 860px;
  margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: var(--accent); }

.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  max-height: 160px;
  line-height: 1.5;
  padding: 4px 0;
}
.composer textarea::placeholder { color: #6b7484; }

.send-btn {
  width: 36px; height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-note { text-align: center; font-size: 11px; color: #5b6372; margin-top: 8px; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2d3443; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a4254; }

/* ---------- Form CTA ---------- */
.cta-row {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.cta-text {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}
.cta-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 22px;
  border-radius: 999px;
  text-decoration: none;
  transition: filter 0.2s;
}
.cta-btn:hover { filter: brightness(1.12); }
.footer-cta {
  display: block;
  text-align: center;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 10px;
  text-decoration: none;
  margin-bottom: 14px;
  transition: filter 0.2s;
}
.footer-cta:hover { filter: brightness(1.12); }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: none; }
  .sidebar-overlay.show { display: block; }
  #sidebar-open, #sidebar-close { display: flex; }
  .chat { padding: 16px 14px 8px; }
  .msg .bubble { max-width: calc(100% - 40px); }
}
