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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --text: #ececec;
  --text2: #a0a0a0;
  --text3: #666666;
  --accent: #3b82f6;
  --accent2: #10b981;
--accent3: #ef4444
  --user-bubble: #1a3a5c;
  --assistant-bubble: #1e1e1e;
  --radius: 18px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ─── Login Screen ──────────────────────────────────────────────── */
.login-screen {
  display: none;
  height: 100%;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-box h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

.login-box input {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
  text-align: center;
}

.login-box input:focus {
  border-color: var(--accent);
}

.login-box button {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.login-error {
  display: none;
  margin-top: 10px;
  color: #ef4444;
  font-size: 13px;
}

/* ─── App ─────────────────────────────────────────────────────────── */
.app {
  display: none;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

/* ─── Header ──────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clear-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.clear-btn:hover, .logout-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.logout-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

/* ─── Room Bar ───────────────────────────────────────────────────── */
.room-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.room-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  min-width: 70px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text2);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.room-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--text3);
  transform: translateY(-1px);
}
.room-btn.active {
    box-shadow: 0 0 12px rgba(59,130,246,0.3);
}
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(59,130,246,0.3);
}
.room-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.7;
}
.room-btn.active svg { opacity: 1; }
.room-btn:hover svg { opacity: 0.9; }
@media (max-width: 500px) {
  .room-bar { gap: 6px; padding: 6px 8px; }
  .room-btn { padding: 5px 10px; min-width: auto; font-size: 0.75rem; }
  .room-btn svg { width: 14px; height: 14px; }
}

/* ─── Messages ────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  width: 100%;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.msg-row.assistant .msg-bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-text {
  font-size: 14.5px;
  line-height: 1.5;
}

.msg-row.thinking { justify-content: flex-start; }

.msg-row.thinking .msg-bubble {
  background: #181818;
  border: 1px dashed var(--border);
  border-bottom-left-radius: 4px;
  max-width: 90%;
}

.msg-row.thinking .msg-text {
  font-size: 13px;
  font-style: italic;
  color: var(--text3);
  line-height: 1.45;
}

/* ─── Typing / Streaming indicator ──────────────────────────────── */
.msg-row.assistant.typing .msg-bubble {
  border-color: var(--accent);
  animation: typingPulse 1.5s ease-in-out infinite;
}

.msg-row.thinking.typing .msg-bubble {
  animation: typingPulse 1.5s ease-in-out infinite;
}

@keyframes typingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ─── Input Bar ───────────────────────────────────────────────────── */
.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.input-bar input {
  flex: 1;
  padding: 10px 14px;
  font-size: 15px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.input-bar input:focus {
  border-color: var(--accent);
}

.input-bar button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.input-bar button:active {
  transform: scale(0.96);
}

/* ─── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-header, .room-bar, .input-bar {
    flex-wrap: wrap;
  }
  .login-box, #messages {
    max-width: none;
    width: 100%;
  }
  .room-btn {
    min-width: auto;
    font-size: 0.75rem;
    padding: 4px 10px;
  }
  .msg-bubble {
    max-width: 90%;
  }
}

/* ─── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Selection ───────────────────────────────────────────────────── */
::selection { background: rgba(59,130,246,0.35); color: #fff; }
