/* ===== THEME VARIABLES ===== */
:root {
  --brand-green: #009E60; /* APMC Green */
  --brand-red: #CE1126;   /* APMC Red */
  --brand-white: #FFFFFF;
}

/* ===== FLOATING CHAT BUTTON ===== */
.chatbot-button {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: var(--brand-green);
  border: none;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 158, 96, 0.4);
  z-index: 99999;
  transition: all 0.3s ease;
}

.chatbot-button:active {
  cursor: grabbing;
}
.chatbot-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 158, 96, 0.6);
}

.chatbot-button.hidden {
  display: none;
}

/* Chat Icon */
.chat-icon {
  width: 28px;
  height: 28px;
  color: white;
  z-index: 10000;
}

/* Notification Badge */
.notification-badge {
  position: absolute;
  bottom: 70px;
  right: 0;
  background: var(--brand-white);
  color: var(--brand-green);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  animation: pulse 2s infinite;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* Hide notification badge after user interaction */
.chatbot-button.interacted .notification-badge {
  opacity: 0;
  animation: none;
}

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

/* ===== CHAT WINDOW ===== */
.chatbot-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 400px;
  max-width: 90vw; /* Don't exceed 90% of viewport width */
  height: 600px;
  max-height: 80vh; /* Don't exceed 80% of viewport height */
  background: white;
  border-radius: 12px;
  box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  overflow: hidden;
  overflow-x: hidden;
}

.chatbot-window.hidden {
  display: none;
}

/* Header */
.chatbot-header {
  background: linear-gradient(135deg, var(--brand-green) 70%, var(--brand-red) 100%);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Cursor styles removed - dragging functionality removed */

.header-left {
  display: flex;
  align-items: center;
  flex: 1;
}

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

.bot-avatar-large {
  font-size: 32px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bot-avatar-large img,
.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.bot-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bot-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.bot-subtitle {
  font-size: 12px;
  opacity: 0.9;
  line-height: 1;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

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

/* Messages Container */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--brand-green);
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--brand-red);
}

/* Message Bubble */
.message {
  animation: slideIn 0.3s ease-out;
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

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

.message-avatar {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.message-content {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.bot-message {
  align-self: flex-start;
  margin-left: 8px; /* Small gap from left edge */
}

.bot-message .message-content {
  align-items: flex-start;
}

.bot-message .message-bubble {
  background: #f0f0f0;
  color: #333;
  max-width: 100%;
}

.user-message {
  align-self: flex-end;
  width: auto;
  max-width: 100%;
  margin-left: auto; /* Push to the right */
  margin-right: 8px; /* Small gap from right edge */
}

.user-message .message-content {
  align-items: flex-end;
  width: auto;
}

.user-message .message-bubble {
  background-color: var(--brand-green);
  color: white;
  max-width: 100%;
  min-width: 120px; /* Minimum width to match bot bubble */
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap; /* Preserve line breaks but wrap text */
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  background: #f0f0f0;
  padding: 12px 16px;
  border-radius: 12px;
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #999;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(1) {
  animation-delay: 0s;
}

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

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

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

/* ===== INITIAL GRID LAYOUT ===== */
.chatbot-options {
  padding: 0 20px 20px 20px;
  flex-shrink: 0;
  max-height: none;
  overflow: visible;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  overflow-x: hidden;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

.option-card {
  background: white;
  border: 2px solid #f0f0f0;
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.option-card:hover {
  border-color: var(--brand-green);
  background: #f0fff8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 158, 96, 0.2);
}

.option-card .icon {
  font-size: 24px;
}

/* ===== POST-INTERACTION LAYOUT ===== */
.options-vertical {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 200px;            /* Limit height for scrolling */
  overflow-y: auto;
  overflow-x: hidden;          /* prevent horizontal scroll */
  -webkit-overflow-scrolling: touch;
  align-items: stretch;        /* Stretch items to full width */
  width: 100%;
}

.option-button {
  background: white;
  border: 1px solid var(--brand-green);
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--brand-green);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;              /* Full width to match container */
  max-width: 100%;         /* Maximum width */
  box-sizing: border-box;  /* Include padding in width */
}

.option-button:hover {
  background-color: var(--brand-green);
  color: var(--brand-white);
  transform: translateX(4px);
}

.option-button .icon {
  font-size: 18px;
  flex-shrink: 0;
}

.option-button:has(> div) {
  padding: 12px 16px;
  min-height: auto;
}

/* ===== INPUT AREA ===== */
.chatbot-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e0e0e0;
  background: #fafafa;
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.chatbot-input:focus {
  outline: none;
  border-color: var(--brand-green);
  box-shadow: 0 0 0 3px rgba(0, 158, 96, 0.1);
}

.chatbot-input::placeholder {
  color: #999;
}

.send-btn {
  background-color: var(--brand-green);
  color: white;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background-color: var(--brand-red);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(206, 17, 38, 0.4);
}

.send-btn:active:not(:disabled) {
  transform: translateY(0);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-icon {
  width: 18px;
  height: 18px;
}

/* ===== RESPONSIVE ===== */

/* Small screens (640px-768px): Windowed chat */
@media (max-width: 768px) and (min-width: 641px) {
  .chatbot-window {
    width: 90vw;
    height: 85vh;
    max-width: 450px;
    max-height: 85vh;
    bottom: 20px;
    right: 20px;
  }

  .chatbot-options {
    max-height: none;
    overflow: visible;
  }

  /* Ensure options wrap properly */
  .options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .option-card {
    padding: 12px 8px;
    font-size: 12px;
    min-width: unset;
    width: 100%;
  }

  .option-button {
    padding: 10px 8px;
    font-size: 12px;
    width: 100%;
    max-width: 100%;
  }
}

/* Mobile (<640px): Windowed chat, vertical stacked buttons */
@media (max-width: 640px) {
  .chatbot-window {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile keyboards */
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 0;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    /* Prevent bounce scroll on iOS */
    overscroll-behavior: none;
  }

  .chatbot-header {
    flex-shrink: 0;
    padding: 12px 16px;
  }

  .bot-name {
    font-size: 14px;
  }

  .bot-subtitle {
    font-size: 11px;
  }

  .chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    gap: 6px;
    min-height: 0;
  }

  .message-bubble {
    padding: 10px 12px;
    font-size: 14px;
  }

  .chatbot-options {
    flex-shrink: 0;
    max-height: 45vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding-bottom: 20px;
  }

  .chatbot-input-area {
    flex-shrink: 0;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .chatbot-input {
    padding: 12px 14px;
    font-size: 16px;
  }

  .send-btn {
    width: 48px;
    height: 48px;
  }

  /* Move button to left side on mobile to avoid overlapping with menu button */
  .chatbot-button {
    bottom: 20px;
    left: 20px;
    right: auto;
    z-index: 99999;
    width: 70px;
    height: 70px;
  }

  /* Hide notification badge on mobile to save space */
  .notification-badge {
    display: none;
  }

  /* Make chat icon larger on mobile */
  .chat-icon {
    width: 32px;
    height: 32px;
  }

  /* Keep 2x2 grid on mobile */
  .options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    overflow: visible;
  }

  .options-vertical {
    max-height: none;
    overflow: visible;
  }

  .option-card {
    padding: 12px;
    font-size: 12px;
    width: 100%;
    min-width: unset;
  }

  .option-card .icon {
    font-size: 20px;
  }

  .option-button {
    padding: 10px 12px;
    font-size: 13px;
    width: 100%;
    min-width: unset;
    max-width: 100%;
  }

  .option-button .icon {
    font-size: 16px;
  }

  .chatbot-input {
    padding: 8px 10px;
    font-size: 13px;
  }

  .send-btn {
    width: 36px;
    height: 36px;
  }

  .send-icon {
    width: 16px;
    height: 16px;
  }

  .doctor-card {
    padding: 12px;
  }

  .doctor-name {
    font-size: 15px;
  }

  .doctor-room {
    font-size: 13px;
  }

  .doctor-schedule {
    padding: 10px;
    font-size: 12px;
  }

  .service-card {
    padding: 10px;
    width: 100%;
  }

  .service-name {
    font-size: 13px;
  }

  .service-description {
    font-size: 11px;
  }
}

/* Tablet (641–1024px): Flexible window size */
@media (min-width: 641px) and (max-width: 1024px) {
  .chatbot-window {
    width: 80vw;
    height: 75vh;
    max-width: 450px;
    max-height: 75vh;
  }

  .chatbot-options {
    max-height: none;
    overflow: visible;
  }

  .notification-badge {
    font-size: 11px;
    padding: 6px 10px;
  }

  /* Option grid 1-2 columns on tablet */
  .options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
  }

  .option-card {
    padding: 14px;
    font-size: 13px;
    min-width: unset;
    width: 100%;
  }

  .option-button {
    width: 100%;
    max-width: 100%;
  }

  .service-card {
    padding: 11px;
  }
}

/* Small Desktop (<1200px): 400x600px window */
@media (min-width: 1025px) and (max-width: 1199px) {
  .chatbot-window {
    width: 380px;
    height: 580px;
  }

  .option-button {
    padding: 11px 14px;
    font-size: 13px;
    width: 100%;
    max-width: 100%;
  }

  .doctor-card {
    padding: 14px;
  }

  .service-card {
    padding: 11px;
  }
}

/* Large Desktop (>1200px): 400x600px window, 2x2 grid */
@media (min-width: 1200px) {
  .chatbot-window {
    width: 400px;
    height: 600px;
  }

  .options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

/* ===== DOCTOR INFO CARD ===== */
.doctor-card {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 16px;
  margin: 12px 0;
}

.doctor-photo-container {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.doctor-photo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--brand-green);
}

.doctor-photo-fallback {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}

.doctor-specialty {
  display: inline-block;
  background: var(--brand-green);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.doctor-name {
  font-size: 16px;
  font-weight: 700;
  color: #333;
  margin-bottom: 8px;
}

.doctor-room {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
}

.doctor-schedule {
  background: #f9f9f9;
  border-left: 3px solid var(--brand-green);
  padding: 12px;
  border-radius: 6px;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.6;
  color: #555;
}

.schedule-day {
  font-weight: 600;
  color: #333;
  margin-top: 8px;
}

.schedule-day:first-child {
  margin-top: 0;
}

.schedule-time {
  color: #666;
  margin-left: 12px;
}

.doctor-secretary {
  background: #f0f0f0;
  padding: 12px;
  border-radius: 6px;
  margin: 12px 0;
  font-size: 13px;
}

.secretary-label {
  font-weight: 600;
  color: #333;
  display: block;
  margin-bottom: 4px;
}

.secretary-name {
  color: #666;
  display: block;
  margin-bottom: 4px;
}

.secretary-phone {
  color: var(--brand-green);
  font-weight: 600;
  display: block;
}

.doctor-card-footer {
  background: #fff5fa;
  border: 1px solid #f0e0e8;
  border-radius: 6px;
  padding: 12px;
  margin-top: 12px;
  font-size: 13px;
  color: #555;
  line-height: 1.5;
}

/* ===== SERVICES CARDS ===== */
.services-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 350px;
  overflow-y: auto;
  padding-right: 8px;
}

.services-list::-webkit-scrollbar {
  width: 4px;
}

.services-list::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.services-list::-webkit-scrollbar-thumb {
  background: var(--brand-green);
  border-radius: 2px;
}

.service-card {
  background: white;
  border: 1px solid var(--brand-green);
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: inherit;
}

.service-card:hover {
  background: var(--brand-green);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.service-card:hover .service-name {
  color: white;
}

.service-name {
  font-weight: 700;
  color: #333;
  margin-bottom: 6px;
  font-size: 14px;
}

.service-description {
  font-size: 12px;
  color: #666;
  line-height: 1.4;
  margin-bottom: 8px;
  max-height: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.service-hours {
  font-size: 11px;
  color: var(--brand-green);
  font-weight: 600;
}

/* ===== LOADING STATES ===== */
.loading-bubble {
  display: flex;
  align-items: center;
  gap: 12px;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid var(--brand-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Disabled state for buttons */
.option-button:disabled,
.option-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Focus visible for keyboard navigation */
.option-button:focus-visible,
.option-card:focus-visible {
  outline: 2px solid var(--brand-green);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .message-bubble {
    border: 1px solid currentColor;
  }
  
  .option-button {
    border-width: 2px;
  }
  
  .option-card {
    border-width: 2px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .message {
    animation: none;
  }
  
  .typing-dot {
    animation: none;
  }
  
  .loading-spinner {
    animation: none;
  }
  
  .notification-badge {
    animation: none;
  }
}
