:root {
  --bg: #212121;
  --bg-elev: #2f2f2f;
  --sidebar: #171717;
  --border: #3a3a3a;
  --text: #ececec;
  --text-dim: #9b9b9b;
  --text-faint: #6e6e6e;
  --accent: #ffffff;
  --user-bubble: #2f2f2f;
  --green: #19c37d;
  --red: #ff6b6b;
  --radius: 16px;
  --font: "Inter", "Söhne", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
}

code {
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ===== Layout ===== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  transition: grid-template-columns 0.2s ease;
}
.app.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}

.sidebar-top {
  padding: 12px;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
.new-chat:hover {
  background: var(--bg-elev);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.side-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-left: 2px;
}

.select-wrap {
  position: relative;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

select,
.side-input {
  width: 100%;
  appearance: none;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
select:focus,
.side-input:focus {
  border-color: #565656;
}

.ghost-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ghost-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-foot code {
  font-size: 11px;
  color: var(--text-faint);
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  flex-shrink: 0;
}

/* ===== Main ===== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid transparent;
}
.brand {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  color: var(--green);
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}

/* ===== Chat scroll ===== */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* ===== Welcome ===== */
.welcome {
  max-width: 760px;
  margin: 0 auto;
  padding: 12vh 24px 24px;
  text-align: center;
}
.welcome.hidden {
  display: none;
}
.welcome-mark {
  font-size: 44px;
  color: var(--green);
  line-height: 1;
  margin-bottom: 18px;
}
.welcome h1 {
  font-size: 30px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.welcome-sub {
  color: var(--text-dim);
  margin: 0 0 36px;
  font-size: 15px;
}
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  text-align: left;
}
.suggestion {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.suggestion:hover {
  background: var(--bg-elev);
  border-color: #565656;
}
.suggestion strong {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}
.suggestion span {
  font-size: 13px;
  color: var(--text-dim);
}

/* ===== Thread ===== */
.thread {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.msg {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.msg.user {
  flex-direction: row-reverse;
}

.avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.avatar.bot {
  background: var(--green);
  color: #06281b;
  font-size: 16px;
}
.avatar.user {
  background: #5436da;
  color: #fff;
  font-size: 10px;
}

.bubble {
  font-size: 15px;
  line-height: 1.7;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  padding: 11px 15px;
  border-radius: 18px;
  border-top-right-radius: 6px;
}
.msg.assistant .bubble {
  padding-top: 4px;
}

.bubble a {
  color: #7aa2ff;
}
.bubble code.inline {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.88em;
}
.bubble pre.code {
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.bubble pre.code code {
  font-size: 13px;
  line-height: 1.55;
  color: #e6e6e6;
}
.err-text {
  color: var(--red);
}

/* typing dots */
.dots {
  display: inline-flex;
  gap: 5px;
  padding: 6px 0;
}
.dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out both;
}
.dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ===== Composer ===== */
.composer-wrap {
  padding: 0 24px 18px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 6px 6px 6px 6px;
  box-shadow: 0 2px 18px rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s ease;
}
.composer:focus-within {
  border-color: #565656;
}

.file-chips {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 8px 4px;
}
.file-chips.has-files {
  display: flex;
}
.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-dim);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.attach-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.attach-btn:hover {
  background: var(--bg);
  color: var(--text);
}

textarea#prompt {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 4px;
  max-height: 220px;
  font-family: inherit;
}
textarea#prompt::placeholder {
  color: var(--text-faint);
}

.send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
}
.send-btn:disabled {
  background: #4a4a4a;
  color: #8a8a8a;
  cursor: not-allowed;
}

.disclaimer {
  max-width: 760px;
  margin: 10px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}
.disclaimer[data-type="ok"] {
  color: var(--green);
}
.disclaimer[data-type="error"] {
  color: var(--red);
}

/* ===== Scrollbars ===== */
::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: #5a5a5a;
  background-clip: padding-box;
}

/* ===== Responsive ===== */
@media (max-width: 820px) {
  .app {
    grid-template-columns: 0 1fr;
  }
  .sidebar {
    position: fixed;
    z-index: 30;
    width: 260px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }
  .suggestions {
    grid-template-columns: 1fr;
  }
  .welcome {
    padding-top: 8vh;
  }
}
