/* Base Theme & Resets */
:root {
  --bg-color: #050b14;
  --bg-panel: rgba(10, 16, 29, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  --primary-glow: #8b5cf6;
  --secondary-glow: #06b6d4;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --ai-bubble: rgba(139, 92, 246, 0.12);
  --user-bubble: rgba(6, 182, 212, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 40%, rgba(139, 92, 246, 0.12), transparent 30%),
    radial-gradient(circle at 90% 60%, rgba(6, 182, 212, 0.12), transparent 30%);
  background-attachment: fixed;
}

/* Glassmorphism System */
.glass-panel {
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
}

/* Scrollbar Modernization */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* --- Authentication Pages --- */
.auth-body {
  justify-content: center;
  align-items: center;
}

.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 1;
  padding: 2rem;
}

.auth-box {
  width: 100%;
  max-width: 420px;
  padding: 3rem 2.5rem;
  border-radius: 24px;
  text-align: center;
  animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(30px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.brand-title {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--secondary-glow), var(--primary-glow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.05em;
}

.auth-subtitle {
  color: var(--text-muted);
  margin-bottom: 2.5rem;
  font-size: 0.95rem;
  font-weight: 400;
}

.input-group {
  margin-bottom: 1.5rem;
  text-align: left;
}

.input-group label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 1rem 1.2rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  outline: none;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.input-group input:focus {
  border-color: rgba(139, 92, 246, 0.6);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.15);
}

.btn {
  width: 100%;
  padding: 1rem;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--primary-glow), #4338ca);
  color: white;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
}

.auth-links {
  margin-top: 2rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-links a {
  color: var(--secondary-glow);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.3s;
}

.auth-links a:hover {
  color: #22d3ee;
  text-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
}

.footer-auth {
  margin-top: 2rem;
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.5);
}

/* --- Chat Infrastructure --- */
.chat-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  height: 100%;
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  background: rgba(5, 11, 20, 0.85);
  backdrop-filter: blur(20px);
  z-index: 10;
  transition: transform 0.3s ease;
}

.sidebar-header {
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

.new-chat-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-radius: 12px;
  padding: 1rem;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 500;
}

.new-chat-btn:hover {
  background: rgba(139, 92, 246, 0.1);
  border-color: rgba(139, 92, 246, 0.4);
  transform: translateY(-1px);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  margin-top: 1rem;
}

.user-info {
  margin-top: auto;
  padding: 1rem 0.5rem 0;
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--secondary-glow), var(--primary-glow));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
}

.logout-btn {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  transition: all 0.3s;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: transparent;
}

.chat-header {
  padding: 1.2rem 2rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(5, 11, 20, 0.7);
  backdrop-filter: blur(15px);
  z-index: 5;
}

.chat-actions {
  display: flex;
  gap: 1rem;
}

.action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

.message-wrapper {
  display: flex;
  margin-bottom: 2rem;
  animation: slideInBottom 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message-wrapper.user {
  justify-content: flex-end;
}

.message {
  max-width: 80%;
  padding: 1.2rem 1.4rem;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.95rem;
  position: relative;
  letter-spacing: 0.2px;
}

.message.user {
  background: var(--bg-panel);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.message.ai {
  background: rgba(139, 92, 246, 0.05);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.greeting {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.code-container {
  position: relative;
  margin: 12px 0;
}

.message pre {
  background: #0d1117;
  padding: 1rem 1rem 1rem 1rem;
  border-radius: 10px;
  overflow-x: auto;
  margin-top: 0.2rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 2.5rem; /* Space for the floating button */
}

.message code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9rem;
  color: #e2e8f0;
}

.copy-code-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.2s;
  z-index: 2;
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.input-area {
  padding: 1.5rem 2rem 1rem;
  background: linear-gradient(to top, rgba(5, 11, 20, 1) 50%, rgba(5, 11, 20, 0.4));
  backdrop-filter: blur(10px);
  z-index: 5;
}

.upload-btn {
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.6rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: transparent;
}

.upload-btn:hover {
  color: var(--secondary-glow);
  background: rgba(255,255,255,0.05);
  transform: translateY(-2px);
}

.input-box {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 0.5rem 0.7rem;
  transition: all 0.3s ease;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  align-items: flex-end;
}

.input-box:focus-within {
  border-color: rgba(139, 92, 246, 0.6);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 30px rgba(139, 92, 246, 0.15);
}

.input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 0.6rem 0.8rem;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 1rem;
  line-height: 1.5;
}

.input-box textarea::placeholder {
  color: rgba(148, 163, 184, 0.5);
}

.send-btn {
  background: linear-gradient(135deg, var(--primary-glow), var(--secondary-glow));
  border: none;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  color: white;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(6, 182, 212, 0.4);
}

.typing-indicator {
  display: none;
  padding: 1.2rem 1.4rem;
  background: rgba(139, 92, 246, 0.05);
  border-radius: 16px;
  width: fit-content;
  border: 1px solid rgba(139, 92, 246, 0.15);
  margin-bottom: 2rem;
  margin-left: 2rem;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: var(--primary-glow);
  display: inline-block;
  border-radius: 50%;
  margin: 0 3px;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

footer {
  text-align: center;
  padding-top: 1rem;
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.6);
}

.error-message {
  color: #fb7185;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
  text-align: center;
  background: rgba(225, 29, 72, 0.1);
  padding: 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(225, 29, 72, 0.2);
}

/* Base Responsive */
@media (max-width: 768px) {
  .chat-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--glass-border); padding: 1rem; }
  .user-info { display: none; }
  .main-chat { height: 100%; }
}
