/**
 * Responsive Fixes for WebKMT
 * Fixes chatbot window and mobile menu responsiveness issues
 */

/* ============================================================================
   CHATBOT RESPONSIVE FIXES
   ============================================================================ */

/* Base chatbot improvements */
.chatbot-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 999;
}

.chatbot-widget {
  position: absolute;
  bottom: 4rem;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 500px;
  max-height: calc(100vh - 120px);
  background: var(--bg-glass-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.1),
    0 8px 24px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: scale(0.8) translateY(20px);
  transform-origin: bottom right;
  visibility: hidden;
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-widget.active {
  opacity: 1;
  transform: scale(1) translateY(0);
  visibility: visible;
}

.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.chatbot-messages {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0; /* Important for proper flex behavior */
}

.chatbot-input-area {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

/* Tablet responsiveness (768px - 1023px) */
@media (max-width: 1023px) and (min-width: 768px) {
  .chatbot-container {
    bottom: 1.5rem;
    right: 1.5rem;
  }

  .chatbot-widget {
    width: 360px;
    height: 480px;
    max-height: calc(100vh - 100px);
  }
}

/* Mobile responsiveness (below 768px) - High specificity to override forms-auth-bundle.css */
@media (max-width: 767px) {
  .chatbot-container {
    bottom: 1rem !important;
    right: 1rem !important;
    left: 1rem !important;
  }

  .chatbot-widget {
    position: fixed !important;
    bottom: 5rem !important;
    left: 1rem !important;
    right: 1rem !important;
    width: auto !important;
    max-width: calc(100vw - 2rem) !important;
    height: 70vh !important;
    max-height: 500px !important;
    min-height: 350px !important;
    transform-origin: bottom center !important;
  }

  .chatbot-trigger {
    border-radius: 50%;
    padding: 0.875rem;
    width: 56px;
    height: 56px;
  }

  .chatbot-label {
    display: none;
  }

  .chatbot-messages {
    padding: 0.875rem;
  }

  .chatbot-input-area {
    padding: 0.875rem;
  }

  .chatbot-form {
    gap: 0.5rem;
  }

  .chatbot-input {
    padding: 0.75rem;
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* Small mobile (below 480px) */
@media (max-width: 479px) {
  .chatbot-container {
    bottom: 0.75rem !important;
    left: 0.75rem !important;
    right: 0.75rem !important;
  }

  .chatbot-widget {
    bottom: 4rem !important;
    left: 0.75rem !important;
    right: 0.75rem !important;
    width: auto !important;
    max-width: calc(100vw - 1.5rem) !important;
    height: 75vh !important;
    max-height: 450px !important;
    border-radius: 12px !important;
  }

  .chatbot-header {
    padding: 0.75rem;
  }

  .chatbot-messages {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .chatbot-input-area {
    padding: 0.75rem;
  }
}

/* ============================================================================
   MOBILE MENU RESPONSIVE FIXES
   ============================================================================ */

/* Base mobile menu improvements */
.mobile-menu-enhanced {
  position: fixed;
  top: 80px;
  right: -100%;
  width: min(320px, 85vw);
  height: calc(100vh - 80px);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--border-primary);
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  z-index: 1000;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.1);
}

.mobile-menu-enhanced.active {
  right: 0;
}

.mobile-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 999;
  backdrop-filter: blur(2px);
}

.mobile-menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

.mobile-nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 1rem 0;
}

.mobile-nav-link {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
  position: relative;
}

.mobile-nav-link:hover,
.mobile-nav-link.active {
  background: rgba(var(--color-primary-rgb), 0.1);
  color: var(--color-primary);
  border-left: 3px solid var(--color-primary);
  padding-left: calc(1.5rem - 3px);
}

.mobile-nav-link:active {
  transform: scale(0.98);
}

/* Hamburger improvements */
.hamburger-enhanced {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 2.5rem;
  height: 2.5rem;
  background: transparent;
  border: 1px solid var(--border-secondary);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s ease;
  z-index: 1001;
}

.hamburger-enhanced:hover {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.1);
}

.hamburger-enhanced:active {
  transform: scale(0.95);
}

.hamburger-line {
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  margin: 2px 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}

.hamburger-enhanced.active .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-enhanced.active .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}

.hamburger-enhanced.active .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* Show hamburger on tablets and mobile */
@media (max-width: 1023px) {
  .hamburger-enhanced {
    display: flex;
  }
}

/* Mobile specific improvements */
@media (max-width: 767px) {
  .mobile-menu-enhanced {
    width: 100%;
    max-width: none;
    right: -100%;
    top: 70px; /* Adjust for smaller header */
    height: calc(100vh - 70px);
  }

  .mobile-nav-link {
    padding: 1.25rem 1.5rem;
    font-size: 1.1rem;
  }

  .hamburger-enhanced {
    width: 2.25rem;
    height: 2.25rem;
  }

  .hamburger-line {
    width: 16px;
  }
}

/* Small mobile adjustments */
@media (max-width: 479px) {
  .mobile-menu-enhanced {
    top: 60px; /* Smaller header on very small screens */
    height: calc(100vh - 60px);
  }

  .mobile-nav-link {
    padding: 1rem 1.25rem;
    font-size: 1rem;
  }

  .hamburger-enhanced {
    width: 2rem;
    height: 2rem;
  }

  .hamburger-line {
    width: 14px;
  }
}

/* ============================================================================
   RTL SUPPORT
   ============================================================================ */

[dir="rtl"] .chatbot-container {
  left: 2rem;
  right: auto;
}

[dir="rtl"] .chatbot-widget {
  left: 0;
  right: auto;
  transform-origin: bottom left;
}

[dir="rtl"] .mobile-menu-enhanced {
  right: auto;
  left: -100%;
  border-right: 1px solid var(--border-primary);
  border-left: none;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.1);
}

[dir="rtl"] .mobile-menu-enhanced.active {
  left: 0;
}

[dir="rtl"] .mobile-nav-link:hover,
[dir="rtl"] .mobile-nav-link.active {
  border-right: 3px solid var(--color-primary);
  border-left: none;
  padding-right: calc(1.5rem - 3px);
  padding-left: 1.5rem;
}

@media (max-width: 767px) {
  [dir="rtl"] .chatbot-container {
    left: 1rem;
    right: 1rem;
  }

  [dir="rtl"] .chatbot-widget {
    left: 1rem;
    right: 1rem;
  }

  [dir="rtl"] .mobile-menu-enhanced {
    left: -100%;
    right: auto;
    width: 100%;
  }
}

/* ============================================================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================================================ */

/* Focus states */
.chatbot-trigger:focus,
.hamburger-enhanced:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.mobile-nav-link:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .chatbot-widget,
  .mobile-menu-enhanced,
  .mobile-menu-overlay,
  .hamburger-line {
    transition: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .chatbot-widget,
  .mobile-menu-enhanced {
    border-width: 2px;
  }

  .mobile-nav-link {
    border-bottom-width: 2px;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .mobile-nav-link {
    padding: 1.5rem;
    min-height: 48px; /* Minimum touch target size */
  }

  .chatbot-trigger,
  .hamburger-enhanced {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Landscape mobile improvements */
@media (max-width: 767px) and (orientation: landscape) {
  .chatbot-widget {
    height: 85vh;
    max-height: 400px;
  }

  .mobile-menu-enhanced {
    height: calc(100vh - 60px);
    top: 60px;
  }
}

/* ============================================================================
   CHATBOT MESSAGE READABILITY IMPROVEMENTS
   ============================================================================ */

/* Fix AI response bubble for better readability using brand colors */
.bot-message .message-text {
  background: rgba(10, 172, 184, 0.1) !important; /* Light brand color background */
  border: 1px solid rgba(10, 172, 184, 0.2);
  color: var(--text-primary) !important;
  backdrop-filter: none; /* Remove blur for better readability */
}

/* Enhanced contrast for dark mode */
[data-theme="dark"] .bot-message .message-text {
  background: rgba(124, 58, 237, 0.15) !important; /* Purple brand color for dark mode */
  border: 1px solid rgba(124, 58, 237, 0.3);
  color: var(--text-primary) !important;
}

/* Ensure user messages remain distinct */
.user-message .message-text {
  background: var(--color-primary) !important;
  color: white !important;
  border: none;
}

/* ============================================================================
   DARK MODE OPTIMIZATIONS
   ============================================================================ */

[data-theme="dark"] .chatbot-widget,
[data-theme="dark"] .mobile-menu-enhanced {
  background: rgba(17, 24, 39, 0.95);
  border-color: rgba(75, 85, 99, 0.3);
}

[data-theme="dark"] .mobile-menu-overlay {
  background: rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .mobile-nav-link:hover,
[data-theme="dark"] .mobile-nav-link.active {
  background: rgba(var(--color-primary-rgb), 0.15);
}

/* ============================================================================
   ADMIN ACCESS BUTTON STYLING
   ============================================================================ */

/* Admin Access Button in User Menu */
.admin-access-btn {
  color: var(--color-primary) !important;
  font-weight: 500;
}

.admin-access-btn:hover {
  background: rgba(10, 172, 184, 0.1) !important;
  color: var(--color-primary-dark, #0891a7) !important;
}

.admin-access-btn svg {
  color: var(--color-primary);
}

/* ============================================================================
   STATIC CHAT TRIGGER HOVER EFFECTS
   ============================================================================ */

/* Replace inline event handlers with CSS for CSP compliance */
#staticChatTrigger:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 8px 24px rgba(10, 172, 184, 0.4) !important;
}

/* ============================================================================
   MOBILE MENU DEBUG AND FIXES
   ============================================================================ */

/* Ensure hamburger is properly visible and clickable */
.hamburger-enhanced {
  display: flex !important;
  position: relative !important;
  z-index: 1001 !important;
  cursor: pointer !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

/* Ensure mobile menu is properly positioned */
.mobile-menu-enhanced {
  position: fixed !important;
  top: 80px !important;
  right: -100% !important;
  width: min(320px, 85vw) !important;
  height: calc(100vh - 80px) !important;
  background: var(--bg-glass) !important;
  z-index: 1000 !important;
  transition: right 0.3s ease !important;
}

.mobile-menu-enhanced.active {
  right: 0 !important;
}