@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0A0E14;
  --surface: #131920;
  --surface-light: #1C2530;
  --card: #172028;
  --primary: #1B8F5A;
  --primary-light: #2DB77A;
  --accent: #58A6FF;
  --text: #E6EDF3;
  --text-secondary: #8B949E;
  --text-hint: #484F58;
  --sent: #1B4332;
  --received: #1C2530;
  --error: #F85149;
  --success: #3FB950;
  --warning: #D29922;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ====== APP LAYOUT ====== */
.app { display: flex; height: 100vh; }

/* ====== SIDEBAR ====== */
.sidebar {
  width: 380px;
  background: var(--surface);
  border-right: 1px solid var(--surface-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--surface-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header h1 { font-size: 20px; font-weight: 700; }
.sidebar-header .actions { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px;
  border: none;
  background: var(--surface-light);
  color: var(--text-secondary);
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--primary); color: white; }

/* Search */
.search-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface-light);
}
.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--surface-light);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}
.search-input:focus { border-color: var(--primary); }
.search-wrap { position: relative; }
.search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-hint);
  font-size: 14px;
}

/* Encryption banner */
.e2ee-banner {
  padding: 6px 16px;
  background: rgba(27,143,90,0.08);
  border-bottom: 1px solid var(--surface-light);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--primary-light);
}
.e2ee-dot { width: 6px; height: 6px; background: var(--success); border-radius: 50%; }

/* Chat List */
.chat-list { flex: 1; overflow-y: auto; }
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--surface-light); border-radius: 2px; }

.chat-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  gap: 14px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid rgba(28,37,48,0.3);
}
.chat-item:hover { background: var(--surface-light); }
.chat-item.active { background: rgba(27,143,90,0.12); }

.avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--surface-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  flex-shrink: 0;
  color: var(--text);
}
.avatar.online::after {
  content: '';
  position: absolute;
  bottom: 2px; right: 2px;
  width: 10px; height: 10px;
  background: var(--success);
  border: 2px solid var(--surface);
  border-radius: 50%;
}
.avatar { position: relative; }

.chat-info { flex: 1; min-width: 0; }
.chat-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chat-name { font-size: 15px; font-weight: 600; }
.chat-time { font-size: 11px; color: var(--text-hint); flex-shrink: 0; }
.chat-bottom { display: flex; justify-content: space-between; align-items: center; }
.chat-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chat-preview .lock { font-size: 10px; margin-right: 4px; opacity: 0.5; }
.unread-badge {
  min-width: 20px; height: 20px;
  background: var(--primary);
  color: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* ====== MAIN CHAT ====== */
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
  overflow: hidden;
}

/* Chat Header */
.chat-header {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-light);
  display: flex;
  align-items: center;
  gap: 14px;
}
.chat-header .info { flex: 1; }
.chat-header .name { font-size: 16px; font-weight: 600; }
.chat-header .status {
  font-size: 12px;
  color: var(--primary-light);
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-header .status .lock-icon { font-size: 10px; }
.chat-header .header-actions { display: flex; gap: 6px; }

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--surface-light); border-radius: 2px; }

.message {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  position: relative;
  animation: msgIn 0.2s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.sent {
  align-self: flex-end;
  background: var(--sent);
  border-bottom-right-radius: 4px;
}
.message.received {
  align-self: flex-start;
  background: var(--received);
  border-bottom-left-radius: 4px;
}
.message .meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}
.message .time { font-size: 11px; color: var(--text-hint); }
.message .status-icon { font-size: 12px; color: var(--text-hint); }
.message .status-icon.read { color: var(--accent); }

.date-divider {
  text-align: center;
  padding: 12px 0;
  font-size: 12px;
  color: var(--text-hint);
}
.date-divider span {
  background: var(--surface);
  padding: 4px 14px;
  border-radius: 8px;
}

/* Input Area */
.input-area {
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--surface-light);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
.input-wrap {
  flex: 1;
  background: var(--surface-light);
  border-radius: 24px;
  display: flex;
  align-items: flex-end;
  padding: 4px 4px 4px 18px;
}
.msg-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 10px 0;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
}
.msg-input::placeholder { color: var(--text-hint); }
.emoji-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
}
.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-light); }

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-hint);
}
.empty-state .icon { font-size: 64px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h2 { font-size: 22px; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 14px; max-width: 340px; text-align: center; line-height: 1.5; }

/* AI Panel */
.ai-panel {
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--surface-light);
  display: flex;
  flex-direction: column;
  display: none;
}
.ai-panel.open { display: flex; }
.ai-header {
  padding: 16px;
  border-bottom: 1px solid var(--surface-light);
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-header .ai-icon {
  width: 36px; height: 36px;
  background: rgba(27,143,90,0.15);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.ai-header .ai-info { flex: 1; }
.ai-header .ai-info h3 { font-size: 15px; }
.ai-header .ai-info span { font-size: 11px; color: var(--primary-light); }
.ai-actions { padding: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.ai-chip {
  padding: 8px 14px;
  background: var(--surface-light);
  border: 1px solid transparent;
  border-radius: 20px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-chip:hover { border-color: var(--primary); color: var(--primary); }
.ai-chip.active { background: rgba(27,143,90,0.15); border-color: var(--primary); color: var(--primary); }
.ai-result {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}
.ai-result-card {
  background: var(--surface-light);
  border-radius: 12px;
  padding: 16px;
}
.ai-result-card .label { font-size: 11px; color: var(--primary); font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 8px; }
.ai-result-card .content { font-size: 14px; line-height: 1.5; }
.ai-result-card .footer { font-size: 11px; color: var(--text-hint); margin-top: 10px; display: flex; align-items: center; gap: 4px; }

/* Login Screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--surface-light);
  border-radius: 20px;
  padding: 48px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.login-card .logo { font-size: 48px; margin-bottom: 20px; }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card .subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 32px; }
.form-field { margin-bottom: 16px; text-align: left; }
.form-field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.form-field input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface-light);
  border: 1px solid var(--card);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.form-field input:focus { border-color: var(--primary); }
.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.login-btn:hover { background: var(--primary-light); }
.e2ee-tag {
  margin-top: 20px;
  font-size: 13px;
  color: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { width: 320px; }
  .messages-area { padding: 16px 20px; }
  .ai-panel { display: none !important; }
}
@media (max-width: 600px) {
  .sidebar { width: 100%; }
  .main-chat { display: none; }
  .app.chatOpen .sidebar { display: none; }
  .app.chatOpen .main-chat { display: flex; }
}



/* Active Chat Layout - Fixed input at bottom */
#activeChat {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 0 !important;
}
#activeChat[style*="display:none"], #activeChat[style*="display: none"] {
  display: none !important;
}
#mainChatArea {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#emptyState {
  flex: 1;
}
