/* ═══════════════════════════════════════════════════════════
   NEXUSAI — style.css
   Dark-first design, Sora font, refined minimal aesthetic
═══════════════════════════════════════════════════════════ */

/* ── RESET ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: 'Sora', sans-serif; line-height: 1.6; overflow: hidden; height: 100dvh; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ── CSS VARIABLES ──────────────────────────────────────── */
:root {
  /* Dark theme (default) */
  --bg:          #0d0d0f;
  --bg-2:        #141416;
  --bg-3:        #1a1a1f;
  --bg-4:        #222228;
  --border:      rgba(255,255,255,0.07);
  --border-md:   rgba(255,255,255,0.12);
  --text:        #e8e8ed;
  --text-2:      #9a9aaa;
  --text-3:      #666675;
  --accent:      #7c6af7;
  --accent-2:    #9b8df9;
  --accent-glow: rgba(124,106,247,0.25);
  --user-bubble: #1e1b4b;
  --user-border: rgba(124,106,247,0.3);
  --ai-bubble:   #141416;
  --sidebar-w:   268px;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.3);
  --shadow-md:   0 8px 32px rgba(0,0,0,0.5);
  --transition:  0.2s ease;
  --font-mono:   'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg:          #f7f7f8;
  --bg-2:        #ffffff;
  --bg-3:        #efefef;
  --bg-4:        #e5e5e8;
  --border:      rgba(0,0,0,0.07);
  --border-md:   rgba(0,0,0,0.13);
  --text:        #1a1a2e;
  --text-2:      #555568;
  --text-3:      #999aaa;
  --accent:      #6355e8;
  --accent-2:    #7c6af7;
  --accent-glow: rgba(99,85,232,0.15);
  --user-bubble: #ede9ff;
  --user-border: rgba(99,85,232,0.25);
  --ai-bubble:   #ffffff;
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.06);
  --shadow-md:   0 8px 32px rgba(0,0,0,0.1);
}

/* ── LAYOUT ─────────────────────────────────────────────── */
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}

/* ── SIDEBAR ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100dvh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform var(--transition), width var(--transition);
  position: relative;
  z-index: 100;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  width: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.new-chat-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: all var(--transition);
}
.new-chat-btn:hover {
  background: var(--accent);
  color: white;
  border-color: transparent;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ── SIDEBAR SEARCH ─────────────────────────────────────── */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 12px 8px;
  padding: 8px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
}
.sidebar-search input {
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: 0.82rem;
  width: 100%;
}
.sidebar-search input::placeholder { color: var(--text-3); }

/* ── CHAT HISTORY ───────────────────────────────────────── */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-md) transparent;
}
.chat-history::-webkit-scrollbar { width: 4px; }
.chat-history::-webkit-scrollbar-track { background: transparent; }
.chat-history::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 4px; }

.history-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 8px 8px 4px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-2);
  font-size: 0.83rem;
  transition: all var(--transition);
  margin-bottom: 2px;
  group: true;
}
.history-item:hover { background: var(--bg-3); color: var(--text); }
.history-item.active { background: var(--accent-glow); color: var(--text); border: 1px solid var(--user-border); }

.history-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-del {
  opacity: 0;
  padding: 2px 4px;
  color: var(--text-3);
  font-size: 0.75rem;
  transition: opacity var(--transition);
  flex-shrink: 0;
}
.history-item:hover .history-item-del { opacity: 1; }
.history-item-del:hover { color: #ef4444; }

/* ── SIDEBAR FOOTER ─────────────────────────────────────── */
.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.83rem;
  transition: all var(--transition);
  width: 100%;
  text-align: left;
}
.footer-btn:hover { background: var(--bg-3); color: var(--text); }

/* ── MAIN PANEL ─────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  transition: background var(--transition);
}

/* ── TOPBAR ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  z-index: 10;
}

.menu-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: all var(--transition);
}
.menu-btn:hover { background: var(--bg-3); color: var(--text); }

.model-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px 6px 12px;
  color: var(--text-2);
  transition: all var(--transition);
  cursor: pointer;
}
.model-selector:hover { border-color: var(--border-md); color: var(--text); }
.model-selector select {
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); border-color: var(--border-md); }

/* ── CHAT AREA ──────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-md) transparent;
}
.chat-area::-webkit-scrollbar { width: 5px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 5px; }

/* ── WELCOME SCREEN ─────────────────────────────────────── */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  animation: fadeUp 0.5s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome-icon {
  margin-bottom: 24px;
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { filter: drop-shadow(0 0 8px var(--accent-glow)); }
  50%       { filter: drop-shadow(0 0 20px var(--accent-glow)); }
}

.welcome-title {
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 10px;
}

.welcome-sub {
  font-size: 0.95rem;
  color: var(--text-2);
  max-width: 400px;
  margin-bottom: 40px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 640px;
  width: 100%;
}

.suggestion-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  color: var(--text-2);
  font-size: 0.83rem;
  line-height: 1.5;
  transition: all var(--transition);
}
.suggestion-card:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--bg-3);
  box-shadow: 0 0 0 1px var(--accent-glow), var(--shadow-sm);
  transform: translateY(-1px);
}
.suggestion-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }

/* ── MESSAGES ───────────────────────────────────────────── */
.messages {
  padding: 20px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding-inline: 24px;
}

.message {
  display: flex;
  gap: 12px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  animation: fadeMsg 0.3s ease;
}
.message:last-child { border-bottom: none; }

@keyframes fadeMsg {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

/* Avatars */
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}
.message.user .msg-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  letter-spacing: 0.05em;
}
.message.ai .msg-avatar {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--accent);
}

/* Message bubble */
.msg-content {
  flex: 1;
  max-width: 85%;
}
.message.user .msg-content { align-items: flex-end; display: flex; flex-direction: column; }

.msg-bubble {
  padding: 13px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.7;
  word-break: break-word;
}

.message.user .msg-bubble {
  background: var(--user-bubble);
  border: 1px solid var(--user-border);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.message.ai .msg-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Message actions */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--transition);
}
.message:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--text-3);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.msg-action-btn:hover { background: var(--bg-3); color: var(--text-2); border-color: var(--border-md); }

/* Code blocks */
.msg-bubble pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}
.msg-bubble pre code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #e0e0ff;
  line-height: 1.6;
}
.msg-bubble code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.83rem;
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-2);
}

.msg-bubble p { margin-bottom: 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 10px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { margin: 16px 0 8px; font-weight: 600; }
.msg-bubble strong { font-weight: 600; color: var(--text); }

/* Copy button on pre */
.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-3);
  font-size: 0.72rem;
  transition: all var(--transition);
  cursor: pointer;
}
.copy-code-btn:hover { color: var(--text); background: var(--bg-4); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 8px 0;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
  opacity: 0.7;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40%           { transform: scale(1.1); opacity: 1; }
}

/* ── INPUT AREA ─────────────────────────────────────────── */
.input-area {
  padding: 16px 20px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-2);
  border: 1.5px solid var(--border-md);
  border-radius: var(--radius);
  padding: 10px 12px;
  max-width: 760px;
  margin: 0 auto;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.attach-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  flex-shrink: 0;
  transition: all var(--transition);
}
.attach-btn:hover { color: var(--accent); background: var(--bg-3); }

textarea#userInput {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 4px 0;
}
textarea#userInput::placeholder { color: var(--text-3); }

.send-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 2px 8px var(--accent-glow);
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-2);
  transform: scale(1.05);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.disclaimer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 10px;
  max-width: 760px;
  margin-inline: auto;
}

/* ── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  transition: opacity var(--transition);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  padding: 36px 32px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: modalIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon { font-size: 2.5rem; margin-bottom: 16px; }
.modal h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 10px; letter-spacing: -0.02em; }
.modal p { color: var(--text-2); font-size: 0.88rem; margin-bottom: 20px; }

.modal input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-3);
  border: 1.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 16px;
}
.modal input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.btn-primary {
  padding: 12px 20px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover { background: var(--accent-2); transform: translateY(-1px); }

.btn-ghost {
  padding: 12px 20px;
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-ghost:hover { background: var(--bg-4); color: var(--text); }

.modal-note { font-size: 0.75rem; color: var(--text-3); }

/* ── TOAST ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-4);
  color: var(--text);
  border: 1px solid var(--border-md);
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
  z-index: 2000;
  white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── SCROLLBAR GLOBAL ───────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 5px; }

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    z-index: 200;
    transform: translateX(calc(-1 * var(--sidebar-w)));
    box-shadow: var(--shadow-md);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }
  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: all;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .messages {
    padding-inline: 16px;
  }

  .msg-content { max-width: 92%; }
}

@media (max-width: 500px) {
  .topbar { padding: 10px 14px; }
  .input-area { padding: 12px 14px 10px; }
  .modal { padding: 28px 22px; }
}
