:root {
  --bg-dark: #0b0f19;
  --panel-bg: rgba(17, 24, 39, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  
  --user-bubble-bg: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --user-bubble-text: #ffffff;
  
  --bot-bubble-bg: rgba(30, 41, 59, 0.85);
  --bot-bubble-border: rgba(255, 255, 255, 0.1);
  --bot-bubble-text: #f1f5f9;
  
  --input-bg: rgba(15, 23, 42, 0.85);
  --input-border: rgba(99, 102, 241, 0.35);
  --input-border-focus: #6366f1;
  
  --accent-purple: #818cf8;
  --accent-cyan: #38bdf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  
  --text-muted: #94a3b8;
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  position: fixed;
  overflow: hidden;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: #f8fafc;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Ambient Glow Background Blobs */
.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.45;
}

.blob-1 {
  width: 380px;
  height: 380px;
  background: #4f46e5;
  top: -80px;
  left: -80px;
}

.blob-2 {
  width: 420px;
  height: 420px;
  background: #06b6d4;
  bottom: -100px;
  right: -100px;
}

/* App Main Container */
.chat-app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 768px;
  height: 92vh;
  max-height: 850px;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5),
              0 0 30px rgba(99, 102, 241, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-header {
  padding: 16px 24px;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(129, 140, 248, 0.15));
  border: 1px solid rgba(56, 189, 248, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

.brand-info h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.status-indicator {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-indicator .dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Chat Messages Box */
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: 95px; /* Leave space for floating input bar */
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

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

.chat-box::-webkit-scrollbar-track {
  background: transparent;
}

.chat-box::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.chat-box::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Base Message Styling */
.message {
  max-width: 78%;
  padding: 14px 18px;
  font-size: 0.95rem;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: fadeIn 0.3s ease-out forwards;
}

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

/* User Bubble - Aligned to Right */
.message.user {
  align-self: flex-end;
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-radius: 20px 20px 4px 20px;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.3);
  font-weight: 500;
}

/* Bot Bubble - Aligned to Left */
.message.bot {
  align-self: flex-start;
  background: var(--bot-bubble-bg);
  color: var(--bot-bubble-text);
  border: 1px solid var(--bot-bubble-border);
  border-radius: 20px 20px 20px 4px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

/* Thinking Indicator */
.message.thinking {
  color: var(--accent-purple);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: pulse-thinking 1.5s infinite ease-in-out;
}

@keyframes pulse-thinking {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Error Bubble */
.message.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* Floating Input Bar Container */
.floating-input-container {
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  z-index: 10;
}

form#chat-form {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--input-border);
  border-radius: 30px;
  padding: 6px 8px 6px 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4),
              0 0 20px var(--accent-glow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

form#chat-form:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5),
              0 0 25px rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
}

input[type="text"]#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-family: var(--font-family);
  font-size: 0.95rem;
  padding: 10px 0;
}

input[type="text"]#user-input::placeholder {
  color: #64748b;
}

button[type="submit"] {
  width: 44px;
  height: 44px;
  border: none;
  outline: none;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

button[type="submit"]:hover:not(:disabled) {
  transform: scale(1.05);
  background: linear-gradient(135deg, #818cf8, #6366f1);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.6);
}

button[type="submit"]:active:not(:disabled) {
  transform: scale(0.95);
}

button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #334155;
  box-shadow: none;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 0;
    align-items: stretch;
  }

  .chat-app {
    height: 100%;
    max-height: 100%;
    width: 100%;
    border-radius: 0;
    border: none;
  }

  .chat-box {
    padding-bottom: 100px;
  }

  .floating-input-container {
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
  }

  form#chat-form {
    padding: 6px 8px 6px 16px;
  }

  input[type="text"]#user-input {
    font-size: 16px; /* Prevents auto-zoom on iOS */
    padding: 12px 0;
  }

  .message {
    max-width: 90%;
    font-size: 0.9rem;
  }
}
