/* ===== CSS Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #343541;
  --bg-secondary: #202123;
  --bg-sidebar: #202123;
  --bg-user-msg: #343541;
  --bg-ai-msg: #444654;
  --bg-input: #40414f;
  --border-color: rgba(255,255,255,0.1);
  --text-primary: #ececf1;
  --text-secondary: #c5c5d2;
  --text-muted: #8e8ea0;
  --accent-green: #10a37f;
  --accent-green-hover: #1a7f64;
  --scrollbar-thumb: #565869;
  --scrollbar-track: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===== Scrollbar (2022 ChatGPT style) ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ===== Layout ===== */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 8px;
  transition: transform 0.2s ease;
  z-index: 100;
}

.sidebar.hidden {
  transform: translateX(-260px);
  margin-left: -260px;
}

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

.new-chat-btn:hover {
  background: rgba(255,255,255,0.06);
}

.new-chat-btn svg {
  width: 16px;
  height: 16px;
  stroke: var(--text-primary);
  fill: none;
  stroke-width: 2;
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

.sidebar-item:hover, .sidebar-item.active {
  background: rgba(255,255,255,0.06);
}

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

.sidebar-bottom-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-bottom-item:hover {
  background: rgba(255,255,255,0.06);
}

/* ===== Main Chat Area ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  min-height: 44px;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  position: relative;
}

.topbar-title-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.15s;
}

.topbar-title-btn:hover {
  background: rgba(255,255,255,0.06);
}

.topbar-title-btn svg {
  width: 12px;
  height: 12px;
  fill: var(--text-muted);
  transition: transform 0.2s;
}

.topbar-title-btn.open svg {
  transform: rotate(180deg);
}

/* Version selector dropdown */
.version-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #2f2f2f;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 8px;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
}

.version-dropdown.show {
  display: block;
}

.version-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.version-item:hover {
  background: rgba(255,255,255,0.06);
}

.version-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.version-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.version-item-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.version-item-check {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--text-primary);
  stroke-width: 2.5;
  flex-shrink: 0;
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
}

.topbar-toggle svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-primary);
  fill: none;
  stroke-width: 2;
}

/* ===== Messages Container ===== */
.messages-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.messages {
  margin: 0 auto;
  padding: 0;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
  text-align: center;
  width: 100%;
}

.welcome-logo {
  width: 48px;
  height: 48px;
  margin-bottom: 20px;
  border-radius: 8px;
  object-fit: cover;
}

.welcome h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
  max-width: 500px;
  line-height: 1.5;
}

.starter-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 900px;
  padding: 0 24px;
}

.starter-btn {
  padding: 14px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
  line-height: 1.4;
  min-width: 0;
  word-break: keep-all;
}

.starter-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
}

.starter-btn strong {
  display: block;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-size: 14px;
}

/* Message rows — full-width stripe style (2022 ChatGPT) */
.message-row {
  padding: 24px 0;
  display: flex;
  justify-content: center;
}

.message-row.user {
  background: var(--bg-user-msg);
}

.message-row.assistant {
  background: var(--bg-ai-msg);
  border-bottom: 1px solid rgba(0,0,0,0.1);
  border-top: 1px solid rgba(0,0,0,0.1);
}

.message-inner {
  max-width: 768px;
  width: 100%;
  display: flex;
  gap: 16px;
  padding: 0 24px;
  align-items: flex-start;
}

/* Avatar */
.avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.avatar.user-avatar {
  background: #5436DA;
}

.avatar.ai-avatar {
  background: var(--accent-green);
  padding: 0;
  overflow: hidden;
}

.avatar.ai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Message content */
.message-content {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  overflow-wrap: break-word;
}

.message-content p {
  margin-bottom: 12px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content code {
  background: rgba(0,0,0,0.3);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'Söhne Mono', 'Courier New', monospace;
  font-size: 13px;
}

.message-content pre {
  background: #000;
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}

.message-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #e6e6e6;
}

.message-content ol, .message-content ul {
  padding-left: 24px;
  margin-bottom: 12px;
}

.message-content li {
  margin-bottom: 4px;
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 20px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.4s infinite;
}

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

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ===== Input Area ===== */
.input-area {
  padding: 16px 24px 24px;
  background: var(--bg-primary);
}

.input-container {
  max-width: 768px;
  margin: 0 auto;
}

.input-box {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 12px 10px 16px;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-box:focus-within {
  border-color: rgba(255,255,255,0.2);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1);
}

.input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  min-height: 24px;
}

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

.send-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 6px;
  border: none;
  background: var(--accent-green);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
  opacity: 0.4;
  flex-shrink: 0;
}

.send-btn.active {
  opacity: 1;
}

.send-btn:hover.active {
  background: var(--accent-green-hover);
}

.send-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

.input-footer {
  text-align: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Overlay (mobile sidebar) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.visible {
  display: block;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .starter-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-260px);
    margin-left: 0;
  }

  .sidebar.hidden {
    transform: translateX(-260px);
    margin-left: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .topbar-toggle {
    display: block;
  }

  .message-inner {
    padding: 0 16px;
  }

  .input-area {
    padding: 12px 16px 16px;
  }

  .welcome h1 {
    font-size: 22px;
  }
}

@media (max-width: 480px) {
  .starter-buttons {
    grid-template-columns: 1fr;
  }
}

/* ===== Error message ===== */
.error-msg {
  background: rgba(255, 80, 80, 0.1);
  border: 1px solid rgba(255, 80, 80, 0.3);
  border-radius: 8px;
  padding: 12px 16px;
  color: #ff9999;
  font-size: 13px;
  margin: 8px 0;
}

/* Stop button */
.stop-btn {
  display: none;
  margin: 0 auto;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 8px;
}

.stop-btn:hover {
  background: rgba(255,255,255,0.06);
}

.stop-btn.visible {
  display: block;
}
