:root {
  --bg-0: #0b0e1a;
  --bg-1: #10131f;
  --bg-2: #151a29;
  --bg-3: #1b2032;
  --border: #262c40;
  --text-0: #f2f3f7;
  --text-1: #c7cadb;
  --text-2: #8890a6;
  --accent-1: #7c5cff;
  --accent-2: #c85cff;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --star: #f5b800;
  --danger: #ff5c72;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

body.light {
  --bg-0: #f4f5f9;
  --bg-1: #ffffff;
  --bg-2: #f0f1f6;
  --bg-3: #e9eaf2;
  --border: #dcdfe9;
  --text-0: #1a1d29;
  --text-1: #3d4256;
  --text-2: #71768c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Segoe UI', Inter, Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-0);
  color: var(--text-0);
}

.app {
  display: grid;
  grid-template-columns: 260px 300px 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* ---------- LOGIN OVERLAY ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg-0);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px 36px;
  text-align: center; width: 340px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-title { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.login-sub { margin: 0 0 24px; color: var(--text-2); font-size: 14px; }
.google-btn-wrap { display: flex; justify-content: center; margin-bottom: 18px; min-height: 40px; }
.login-note { font-size: 11px; color: var(--text-2); line-height: 1.5; margin: 0; }
.login-error {
  color: var(--danger); font-size: 12px; margin: 10px 0 0;
}

/* ---------- NAV PANEL ---------- */
.nav-panel {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  min-height: 0;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.brand-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.brand-icon.small { width: 34px; height: 34px; font-size: 15px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--text-2); }

.new-chat-btn {
  border: none;
  cursor: pointer;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 18px;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.new-chat-btn:hover { filter: brightness(1.1); }
.new-chat-btn:active { transform: scale(0.98); }
.plus { font-size: 16px; }

.primary-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item .icon { font-size: 15px; }
.nav-item:hover { background: var(--bg-2); color: var(--text-0); }
.nav-item.active { background: var(--bg-3); color: var(--text-0); font-weight: 600; }

.nav-footer { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }

.theme-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-1);
  padding: 8px 4px;
}
.theme-label { flex: 1; }

.switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 20px; transition: 0.2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 14px; width: 14px;
  left: 2px; top: 2px; background: var(--text-2);
  border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--accent-grad); }
.switch input:checked + .slider::before { transform: translateX(18px); background: white; }
.switch.big { width: 44px; height: 24px; }
.switch.big .slider::before { height: 18px; width: 18px; }
.switch.big input:checked + .slider::before { transform: translateX(20px); }

.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: var(--radius-sm);
  background: var(--bg-2);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-grad); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-email { font-size: 11px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dots { color: var(--text-2); cursor: pointer; padding: 0 4px; background: none; border: none; font-size: 14px; }
.dots:hover { color: var(--danger); }

/* ---------- LIST PANEL ---------- */
.list-panel {
  background: var(--bg-0);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 14px;
  overflow: hidden;
  min-height: 0;
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 10px 12px;
  margin-bottom: 16px;
}
.search-box input {
  border: none; background: transparent; outline: none;
  color: var(--text-0); font-size: 13px; width: 100%;
}
.search-box input::placeholder { color: var(--text-2); }

.chat-groups { flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }
.group-label {
  font-size: 12px; color: var(--text-2); font-weight: 600;
  margin: 14px 4px 8px; text-transform: none;
}
.group-label:first-child { margin-top: 0; }

.chat-item {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 34px 10px 10px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 2px;
  border: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-2); }
.chat-item.active { background: var(--bg-3); border-color: var(--accent-1); }
.chat-item .icon { color: var(--text-2); font-size: 13px; flex-shrink: 0; }
.chat-item .title {
  flex: 1; font-size: 13px; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item.active .title { color: var(--text-0); }
.chat-item .time { font-size: 11px; color: var(--text-2); flex-shrink: 0; }
.chat-item .star { color: var(--star); font-size: 12px; flex-shrink: 0; }

.chat-delete-btn {
  display: none;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
}
.chat-item:hover .chat-delete-btn { display: inline-flex; }
.chat-delete-btn:hover { color: var(--danger); background: rgba(255, 92, 114, 0.12); }

.clear-all-btn {
  margin-top: 12px;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.clear-all-btn:hover { background: rgba(255, 92, 114, 0.1); }

/* ---------- CHAT PANEL ---------- */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}
.chat-header-brand { display: flex; align-items: center; gap: 10px; }
.chat-header-actions { display: flex; align-items: center; gap: 14px; }
.about-btn {
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text-1);
  padding: 8px 14px; border-radius: var(--radius-md); cursor: pointer; font-size: 13px;
}
.about-btn:hover { background: var(--bg-3); }

.messages {
  flex: 1;
  min-height: 0;
  height: 0;
  overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px;
}

.msg-row { display: flex; gap: 12px; max-width: 78%; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; max-width: 60%; }

.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3); border: 1px solid var(--border); font-size: 15px;
}

.msg-bubble {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px;
  font-size: 14px; line-height: 1.55; color: var(--text-0);
}
.msg-row.user .msg-bubble { background: var(--accent-grad); color: white; border: none; }
.msg-bubble ul { margin: 8px 0; padding-left: 20px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble li strong { color: inherit; }

.msg-meta {
  display: flex; align-items: center; gap: 10px; margin-top: 6px;
  font-size: 11px; color: var(--text-2);
}
.msg-row.user .msg-meta { justify-content: flex-end; }
.msg-actions { display: flex; gap: 8px; }
.msg-actions button {
  background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 12px;
}
.msg-actions button:hover { color: var(--text-0); }

.typing-dots span {
  display: inline-block; width: 6px; height: 6px; margin-right: 3px;
  border-radius: 50%; background: var(--text-2);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ---------- COMPOSER ---------- */
.composer {
  padding: 16px 24px 20px; border-top: 1px solid var(--border); background: var(--bg-1);
  flex-shrink: 0;
}
.composer-box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 10px 14px;
}
.composer-box textarea {
  flex: 1; resize: none; border: none; background: transparent; outline: none;
  color: var(--text-0); font-size: 14px; font-family: inherit; max-height: 120px; padding: 6px 0;
}
.composer-box textarea::placeholder { color: var(--text-2); }
.composer-actions-left { display: flex; gap: 6px; }
.icon-btn {
  background: none; border: none; color: var(--text-2); cursor: pointer;
  font-size: 15px; padding: 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-0); }

.send-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  background: var(--accent-grad); color: white; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.disclaimer { text-align: center; font-size: 11px; color: var(--text-2); margin-top: 10px; }

/* Scrollbars */
.chat-groups::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 6px; }
.chat-groups::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 6px;
}

/* ---------- STAR TOGGLE BUTTON ---------- */
.chat-item .star-btn {
  background: none; border: none; cursor: pointer; flex-shrink: 0;
  font-size: 13px; color: var(--text-2); padding: 2px 4px; line-height: 1;
}
.chat-item .star-btn.starred { color: var(--star); }
.chat-item .star-btn:hover { color: var(--star); }

/* Chat item layout needs to fit: icon, title, star-btn, time, delete btn */
.chat-item { padding-right: 34px; }

/* ---------- CHAT RENAME (inline edit) ---------- */
.chat-item .title-input {
  flex: 1; font-size: 13px; color: var(--text-0);
  background: var(--bg-3); border: 1px solid var(--accent-1);
  border-radius: 4px; padding: 2px 6px; outline: none; font-family: inherit;
}

/* ---------- NO CHATS / EMPTY STATES ---------- */
.empty-state {
  padding: 24px 8px; text-align: center; color: var(--text-2); font-size: 13px;
}

/* ---------- MODALS (Settings / About) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 420px; max-width: 90vw;
  max-height: 80vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close {
  background: none; border: none; color: var(--text-2); cursor: pointer;
  font-size: 16px; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-3); color: var(--text-0); }
.modal-body { padding: 18px 20px; }

.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border);
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row-title { font-size: 13px; font-weight: 600; color: var(--text-0); }
.settings-row-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.danger-btn {
  margin-top: 16px; width: 100%;
  border: 1px solid var(--danger); background: transparent; color: var(--danger);
  border-radius: var(--radius-md); padding: 10px; font-size: 13px; cursor: pointer;
}
.danger-btn:hover { background: rgba(255, 92, 114, 0.1); }

.about-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.about-text { font-size: 13px; color: var(--text-1); line-height: 1.6; margin: 0 0 12px; }
.about-text.small { font-size: 11px; color: var(--text-2); }
.about-list { margin: 0 0 14px; padding-left: 20px; font-size: 13px; color: var(--text-1); line-height: 1.8; }

/* ---------- SUGGESTIONS POPOVER ---------- */
.suggestions-popover {
  position: absolute;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: 0 12px 32px rgba(0,0,0,0.35);
  padding: 6px; z-index: 500; width: 260px;
}
.suggestions-popover button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text-1); cursor: pointer;
  font-size: 13px; padding: 9px 10px; border-radius: var(--radius-sm);
}
.suggestions-popover button:hover { background: var(--bg-3); color: var(--text-0); }

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 0 0 1fr; }
  .nav-panel, .list-panel { display: none; }
}