:root {
  --pink: #ff6fa3;
  --pink-dark: #e5548a;
  --pink-light: #ffe8f0;
  --user-bubble: #ffe1eb; /* pink user bubble */
  --assistant-bubble: #ffffff;
  --bg-pattern: #fff4f8; /* soft pink */
  --header-bg: linear-gradient(135deg, #ff6fa3 0%, #c06c84 100%);
}

/* Smooth theme transitions */
html, body, .chat-header, .messages-area, .chat-input-area, .send-button, .message-bubble, .input-wrapper, .chat-footer, .recording-pill {
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

/* Dark Theme */
.theme-dark body,
body.theme-dark {
  background: linear-gradient(135deg, #1e1b22 0%, #2a2029 100%) !important;
  color: #e8e8e8 !important;
}

.theme-dark .chat-container { background: #1f1a1e !important; }

.theme-dark .chat-header {
  background: linear-gradient(135deg, #5d2b45 0%, #3b2231 100%) !important;
  color: #f6e6ef !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5) !important;
}

.theme-dark .messages-area { background: #221a20 !important; }

.theme-dark .assistant-message,
.theme-dark .assistant-wrapper .message-bubble,
.theme-dark .message {
  background: #2b2329 !important;
  color: #f1eaf0 !important;
  border-color: rgba(255,255,255,0.06) !important;
}

.theme-dark .user-message,
.theme-dark .user-wrapper .message-bubble {
  background: #3a2a34 !important;
  color: #ffe7f2 !important;
}

.theme-dark .message-time { color: #b9a7b2 !important; }

.theme-dark .chat-input-area {
  background: #251d23 !important;
  border-top-color: #3a2c34 !important;
}

.theme-dark .input-wrapper {
  background: #2a2228 !important;
  border-color: #3a2c34 !important;
}

.theme-dark .chat-input,
.theme-dark .chat-input-area textarea { color: #f6e6ef !important; }

.theme-dark .send-button {
  background: linear-gradient(135deg, #b24b7a 0%, #8e3e64 100%) !important;
  box-shadow: 0 2px 10px rgba(178, 75, 122, 0.35) !important;
}

.theme-dark .recording-pill {
  background: rgba(178, 75, 122, 0.18) !important;
  color: #ffcee2 !important;
  border-color: rgba(178, 75, 122, 0.5) !important;
}

.theme-dark .chat-footer {
  background: #241c22 !important;
  border-top-color: #3a2c34 !important;
  color: #c9b8c2 !important;
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #ffb6d5 0%, #ff8dbd 100%);
  color: #333;
  height: 100vh;
  margin: 0;
  touch-action: manipulation; /* Prevents double-tap zoom */
}

/* WhatsApp-style Chat Container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-pattern);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d9d9d9' fill-opacity='0.1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  position: relative;
}

/* Chat Header */
.chat-header {
  position: fixed;
  top: 0;
  width: 100%;
  height: 60px; /* Ensure sufficient height */
  background: var(--header-bg);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  z-index: 1050; /* Ensure it stays above other elements */
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Add shadow for visibility */
}

.header-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.header-info {
  flex: 1;
  margin-left: 10px;
}

.header-name {
  font-weight: bold;
  font-size: 16px;
}

.header-status {
  font-size: 12px;
  color: #d4d4d4;
}

.avatar-header {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-reset {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

.btn-reset:hover {
  background: rgba(255, 255, 255, 0.3);
  color: white;
  transform: rotate(180deg);
}

.btn-reset:active {
  transform: rotate(180deg) scale(0.9);
}

/* Floating Background Icons */
.floating-icons {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.floating-icon {
  position: absolute;
  font-size: 24px;
  opacity: 0.15;
  animation: float linear infinite;
}

@keyframes float {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.15;
  }
  90% {
    opacity: 0.15;
  }
  100% {
    transform: translateY(-100px) rotate(360deg);
    opacity: 0;
  }
}

/* Adjust floating emoji animation speed */
.floating-emoji {
  animation: float 10s infinite ease-in-out;
}

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 2;
  background: var(--bg-pattern);
}

.messages-area::-webkit-scrollbar {
  width: 8px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

/* Message Wrapper */
.message-wrapper {
  display: flex;
  margin-bottom: 4px;
}

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

.assistant-wrapper {
  justify-content: flex-start;
}

/* Message Bubble */
.message {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 8px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  animation: fadeIn 0.3s ease-in;
  /* Ensure chat messages use Roboto at 12px */
  font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 14 px;
}



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

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

.assistant-message {
  background: white;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.message-text {
  font-size: 12px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  margin-bottom: 4px;
}

/* Markdown styling in messages */
.message-text p {
  margin: 0 0 8px 0;
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text ul,
.message-text ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-text li {
  margin: 4px 0;
}

.message-text strong,
.message-text b {
  font-weight: 600;
}

.message-text em,
.message-text i {
  font-style: italic;
}

.message-text code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.message-text pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
}

.message-text a {
  color: #0066cc;
  text-decoration: underline;
}

.user-message .message-text a {
  color: #004499;
}

.message-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #90949c;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Chat Input Area */
.chat-input-area {
  display: flex;
  align-items: center;
  padding: 10px;
  background: #fff7fa;
  border-top: 1px solid #ffd1e2;
  z-index: 100;
  flex-shrink: 0; /* Prevent input area from shrinking */
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: white;
  border-radius: 20px;
  padding: 5px 10px;
  margin-right: 10px;
  border: 1px solid #d4d4d4;
}

.chat-input-area textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  background: transparent;
}

.chat-input {
  border-radius: 25px;
  border: none;
  padding: 12px 20px;
  font-size: 16px; /* Prevents zoom on iOS - minimum 16px */
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-input:focus {
  outline: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.send-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6fa3 0%, #ff8fb4 100%);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(255, 107, 157, 0.35);
}

.send-button:hover {
  transform: scale(1.1);
}

.send-button:active {
  transform: scale(0.9);
}

/* Voice Note Button */
.btn-voice {
  background: white;
  color: var(--pink);
  border: 2px solid var(--pink);
  border-radius: 50%;
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Inline Recording Pill */
.recording-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 111, 163, 0.15);
  color: #c83f75;
  border: 1px solid rgba(255, 111, 163, 0.35);
  padding: 6px 10px;
  border-radius: 9999px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.recording-pill .pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff3b53;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 50%, 100% { opacity: 1; }
  25%, 75% { opacity: 0; }
}

/* Recording button states */
.is-recording #voiceIcon { /* voice button becomes stop */
  content: '\f04d'; /* fa-stop unicode for fallback */
}

.is-recording .send-button#sendButton { /* send becomes cancel color */
  background: #ffccd9;
  color: #c83f75;
}

/* Quick toast popup */
.toast-pop {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 14px;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 14px;
  z-index: 3000;
  pointer-events: none;
  animation: fadeInOut 1s ease forwards;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px); }
  10% { opacity: 1; transform: translateX(-50%) translateY(0); }
  90% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(6px); }
}

.is-recording #sendIcon::before { /* show an X icon via font awesome class swapped via JS; fallback color here */
  color: #c83f75;
}

.btn-voice:hover {
  background: var(--pink);
  color: white;
  transform: scale(1.05);
}

.btn-voice:active {
  transform: scale(0.95);
}

.btn-voice:disabled {
  background: #f0f0f0;
  color: #ccc;
  border-color: #ccc;
  cursor: not-allowed;
  transform: scale(1);
}

/* Attachment Button (WhatsApp style) */
.btn-attachment {
  background: white;
  color: #54656f;
  border: none;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-size: 1.3rem;
  font-weight: 600;
}

.btn-attachment:hover {
  background: #f0f0f0;
  transform: rotate(45deg) scale(1.05);
}

.btn-attachment:active {
  transform: rotate(45deg) scale(0.95);
  background: #e8e8e8;
}

.btn-attachment i {
  transition: transform 0.2s;
}

.btn-attachment:disabled {
  background: #f0f0f0;
  color: #ccc;
  cursor: not-allowed;
  transform: scale(1);
}

/* Image Upload Button (deprecated - keeping for backwards compatibility) */
.btn-image {
  background: white;
  color: var(--pink);
  border: 2px solid var(--pink);
  border-radius: 50%;
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn-image:hover {
  background: var(--pink);
  color: white;
  transform: scale(1.05);
}

.btn-image:active {
  transform: scale(0.95);
}

.btn-image:disabled {
  background: #f0f0f0;
  color: #ccc;
  border-color: #ccc;
  cursor: not-allowed;
  transform: scale(1);
}

/* Image Preview Modal */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.image-modal-content {
  background: white;
  border-radius: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
  animation: modalSlideUp 0.3s ease;
}

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

.image-modal-header {
  padding: 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--pink-light);
  border-radius: 20px 20px 0 0;
}

.image-modal-header h5 {
  margin: 0;
  color: var(--pink);
  font-size: 1.2rem;
  font-weight: 600;
}

.btn-close-modal {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: #999;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
  line-height: 1;
}

.btn-close-modal:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #333;
}

.image-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.image-modal-body textarea {
  font-size: 16px; /* Prevents zoom on iOS */
  width: 100%;
}

.preview-img {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: contain;
  border-radius: 12px;
  border: 2px solid #eee;
}

.image-modal-footer {
  padding: 20px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.image-modal-footer .btn {
  padding: 10px 20px;
  border-radius: 25px;
  font-weight: 500;
  transition: all 0.2s;
}

.image-modal-footer .btn-secondary {
  background: #f0f0f0;
  color: #666;
  border: none;
}

.image-modal-footer .btn-secondary:hover {
  background: #e0e0e0;
}

/* Recording Status */
.recording-status {
  background: white;
  padding: 15px 20px;
  border-radius: 12px;
  margin-top: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  animation: slideUp 0.3s ease-out;
}

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

.recording-pulse {
  width: 12px;
  height: 12px;
  background: #dc3545;
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.2);
  }
}

/* Admin Styles */
.admin-container {
  background: white;
  min-height: 100vh;
}

.bg-pink {
  background-color: var(--pink) !important;
}

.text-pink {
  color: var(--pink) !important;
}

.btn-pink {
  background-color: var(--pink);
  color: white;
  border: none;
}

.btn-pink:hover {
  background-color: var(--pink-dark);
  color: white;
}

.bg-pink-light {
  background-color: var(--pink-light) !important;
}

/* Admin Login */
.admin-login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--pink-light) 0%, #fff 100%);
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.avatar-login {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border: 4px solid var(--pink-light);
}

/* Footer Styling */
.chat-footer {
  background: #f0f0f0;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  color: #888;
  border-top: 1px solid #e0e0e0;
}

/* Responsive Design */
@media (max-width: 576px) {
  .chat-container {
    margin: 0;
    height: 100dvh !important; /* account for mobile browser UI */
    border-radius: 0;
  }

  /* Don't overlay the input with a fixed footer on small screens */
  .chat-footer {
    position: static !important;
    display: none; /* hide footer to avoid overlap; switch to static if you want it visible */
  }

  /* Ensure the input stays visible and comfy with safe-area insets */
  .chat-input-area {
    position: sticky;
    bottom: 0;
    z-index: 1000;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: #fff7fa;
  }

  /* Leave room so the last message isn't hidden under the sticky input */
  .messages-area {
    padding-bottom: 96px !important;
  }
}

@media (min-width: 768px) {
  .chat-container {
    max-width: 900px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  }
}

@media (max-width: 768px) {
  /* Make everything more mobile-friendly */
  .message {
    max-width: 80%;
    font-size: 12px;
  }
  
  .message-text {
    font-size: 12px;
  }
  
  .chat-header {
    padding: 10px 15px;
  }
  
  .chat-header h5 {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .avatar-header {
    width: 40px;
    height: 40px;
  }
  
  .btn-reset {
    width: 35px;
    height: 35px;
    font-size: 1rem;
  }
  
  .messages-area {
    padding: 10px;
  }
  
  .chat-input-area {
    padding: 8px 10px;
  }
  
  .chat-input {
    font-size: 14px;
    padding: 10px 15px;
  }
  
  .btn-send,
  .btn-voice,
  .btn-attachment,
  .btn-image {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }
  
  /* Stack buttons vertically on very small screens */
  .input-group {
    gap: 8px;
  }
  
  /* Image modal adjustments */
  .image-modal-content {
    max-width: 95%;
    margin: 10px;
  }
  
  .image-modal-header h5 {
    font-size: 1rem;
  }
  
  .preview-img {
    max-height: 300px;
  }
  
  .image-modal-body {
    padding: 15px;
  }
  
  .image-modal-footer {
    padding: 15px;
    flex-direction: column;
  }
  
  .image-modal-footer .btn {
    width: 100%;
  }
  
  /* Admin login adjustments */
  .login-card {
    margin: 15px;
    padding: 30px 20px;
  }
  
  .avatar-login {
    width: 80px;
    height: 80px;
  }
}

@media (max-width: 576px) {
  .message {
    max-width: 85%;
  }
  
  .floating-icon {
    font-size: 18px;
  }
  
  .chat-input {
    font-size: 13px;
  }
  
  /* Reduce padding on very small screens */
  .messages-area {
    padding: 8px;
  }
  
  .chat-input-area {
    padding: 6px 8px;
  }
  
  .chat-header {
    padding: 8px 10px;
  }
  
  .chat-header h5 {
    font-size: 0.85rem;
  }
  
  .avatar-header {
    width: 35px;
    height: 35px;
  }
  
  .btn-reset {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }
}

/* Touch-friendly buttons */
@media (hover: none) and (pointer: coarse) {
  .btn-send,
  .btn-voice,
  .btn-attachment,
  .btn-image,
  .btn-reset {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Removed old WhatsApp-like green overrides to allow theme system to work */
