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

:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: rgba(18, 18, 42, 0.6);
  --bg-user: #2a2a5a;
  --bg-input: #1a1a3a;
  --border: rgba(255,255,255,0.06);
  --border-focus: rgba(79, 195, 247, 0.5);
  --accent: #4fc3f7;
  --accent-glow: rgba(79, 195, 247, 0.15);
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --text-muted: #5555aa;
  --danger: #ff5252;
  --success: #4caf50;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

html { scroll-behavior: smooth; }

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

  -webkit-font-smoothing: antialiased;
}

/* ── Particles Canvas ──────────────────────────── */
#particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ── Background ──────────────────────────── */
#bg-grid {
  position: fixed;
  inset: 0;
  background-image: 
    linear-gradient(rgba(79, 195, 247, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 195, 247, 0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  z-index: 1;
}

#bg-glow {
  position: fixed;
  width: 500px;
  height: 500px;
  top: -150px;
  right: -150px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  z-index: 1;
  pointer-events: none;
}

#app {
  position: relative;
  z-index: 2;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Login ───────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  padding: 20px;
}

.login-card {
  position: relative;
  width: 380px;
  max-width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: cardIn 0.6s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

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

.login-glow {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 20%, var(--accent-glow) 0%, transparent 50%);
  opacity: 0.5;
  pointer-events: none;
}

.login-content {
  position: relative;
  padding: 48px 36px 36px;
  text-align: center;
  z-index: 1;
}

.logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.logo-ring {
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { filter: drop-shadow(0 0 20px rgba(79,195,247,0.3)); }
  50% { filter: drop-shadow(0 0 50px rgba(79,195,247,0.5)); }
}

.logo-svg {
  width: 100%;
  height: 100%;
}

.login-content h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 32px;
}

.input-group {
  position: relative;
  margin-bottom: 16px;
  text-align: left;
}

.input-group input {
  width: 100%;
  padding: 16px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: all 0.25s;
}

.input-group input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px rgba(79, 195, 247, 0.08);
}

.input-group input::placeholder { color: transparent; }
.input-group input:not(:placeholder-shown) + .input-label,
.input-group input:focus + .input-label {
  opacity: 1;
  transform: translateY(-28px) scale(0.85);
}

.input-label {
  position: absolute;
  left: 18px;
  top: 17px;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
  transition: all 0.2s;
  opacity: 0;
}

#login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), #7c4dff);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden;
}

#login-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s;
}

#login-btn:hover::before { transform: translateX(100%); }

#login-btn:hover { 
  opacity: 0.9; 
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(79, 195, 247, 0.25);
}
#login-btn:active { transform: translateY(0); }
#login-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-loader {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

#login-btn.loading .btn-text { display: none; }
#login-btn.loading .btn-loader { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.3s;
}

.error.show { opacity: 1; }

.login-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 36px;
  border-top: 1px solid var(--border);
}

.footer-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: blink 2s infinite;
}

@keyframes blink { 50% { opacity: 0.3; } }

.footer-text {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

/* ── Chat ─────────────────────────────────── */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: 0 0 60px rgba(0,0,0,0.3);
}

/* ── Toolbar ─────────────────────────────────── */
.input-toolbar {
  display: flex;
  gap: 4px;
  padding: 0 4px 8px 4px;
}

.toolbar-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.toolbar-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79,195,247,0.06);
}

.toolbar-btn:active { transform: scale(0.92); }

/* ── Recording Bar ───────────────────────────── */
#recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-top: 8px;
  background: rgba(255, 77, 77, 0.06);
  border: 1px solid rgba(255, 77, 77, 0.2);
  border-radius: 12px;
  animation: slideUp 0.2s ease;
}

#recording-bar.hidden { display: none !important; }

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

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: recPulse 1s infinite;
}

@keyframes recPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--danger); }
  50% { opacity: 0.4; box-shadow: none; }
}

.rec-time {
  font-size: 14px;
  font-weight: 600;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

#waveform {
  flex: 1;
  height: 40px;
  border-radius: 6px;
  background: rgba(0,0,0,0.2);
}

.rec-actions {
  display: flex;
  gap: 6px;
}

.rec-cancel, .rec-send {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  transition: all 0.2s;
}

.rec-cancel {
  background: rgba(255,82,82,0.15);
  color: var(--danger);
}
.rec-cancel:hover { background: rgba(255,82,82,0.25); }

.rec-send {
  background: var(--accent);
  color: #000;
}
.rec-send:hover { opacity: 0.85; }

/* ── Preview Modal ──────────────────────────── */
#preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

#preview-modal.hidden { display: none !important; }

.preview-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.preview-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.preview-close:hover { background: rgba(0,0,0,0.8); }

#preview-body {
  max-width: 100%;
  max-height: 85vh;
}
#preview-body img { max-width: 100%; max-height: 85vh; display: block; }
#preview-body video { max-width: 100%; max-height: 85vh; display: block; }
#preview-body audio { width: 300px; padding: 20px; }

/* ── Uploaded media in messages ─────────────── */
.msg-media {
  max-width: 280px;
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: transform 0.2s;
}
.msg-media:hover { transform: scale(1.02); }

.msg-media img {
  width: 100%;
  border-radius: 10px;
  display: block;
}

.msg-media video {
  width: 100%;
  border-radius: 10px;
  display: block;
}

.msg-media audio {
  width: 100%;
  border-radius: 10px;
  background: var(--bg-input);
}

/* Audio wave in chat */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: 10px;
  min-width: 200px;
  cursor: pointer;
  transition: background 0.2s;
}
.audio-player:hover { background: rgba(79,195,247,0.08); }
.audio-player .play-icon { font-size: 20px; }
.audio-player .audio-wav { flex: 1; height: 30px; border-radius: 4px; }
.audio-player .audio-time { font-size: 11px; color: var(--text-muted); min-width: 32px; text-align: right; }

/* ── Link preview ───────────────────────────── */
.link-preview {
  display: inline-block;
  padding: 8px 14px;
  background: rgba(79,195,247,0.06);
  border: 1px solid rgba(79,195,247,0.15);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  transition: all 0.2s;
  margin: 4px 0;
}
.link-preview:hover {
  background: rgba(79,195,247,0.12);
  border-color: var(--accent);
}

.hidden { display: none !important; }

/* ── Header ──────────────────────────────────── */
header {
  padding: 14px 24px;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}

header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.3;
}

.header-left { display: flex; align-items: center; gap: 14px; }

.header-avatar {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s;
}

.header-avatar:hover { transform: scale(1.1) rotate(-5deg); }

.avatar-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 10px var(--accent-glow));
}

.header-info h2 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

.status-text {
  color: var(--success);
  font-weight: 500;
}

.status-sep {
  color: var(--text-muted);
  margin: 0 2px;
}

.header-clock {
  color: var(--text-muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

#sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

#sidebar-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 195, 247, 0.08);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#new-chat-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 195, 247, 0.08);
}

#logout-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(255, 82, 82, 0.08);
}

#new-chat-btn:active { transform: scale(0.9); }
#logout-btn:active { transform: scale(0.9); }

/* ── Messages ─────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--bg-card); border-radius: 3px; }
#messages::-webkit-scrollbar-thumb:hover { background: var(--bg-input); }

/* ── Welcome Section ───────────────────────── */
.welcome-section {
  text-align: center;
  padding: 40px 20px 20px;
  animation: fadeInUp 0.6s ease;
}

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

.welcome-msg { margin-bottom: 28px; }

.welcome-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  animation: floatLogo 4s ease-in-out infinite;
}

@keyframes floatLogo {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}

.welcome-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #fff;
}

.welcome-desc {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  max-width: 300px;
  margin: 0 auto;
}

/* ── Suggestions ─────────────────────────────── */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 400px;
  margin: 0 auto;
  animation: fadeInUp 0.8s ease;
}

.suggestion-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(26, 26, 58, 0.6);
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.25s;
  backdrop-filter: blur(4px);
}

.suggestion-chip:hover {
  border-color: var(--accent);
  background: rgba(79, 195, 247, 0.08);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(79, 195, 247, 0.15);
}

.suggestion-chip:active {
  transform: translateY(0);
}

.chip-icon { font-size: 16px; }

/* ── Messages ──────────────────────────────── */
.msg {
  max-width: 75%;
  padding: 12px 18px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 15px;
  animation: msgIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
}

/* Markdown dentro de mensajes */
.msg strong { color: var(--accent); font-weight: 600; }
.msg em { color: #b388ff; }
.msg code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: #80cbc4;
}
.msg pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 8px 0;
  overflow-x: auto;
}
.msg pre code {
  background: none;
  padding: 0;
  color: inherit;
}
.msg ul, .msg ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg li { margin: 3px 0; }
.msg a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.msg a:hover { border-bottom-color: var(--accent); }
.msg blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-dim);
  opacity: 0.8;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #2a2a5a, #3a3a7a);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(42, 42, 90, 0.3);
}

.msg.bot {
  align-self: flex-start;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg .time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
  font-weight: 500;
}

.msg.bot .time { text-align: left; }

/* Typing indicator */
.typing {
  align-self: flex-start;
  padding: 16px 24px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  gap: 6px;
  align-items: center;
  animation: msgIn 0.2s ease;
}

.typing span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-8px); box-shadow: 0 4px 8px rgba(79,195,247,0.3); }
}

/* Input area */
#input-area {
  padding: 16px 24px 20px;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Login también centrado con max-width en pantallas grandes */

.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 4px;
  transition: all 0.25s;
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px rgba(79, 195, 247, 0.06), 0 0 30px rgba(79, 195, 247, 0.05);
}

#message-input {
  flex: 1;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
}

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

#send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c4dff);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;


}

#send-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.2) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.3s;
}

#send-btn:hover::after { opacity: 1; }
#send-btn:hover { transform: scale(1.05); }
#send-btn:active { transform: scale(0.92); }
#send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

/* ── Settings Modal ───────────────────────────── */
#settings-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

#settings-modal.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.settings-content {
  width: 420px;
  max-width: 100%;
  max-height: 85vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: cardIn 0.3s ease;
}

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

.settings-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.settings-close {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.settings-close:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.settings-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
  max-height: calc(85vh - 60px);
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.settings-user-info {
  background: var(--bg-input);
  border-radius: 10px;
  padding: 12px 16px;
}

.settings-field {
  margin-bottom: 12px;
}

.settings-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.settings-field span {
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
}

.settings-field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}

.settings-field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px rgba(79, 195, 247, 0.08);
}

#pw-change-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c4dff);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

#pw-change-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(79, 195, 247, 0.25);
}

#pw-change-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#pw-change-btn.loading .btn-text { display: none; }
#pw-change-btn.loading .btn-loader { display: block; }

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

/* ── Login extras ──────────────────────────── */
.login-switch {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 16px;
}

.login-switch a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s;
}

.login-switch a:hover {
  color: #7c4dff;
  text-decoration: underline;
}

/* ── Toast ────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--danger), #d32f2f);
  color: white;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 8px 30px rgba(255,82,82,0.3);
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ── Responsive ───────────────────────────────── */
@media (max-width: 900px) {
  #chat-screen {
    max-width: 100%;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }
  .msg { max-width: 85%; }
  #messages { padding: 16px; }
  #input-area { padding: 12px 16px 16px; }
  header { padding: 12px 16px; }
  .login-content { padding: 36px 24px 28px; }
  .suggestions { gap: 8px; }
  .suggestion-chip { padding: 8px 14px; font-size: 12px; }
  .welcome-section { padding: 30px 16px 16px; }
  #message-input { -webkit-user-select: text; user-select: text; -webkit-appearance: none; }
  #input-area { padding-bottom: 24px; }
  #chat-screen { height: 100dvh; }
  #app { height: 100dvh; }
}

/* ── Sidebar ───────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
  box-shadow: 4px 0 30px rgba(0,0,0,0.3);
}

#sidebar.hidden { transform: translateX(-100%); display: flex !important; }

.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-logo { width: 32px; height: 32px; flex-shrink: 0; }
.sidebar-svg { width: 100%; height: 100%; }
.sidebar-header h3 { flex: 1; font-size: 15px; font-weight: 700; }
#sidebar-close { width: 30px; height: 30px; border: none; border-radius: 6px; background: transparent; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center; }
#sidebar-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }

#new-chat-sidebar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; margin: 8px 12px; border: 1.5px dashed var(--border); border-radius: 10px; background: transparent; color: var(--text-dim); font-size: 13px; font-family: inherit; cursor: pointer; flex-shrink: 0; }
#new-chat-sidebar:hover { border-color: var(--accent); color: var(--accent); }

#conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-empty { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.conv-item { display: flex; align-items: flex-start; padding: 10px; border-radius: 10px; cursor: pointer; gap: 6px; }
.conv-item:hover { background: rgba(255,255,255,0.04); }
.conv-item.active { background: rgba(79,195,247,0.08); border-left: 3px solid var(--accent); }
.conv-item-main { flex: 1; min-width: 0; }
.conv-title { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.conv-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.conv-count { background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 8px; font-size: 10px; color: var(--text-dim); }

#sidebar-overlay { position: fixed; inset: 0; z-index: 199; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
#sidebar-overlay.hidden { display: none !important; }

/* ── Scroll to bottom ─────────────────────── */
#scroll-bottom-btn { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); z-index: 50; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 50%; background: var(--bg-card); backdrop-filter: blur(12px); color: var(--accent); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s; box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
#scroll-bottom-btn.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(20px); }
#scroll-bottom-btn:hover { background: var(--accent); color: #fff; }

/* ── Sidebar ───────────────────────────────── */
#sidebar { position: fixed; top: 0; left: 0; width: 320px; height: 100vh; height: 100dvh; background: var(--bg-secondary); border-right: 1px solid var(--border); z-index: 200; display: flex; flex-direction: column; transition: transform 0.3s; box-shadow: 4px 0 30px rgba(0,0,0,0.3); }
#sidebar.hidden { transform: translateX(-100%); display: flex !important; }
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-header h3 { flex: 1; font-size: 15px; font-weight: 700; }
#sidebar-close { width: 30px; height: 30px; border: none; border-radius: 6px; background: transparent; color: var(--text-dim); cursor: pointer; }
#sidebar-close:hover { background: rgba(255,255,255,0.06); }
#new-chat-sidebar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; margin: 8px 12px; border: 1.5px dashed var(--border); border-radius: 10px; background: transparent; color: var(--text-dim); font-size: 13px; font-family: inherit; cursor: pointer; }
#new-chat-sidebar:hover { border-color: var(--accent); color: var(--accent); }
#conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }
.conv-item { display: flex; align-items: flex-start; padding: 10px; border-radius: 10px; cursor: pointer; gap: 6px; }
.conv-item:hover { background: rgba(255,255,255,0.04); }
.conv-item.active { background: rgba(79,195,247,0.08); border-left: 3px solid var(--accent); }
.conv-item-main { flex: 1; min-width: 0; }
.conv-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.conv-count { background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 8px; font-size: 10px; }
#sidebar-overlay { position: fixed; inset: 0; z-index: 199; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
#sidebar-overlay.hidden { display: none !important; }

/* ── Scroll to bottom ─────────────────────── */
.scroll-bottom-btn { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); z-index: 50; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 50%; background: var(--bg-card); backdrop-filter: blur(12px); color: var(--accent); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s; box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
.scroll-bottom-btn.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(20px); }
.scroll-bottom-btn:hover { background: var(--accent); color: #fff; }

/* ── Chat main ────────────────────────────── */
#chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#messages { flex: 1; min-height: 0; }

/* ── Mobile keyboard fix ─────────────────── */
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
#app { overflow: hidden; }
#chat-screen { overflow: hidden; }

/* ══════════════════════════════════════════════
   IMPROVEMENTS v2.1
   ══════════════════════════════════════════════ */

/* ── Connection Status ──────────────────────── */
#connection-status {
  font-size: 10px;
  transition: color 0.4s, text-shadow 0.4s;
}
.connection-ok { color: var(--success); text-shadow: 0 0 6px rgba(76, 175, 80, 0.5); }
.connection-err { color: var(--danger); text-shadow: 0 0 6px rgba(255, 82, 82, 0.5); }
.connection-checking { color: #ffa726; text-shadow: 0 0 6px rgba(255, 167, 38, 0.3); animation: blink 1s infinite; }

/* ── Copy button on bot messages ──────────── */
.msg.bot { position: relative; }
.msg .copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.2s;
}
.msg.bot:hover .copy-btn { opacity: 1; }
.msg .copy-btn:hover {
  background: rgba(79,195,247,0.15);
  color: var(--accent);
}
.msg .copy-btn.copied {
  opacity: 1;
  background: rgba(76,175,80,0.15);
  color: var(--success);
}

/* ── Emoji picker ────────────────────────────── */
#emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  margin-top: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  animation: slideUp 0.2s ease;
}
#emoji-picker.hidden { display: none !important; }

.emoji-item {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.emoji-item:hover {
  background: rgba(79,195,247,0.1);
  transform: scale(1.2);
}
.emoji-item:active { transform: scale(0.9); }

/* ── Skeleton loading ────────────────────────── */
.skeleton-loading {
  align-self: flex-start;
  padding: 14px 20px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
  animation: msgIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-input) 0%, rgba(79,195,247,0.08) 50%, var(--bg-input) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-line:last-child { width: 60%; }
.skeleton-line:nth-child(2) { width: 85%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Enhanced Toast ──────────────────────────── */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, #2a2a5a, #3a3a7a);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1);
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  border: 1px solid var(--border);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#toast.error {
  background: linear-gradient(135deg, var(--danger), #d32f2f);
  color: white;
}
#toast.success {
  background: linear-gradient(135deg, #2e7d32, #388e3c);
  color: white;
}

/* ── Drag & Drop Overlay ─────────────────────── */
#drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
#drag-overlay.hidden { display: none !important; }

.drag-overlay-content {
  text-align: center;
  color: var(--text-dim);
  border: 2px dashed var(--border);
  border-radius: 24px;
  padding: 48px 64px;
  transition: all 0.3s;
}
#drag-overlay.drag-active .drag-overlay-content {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79,195,247,0.04);
  transform: scale(1.03);
}
.drag-overlay-content svg { margin-bottom: 16px; }
.drag-overlay-content p {
  font-size: 18px;
  font-weight: 600;
}

/* ── Enhanced Typing Indicator ───────────────── */
.typing {
  align-self: flex-start;
  padding: 16px 24px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  gap: 6px;
  align-items: center;
  animation: msgIn 0.2s ease;
}

.typing span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0) scale(1); }
  30% { opacity: 1; transform: translateY(-10px) scale(1.1); box-shadow: 0 6px 12px rgba(79,195,247,0.3); }
}

/* ── Enhanced Msg Fade-in ────────────────────── */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg {
  animation: msgIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Smooth Transitions for interactive elements */
.toolbar-btn,
.suggestion-chip,
#send-btn,
.header-actions button,
#sidebar-toggle,
.settings-close,
#login-btn,
.preview-close,
.rec-cancel,
.rec-send,
.msg-media,
#scroll-bottom-btn,
.conv-item,
#new-chat-sidebar,
.emoji-item,
.copy-btn {
  transition: all 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
}

/* ── Better Scrollbar ────────────────────────── */
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(79,195,247,0.15), rgba(124,77,255,0.15));
  border-radius: 3px;
  border: 1px solid transparent;
  background-clip: content-box;
}
#messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(79,195,247,0.3), rgba(124,77,255,0.3));
}

/* ── Better Spacing & Shadows ────────────────── */
.msg.user {
  box-shadow: 0 4px 20px rgba(42, 42, 90, 0.3), 0 0 0 1px rgba(79,195,247,0.03);
}
.msg.bot {
  box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 0 0 1px rgba(255,255,255,0.02);
}

/* ── Responsive: Sidebar full-width on mobile ── */
@media (max-width: 900px) {
  #sidebar {
    width: 100% !important;
    max-width: 100vw;
    border-right: none;
  }
  header {
    padding: 10px 12px !important;
  }
  .header-info h2 {
    font-size: 14px;
  }
  .header-avatar {
    width: 32px;
    height: 32px;
  }
  .header-actions button {
    width: 34px;
    height: 34px;
  }
  #sidebar-toggle {
    width: 34px;
    height: 34px;
  }
  .msg {
    font-size: 14px;
    padding: 10px 14px;
  }
  .msg-media {
    max-width: 220px;
  }
  .suggestion-chip {
    font-size: 12px;
    padding: 8px 14px;
  }
  .welcome-title {
    font-size: 18px;
  }
  .welcome-desc {
    font-size: 13px;
  }
  #input-area {
    padding: 10px 12px 16px;
  }
  .input-wrapper {
    padding: 3px;
  }
  #message-input {
    font-size: 16px !important; /* Prevent zoom on iOS */
  }
  #emoji-picker {
    padding: 6px 8px;
    gap: 3px;
  }
  .emoji-item {
    width: 32px;
    height: 32px;
    font-size: 17px;
  }
}

@media (max-width: 480px) {
  .msg {
    max-width: 88%;
    font-size: 13px;
    padding: 9px 12px;
  }
  #messages {
    padding: 10px;
    gap: 8px;
  }
  .login-content {
    padding: 28px 20px 24px;
  }
  .login-content h1 {
    font-size: 24px;
  }
  .welcome-section {
    padding: 24px 12px 12px;
  }
  .settings-content {
    border-radius: 12px;
    max-height: 90vh;
  }
}
