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

:root {
  --bg: #0b0e17;
  --surface: #131926;
  --surface-2: #1a2235;
  --border: rgba(99, 102, 241, 0.15);
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --text: #e5e7eb;
  --text-2: #9ca3af;
  --text-3: #6b7280;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --radius-lg: 20px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Install Banner ─── */
.install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  font-size: 0.85rem;
  font-weight: 500;
  gap: 0.5rem;
}
.install-banner button {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
}
.install-banner button:hover { background: rgba(255,255,255,0.3); }

/* ─── Auth Screen ─── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  animation: fadeUp 0.4s ease;
  box-shadow: 0 25px 60px rgba(0,0,0,0.4);
}
.auth-box .logo {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}
.auth-box h1 {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-box p.subtitle {
  text-align: center;
  color: var(--text-3);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}
.auth-box .field {
  margin-bottom: 1rem;
}
.auth-box .field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-2);
  margin-bottom: 0.35rem;
  font-weight: 500;
}
.auth-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.auth-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.auth-box .btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.auth-box .btn-row button { flex: 1; }

/* ─── Chat Layout ─── */
#app {
  display: none;
  height: 100vh;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header .brand {
  font-weight: 700;
  font-size: 1.1rem;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.chat-header .spacer { flex: 1; }
.chat-header .header-btn {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.4rem;
  border-radius: 8px;
  transition: all 0.2s;
}
.chat-header .header-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.chat-header .user-email {
  font-size: 0.8rem;
  color: var(--text-3);
}

.chat-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
  width: 320px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-search {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(99,102,241,0.15);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
.sidebar-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}
.sidebar-list {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: rgba(99,102,241,0.12); border-left: 3px solid var(--primary); }
.conv-item .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}
.conv-item .conv-info { flex: 1; min-width: 0; }
.conv-item .conv-name {
  font-weight: 600;
  font-size: 0.9rem;
}
.conv-item .conv-preview {
  font-size: 0.78rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .conv-time {
  font-size: 0.7rem;
  color: var(--text-3);
  flex-shrink: 0;
}

/* ─── Main Chat ─── */
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 0.95rem;
  text-align: center;
  padding: 2rem;
}
.chat-placeholder .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.message {
  max-width: 75%;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.4;
  animation: fadeUp 0.2s ease;
  word-wrap: break-word;
}
.message.own {
  background: var(--primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.message.other {
  background: var(--surface-2);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.message .msg-time {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 0.25rem;
  text-align: right;
}
.message.own .msg-time { color: rgba(255,255,255,0.7); }

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chat-input-area input {
  flex: 1;
  padding: 0.7rem 1rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.chat-input-area input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}
.chat-input-area button {
  padding: 0.7rem 1.2rem;
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-input-area button:hover { background: var(--primary-hover); }

/* ─── Search Results ─── */
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
  display: none;
  margin-top: 4px;
}
.search-results.show { display: block; }
.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.search-result-item:hover { background: var(--surface-2); }
.search-result-item .avatar-sm {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ─── Typing indicator ─── */
.typing-indicator {
  font-size: 0.78rem;
  color: var(--text-3);
  padding: 0.25rem 1rem;
  display: none;
}

/* ─── Animations ─── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* ─── Mobile ─── */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .sidebar.hidden { display: none; }
  .main-chat.full { display: flex; }
  .main-chat { display: none; }
  .main-chat .back-btn { display: block; }
}
