:root {
  --primary: #4F46E5;
  --primary-glow: rgba(79, 70, 229, 0.4);
  --secondary: #0EA5E9;

  --bg-gradient-1: #0f172a;
  --bg-gradient-2: #1e1b4b;

  --glass-bg: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(255, 255, 255, 0.4);
  --glass-shadow: rgba(0, 0, 0, 0.1);

  --text-main: #1e293b;
  --text-light: #64748b;
  --white: #ffffff;

  --msg-user-bg: linear-gradient(135deg, #4F46E5, #0EA5E9);
  --msg-bot-bg: #f1f5f9;

  --sidebar-w: 280px;
}

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

button,
input {
  touch-action: manipulation;
  /* Remove mobile tap delay */
}

body {
  height: 100vh;
  background: radial-gradient(circle at top left, var(--bg-gradient-2), var(--bg-gradient-1));
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}

/* Background Animated Shapes */
.bg-shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  z-index: -1;
  opacity: 0.6;
  animation: float 10s infinite alternate;
}

.shape-1 {
  width: 400px;
  height: 400px;
  background: var(--primary);
  top: -100px;
  left: -100px;
}

.shape-2 {
  width: 300px;
  height: 300px;
  background: var(--secondary);
  bottom: -50px;
  right: -50px;
  animation-delay: -5s;
}

@keyframes float {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }

  100% {
    transform: translate(30px, 50px) rotate(10deg);
  }
}

/* LAYOUT */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.logo-area-sidebar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
}

.logo-area-sidebar i {
  background: var(--msg-user-bg);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 1.4rem;
}

.new-chat-btn {
  background: var(--msg-user-bg);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--primary-glow);
}

.sidebar-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  flex: 1;
  max-height: calc(100vh - 250px);
}

.history-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-main);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.history-item.active {
  background: rgba(79, 70, 229, 0.1);
  color: var(--primary);
  font-weight: 500;
}

.history-empty {
  font-size: 0.85rem;
  color: var(--text-light);
  font-style: italic;
  padding: 10px;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  padding-top: 20px;
}

.nav-item {
  width: 100%;
  background: transparent;
  border: none;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-light);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
}

.nav-item:hover {
  background: rgba(0, 0, 0, 0.04);
  color: #ef4444;
  /* Red for logout */
}

/* MAIN CHAT AREA */
.chat-container {
  flex: 1;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  /* Ensure above background */
  height: 100vh;
}

/* Header */
.chat-header {
  padding: 15px 30px;
  background: rgba(255, 255, 255, 0.6);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(10px);
}

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

.header-text h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.header-text .subtitle {
  font-size: 0.8rem;
  color: var(--text-light);
}

.icon-btn {
  background: transparent;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--primary);
}

/* Status Bar */
.chat-status {
  background: rgba(255, 255, 255, 0.4);
  padding: 4px 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

/* Messages Area */
.chat-messages {
  flex: 1;
  padding: 20px 30px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bot-message {
  align-self: flex-start;
}

.bot-message .avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--primary);
  font-size: 0.9rem;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.msg-content {
  background: var(--msg-bot-bg);
  padding: 14px 18px;
  border-radius: 0 16px 16px 16px;
  color: var(--text-main);
  line-height: 1.5;
  font-size: 0.95rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
  position: relative;
}

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

.user-message .msg-content {
  background: var(--msg-user-bg);
  color: white;
  border-radius: 16px 0 16px 16px;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.msg-content strong {
  font-weight: 600;
}

.message-time {
  font-size: 0.65rem;
  margin-top: 6px;
  opacity: 0.7;
  text-align: right;
}

/* Typing Indicator */
.typing-container {
  padding: 0 30px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-light);
  font-size: 0.8rem;
  display: none;
  animation: fadeIn 0.3s;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  background: var(--text-light);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

/* Voice Button */
#mic-button {
  background: transparent;
  color: var(--text-light);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  margin-right: 5px;
}

#mic-button:hover {
  background: var(--bg-secondary);
  color: var(--primary);
}

#mic-button.recording {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

/* Suggestions */
.suggestions-area {
  padding: 10px 30px;
  gap: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.suggestion-chip {
  background: white;
  border: 1px solid #e2e8f0;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

.suggestion-chip:hover {
  background: var(--msg-user-bg);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px var(--primary-glow);
  border-color: transparent;
}

/* Input Area */
.input-area {
  padding: 20px 30px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
}

.input-wrapper {
  background: white;
  border-radius: 50px;
  padding: 6px;
  padding-left: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid #f1f5f9;
  transition: box-shadow 0.3s;
}

.input-wrapper:focus-within {
  box-shadow: 0 8px 25px rgba(79, 70, 229, 0.15);
  border-color: #e0e7ff;
}

.input-wrapper input {
  flex: 1;
  border: none;
  font-size: 0.95rem;
  outline: none;
  color: var(--text-main);
  background: transparent;
  padding: 8px 0;
}

#send-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--msg-user-bg);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.2s;
  margin-left: 10px;
}

#send-button:hover {
  transform: scale(1.05);
}

#send-button:active {
  transform: scale(0.95);
}

/* LOGIN MODAL */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.login-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: white;
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform: translateY(20px);
  transition: transform 0.3s;
  text-align: center;
}

.login-overlay.active .login-card {
  transform: translateY(0);
}

.login-icon {
  width: 60px;
  height: 60px;
  background: var(--msg-user-bg);
  border-radius: 20px;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  margin: 0 auto 20px;
  box-shadow: 0 10px 25px var(--primary-glow);
}

.login-header h2 {
  font-size: 1.5rem;
  color: var(--text-main);
  margin-bottom: 8px;
}

.login-header p {
  color: var(--text-light);
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 600;
  margin-bottom: 8px;
}

.input-icon-wrapper {
  position: relative;
}

.input-icon-wrapper i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.input-icon-wrapper input {
  width: 100%;
  padding: 12px;
  padding-left: 45px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s;
}

.input-icon-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--msg-user-bg);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
  margin-top: 10px;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px var(--primary-glow);
}

.error-msg {
  color: #ef4444;
  font-size: 0.85rem;
  margin-top: 15px;
  min-height: 20px;
}

/* RESPONSIVE */
.mobile-only {
  display: none;
}

/* Tablet / Laptop (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  :root {
    --sidebar-w: 240px;
    /* Slimmer sidebar */
  }

  .chat-header {
    padding: 15px 20px;
  }

  .chat-messages {
    padding: 20px;
  }

  .app-layout {
    max-width: 100%;
    height: 100vh;
    border-radius: 0;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .mobile-only {
    display: flex;
  }

  .app-layout {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    /* Mobile viewport fix */
    width: 100%;
    margin: 0;
    border-radius: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    /* Higher than everything */
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Overlay constraint */
  .login-overlay {
    z-index: 3000;
  }

  .login-overlay:not(.active) {
    pointer-events: none;
    /* Critical fix */
  }

  .chat-container {
    width: 100%;
    height: 100%;
    border-radius: 0;
    z-index: 10;
  }

  .chat-header {
    padding: 12px 16px;
    z-index: 20;
    position: sticky;
    top: 0;
  }

  .chat-messages {
    padding: 15px;
    padding-bottom: 90px;
    /* Space for fixed input */
  }

  .input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    z-index: 50;
    margin-bottom: 0;
  }

  .input-wrapper {
    padding-left: 16px;
    height: 50px;
    /* Larger tap target */
  }

  #send-button {
    width: 48px;
    height: 48px;
  }

  .login-card {
    margin: 20px;
    padding: 25px;
    width: 90%;
  }

  /* Hide shapes on mobile for performance/cleanliness */
  .bg-shape {
    opacity: 0.4;
  }
}