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

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #171717;
  --bg-tertiary: #212121;
  --bg-hover: #2a2a2a;
  --text-primary: #ececec;
  --text-secondary: #9b9b9b;
  --text-muted: #666;
  --accent: #1176BE;
  --accent-hover: #1589d9;
  --border: #2e2e2e;
  --user-bubble: #2e2e2e;
  --ai-bubble: transparent;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --sidebar-width: 260px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ============ AUTH SCREEN ============ */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
}

.auth-card {
  text-align: center;
  padding: 48px 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 420px;
  max-width: 90vw;
}

.auth-logo { margin-bottom: 16px; }
.auth-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }

/* Auth Tabs */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.auth-tab:hover:not(.active) {
  color: var(--text-primary);
}

/* Auth Forms */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

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

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

.auth-submit-btn {
  width: 100%;
  padding: 12px;
  margin-top: 4px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-submit-btn:hover { background: var(--accent-hover); }
.auth-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Auth Divider */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-divider span {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Google Button */
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.google-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.google-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

.hidden { display: none !important; }

/* ============ CHAT LAYOUT ============ */
.chat-screen {
  display: flex;
  height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px;
}

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

.sidebar-header-row .new-chat-btn { flex: 1; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-close:hover { background: var(--bg-hover); color: var(--text-primary); }

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

.sidebar-chats {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.chat-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.chat-item.active { background: var(--bg-tertiary); color: var(--text-primary); }
.chat-item-title { overflow: hidden; text-overflow: ellipsis; flex: 1; }

.chat-item-delete {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  flex-shrink: 0;
}
.chat-item:hover .chat-item-delete { display: block; }
.chat-item-delete:hover { color: var(--danger); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-badge {
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

/* User Profile */
.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.user-profile:hover { background: var(--bg-hover); }

.profile-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.profile-popup.visible { display: block; }

.profile-popup-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.profile-popup-email {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  word-break: break-all;
}
.profile-popup-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--danger);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.profile-popup-logout:hover { background: rgba(239,68,68,0.1); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Logout is now inside profile popup */

/* ============ MAIN CHAT ============ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.sidebar-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 8px;
  cursor: pointer;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

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

.welcome-icon { margin-bottom: 20px; }
.welcome h2 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.welcome p { color: var(--text-secondary); font-size: 15px; max-width: 420px; margin-bottom: 32px; }

.welcome-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 500px;
  width: 100%;
}

.suggestion {
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}
.suggestion:hover { background: var(--bg-tertiary); color: var(--text-primary); border-color: var(--accent); }

/* ============ MESSAGES ============ */
.message {
  padding: 20px 0;
  display: flex;
  gap: 16px;
  max-width: 768px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 600;
}

.message.user .message-avatar {
  background: var(--accent);
  color: white;
}

.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

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

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

.message-content pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.message-content pre code {
  background: transparent;
  padding: 0;
}

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

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

.message-content strong { font-weight: 600; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ============ INPUT AREA ============ */
.input-area {
  padding: 12px 20px 20px;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}
.input-wrapper:focus-within { border-color: var(--accent); }

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  line-height: 1.5;
  padding: 4px 0;
}

#messageInput::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-muted); cursor: not-allowed; }

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

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }
  .sidebar-overlay.visible { display: block; }

  .sidebar-toggle { display: block; }
  .sidebar-close { display: block; }

  .messages-container { padding-top: 52px; }

  .sidebar-toggle { top: calc(12px + env(safe-area-inset-top, 0px)); }

  .welcome { padding: 20px 16px; padding-top: 0; }
  .welcome h2 { font-size: 22px; }
  .welcome p { font-size: 14px; margin-bottom: 24px; }
  .welcome-icon svg { width: 44px; height: 44px; }
  .welcome-suggestions { grid-template-columns: 1fr; max-width: 100%; }
  .suggestion { font-size: 13px; padding: 12px 14px; }

  .message { padding-left: 12px; padding-right: 12px; gap: 10px; padding-top: 14px; padding-bottom: 14px; }
  .message-avatar { width: 28px; height: 28px; border-radius: 6px; }
  .message-content { font-size: 14px; line-height: 1.6; }
  .message-content pre { padding: 10px 12px; font-size: 12px; }

  .input-area { padding: 8px 10px 16px; }
  .input-wrapper { padding: 6px 10px; border-radius: 12px; }
  #messageInput { font-size: 14px; }
  .send-btn { width: 32px; height: 32px; border-radius: 6px; }
  .input-info { font-size: 11px; margin-top: 6px; }

  .auth-card { padding: 32px 24px; width: 360px; }
  .auth-card h1 { font-size: 20px; }
}

/* Small phones */
@media (max-width: 380px) {
  .message { padding-left: 8px; padding-right: 8px; }
  .input-area { padding-left: 8px; padding-right: 8px; }
  .auth-card { width: 95vw; padding: 28px 20px; }
  .welcome-suggestions { gap: 8px; }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .input-area { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .sidebar-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .sidebar-header { padding-top: calc(12px + env(safe-area-inset-top)); }
}
