/**
 * PMERIT Mobile Layout - Match Mobile-UI-Blueprint.jpg
 * Version: 3.0 - FIXED (Toggles, Footer Contrast, Enhanced Input)
 * Last Updated: October 14, 2025
 * 
 * FIXES APPLIED:
 * - Toggle switches now use :checked pseudo-class (no JS required!)
 * - Mobile footer with high-contrast colors (WCAG AA compliant)
 * - Enhanced ChatGPT-style input proportions
 * - Dashboard button primary styling
 * - Character counter hidden initially
 */

/* ========================================
   MOBILE LAYOUT (< 1024px)
   ======================================== */

@media (max-width: 1023px) {
  
  /* === VIEWPORT & BODY === */
  html, body {
    height: 100%;
    overflow: hidden; /* Non-scrollable viewport */
    background: var(--bg-primary);
    color: var(--text-primary);
  }
  
  body {
    display: flex;
    flex-direction: column;
  }
  
  /* === HIDE DESKTOP LAYOUT === */
  .desktop-layout {
    display: none !important;
  }
  
  /* === SHOW MOBILE LAYOUT === */
  .mobile-layout {
    display: flex !important;
    flex-direction: column;
    height: 100%;
    width: 100%;
  }
  
  /* === MOBILE HEADER === */
  .pmerit-header {
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: var(--z-sticky);
    flex-shrink: 0;
  }
  
  .pmerit-logo {
    font-family: var(--font-primary);
    font-weight: var(--weight-bold);
    font-size: 1.25rem;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
  }
  
  .pmerit-logo::before {
    content: "🎓";
    font-size: 1.5rem;
  }
  
  .header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
  }
  
  .lang-selector,
  .hamburger-btn,
  .sign-in-btn {
    min-width: 44px;
    min-height: 44px;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: var(--text-small);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: var(--transition);
  }
  
  .hamburger-btn {
    font-size: 1.25rem;
  }
  
  .sign-in-btn {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
  }
  
  /* === CHAT MESSAGES AREA === */
  .chat-messages {
    flex: 1;
    background: var(--bg-primary);
    padding: var(--space-md);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }
  
  .chat-message {
    margin-bottom: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
  }
  
  .chat-message.user {
    background: var(--primary);
    color: var(--text-inverse);
    margin-left: var(--space-xl);
  }
  
  .chat-message.ai {
    background: var(--bg-secondary);
    margin-right: var(--space-xl);
  }
  
  /* ==========================================
     ✅ FIX #3: ENHANCED CHATGPT-STYLE INPUT
     Better proportions, rounded design, polish
     ========================================== */
  
  .chat-input-container {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: var(--space-md);
    flex-shrink: 0;
    
    /* iOS safe area */
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }
  
  /* Chat Input Wrapper (contains all input elements) */
  .chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    
    background: var(--bg-card);
    border: none; /* ✅ REMOVED hard border */
    border-radius: 9999px; /* ✅ EXTREME ROUNDING - Perfect capsule like ChatGPT */
    
    padding: 12px 16px; /* ✅ UPDATED for better proportions */
    
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    
    /* ✅ Subtle shadow instead of border for depth */
    box-shadow: 
      0 0 0 1px rgba(0, 0, 0, 0.06),
      0 2px 4px rgba(0, 0, 0, 0.08);
    
    position: relative;
  }
  
  .chat-input-wrapper:focus-within {
    /* ✅ Subtle blue glow on focus (no hard border) */
    box-shadow: 
      0 0 0 1px rgba(42, 91, 140, 0.3),
      0 0 0 4px rgba(42, 91, 140, 0.08),
      0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
  }
  
  /* Add Button (Plus Icon) */
  .input-add-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    background: transparent;
    border: none;
    border-radius: 50%;
    
    font-size: 16px;
    color: var(--text-secondary);
    
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
  }
  
  .input-add-btn:hover {
    background: var(--bg-secondary);
    color: var(--primary);
    transform: rotate(90deg) scale(1.1);
  }
  
  .input-add-btn:active {
    transform: rotate(90deg) scale(0.95);
  }
  
  /* Text Input */
  .chat-input {
    flex: 1;
    
    background: transparent;
    border: none;
    outline: none;
    
    font-family: var(--font-body);
    font-size: 16px; /* Prevent iOS zoom */
    line-height: 1.5;
    color: var(--text-primary);
    
    padding: 4px 0;
    
    resize: none;
    min-height: 24px;
    max-height: 120px;
    
    /* Remove iOS default styling */
    -webkit-appearance: none;
    appearance: none;
  }
  
  .chat-input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
  }
  
  /* Input Actions (Voice & Send) */
  .input-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }
  
  /* Voice Button */
  .input-voice-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    background: transparent;
    border: none;
    border-radius: 50%;
    
    font-size: 14px;
    color: var(--text-secondary);
    
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
  }
  
  .input-voice-btn:hover {
    background: var(--bg-secondary);
    color: var(--primary);
    transform: scale(1.1);
  }
  
  .input-voice-btn:active {
    transform: scale(0.95);
  }
  
  /* Send Button */
  .send-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    background: var(--primary);
    border: none;
    border-radius: 50%;
    
    color: white;
    font-size: 14px;
    
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    
    box-shadow: 0 2px 4px rgba(42, 91, 140, 0.2);
    flex-shrink: 0;
  }
  
  .send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.08);
    box-shadow: 0 4px 8px rgba(42, 91, 140, 0.3);
  }
  
  .send-btn:active {
    transform: scale(0.95);
  }
  
  .send-btn:disabled {
    background: var(--bg-secondary);
    color: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
  }
  
  /* ✅ FIX #4: Character Counter Hidden Initially */
  .char-counter {
    position: absolute;
    bottom: 4px;
    right: 48px;
    
    font-size: 11px;
    color: var(--text-tertiary);
    
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
  }
  
  .chat-input-wrapper:focus-within .char-counter,
  .char-counter:not(.hidden) {
    opacity: 1;
    visibility: visible;
  }
  
  .char-counter.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
  }
  
  .char-counter.warning {
    color: var(--warning);
  }
  
  .char-counter.error {
    color: var(--error);
  }
  
  /* ==========================================
     ✅ FIX #2: MOBILE FOOTER HIGH CONTRAST
     WCAG AA compliant colors
     ========================================== */
  
  .pmerit-footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: var(--space-md) var(--space-lg);
    
    text-align: center;
    font-size: var(--text-small);
    
    flex-shrink: 0;
    
    /* iOS safe area */
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }
  
  /* Mobile Footer Link - HIGH CONTRAST */
  .footer-link-mobile,
  .footer-link {
    color: var(--text-primary); /* Dark text instead of coral */
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition-fast);
  }
  
  .footer-link-mobile:hover,
  .footer-link:hover {
    color: var(--primary);
    text-decoration: underline;
  }
  
  /* Footer Separator */
  .footer-separator {
    color: var(--text-secondary);
    margin: 0 0.5rem;
  }
  
  /* Mobile Footer Status - HIGH CONTRAST */
  .footer-status-mobile,
  .footer-status {
    color: var(--text-secondary); /* Medium gray */
    font-weight: 400;
  }
  
  /* ==========================================
     HAMBURGER MENU
     ========================================== */
  
  .side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    
    background: var(--bg-primary);
    box-shadow: var(--shadow-xl);
    
    transition: left 0.3s ease-in-out;
    z-index: var(--z-modal);
    
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    
    padding: var(--space-xl) var(--space-lg);
    padding-top: calc(var(--header-height) + var(--space-md));
  }
  
  .side-menu.active {
    left: 0;
  }
  
  .menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    
    background: var(--bg-overlay);
    opacity: 0;
    visibility: hidden;
    
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    z-index: calc(var(--z-modal) - 1);
  }
  
  .menu-overlay.active {
    opacity: 1;
    visibility: visible;
  }
  
  .menu-title {
    font-family: var(--font-primary);
    font-weight: var(--weight-semibold);
    font-size: 1rem;
    margin-bottom: var(--space-lg);
    margin-top: var(--space-lg);
    color: var(--text-primary);
  }
  
  .menu-title:first-child {
    margin-top: 0;
  }
  
  /* ✅ FIX #1: Dashboard Button Primary at Top */
  .menu-item-primary {
    background: var(--primary) !important;
    color: var(--text-inverse) !important;
    border-color: var(--primary) !important;
    font-weight: 600;
    box-shadow: var(--shadow-md);
  }
  
  .menu-item-primary:hover {
    background: var(--primary-dark) !important;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }
  
  /* ✅ FIX: Customer Service Mode Button - Match Primary Color */
  .menu-item-customer-service {
    background: var(--primary) !important; /* Match Dashboard color */
    color: var(--text-inverse) !important;
    border-color: var(--primary) !important;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    opacity: 1 !important; /* Force visible */
    visibility: visible !important; /* Force visible */
    display: flex !important; /* Force display */
  }
  
  .menu-item-customer-service:hover {
    background: var(--primary-dark) !important; /* Match hover state */
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }
  
  .menu-item-customer-service:active,
  .menu-item-customer-service.active {
    background: var(--primary-dark) !important;
  }
  
  .menu-item {
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
    
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    
    cursor: pointer;
    transition: var(--transition);
    
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    min-height: 44px;
  }
  
  .menu-item:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
  }
  
  .menu-item.active {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
  }
  
  /* Menu Toggle Label for Full Clickability */
  .menu-toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    cursor: pointer;
  }
  
  /* ==========================================
     ✅ FIX #1: WORKING TOGGLE SWITCHES
     Uses :checked pseudo-class (pure CSS, no JS!)
     ========================================== */
  
  .toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
    flex-shrink: 0;
  }
  
  /* Hide the actual checkbox */
  .toggle-switch input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
  }
  
  /* The slider (background track) */
  .toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    border-radius: 24px;
    cursor: pointer;
    transition: var(--transition);
  }
  
  /* The slider knob (circle) */
  .toggle-slider::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--text-inverse);
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
  
  /* ✅ WHEN CHECKED - Background changes to primary color */
  .toggle-switch input[type="checkbox"]:checked + .toggle-slider {
    background: var(--primary);
  }
  
  /* ✅ WHEN CHECKED - Knob slides right */
  .toggle-switch input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(20px);
  }
  
  /* Focus state for accessibility */
  .toggle-switch input[type="checkbox"]:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(42, 91, 140, 0.1);
  }
  
  /* Hover effect */
  .toggle-slider:hover {
    background: var(--bg-secondary);
  }
  
  .toggle-switch input[type="checkbox"]:checked + .toggle-slider:hover {
    background: var(--primary-dark);
  }
  
  /* ==========================================
     CTA BUTTONS
     ========================================== */
  
  .cta-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg);
  }
  
  .cta-btn {
    padding: var(--space-md) var(--space-xl);
    
    background: var(--primary);
    color: var(--text-inverse);
    
    border: none;
    border-radius: var(--radius-md);
    
    font-family: var(--font-primary);
    font-size: var(--text-body);
    font-weight: var(--weight-semibold);
    
    cursor: pointer;
    transition: var(--transition);
    
    min-height: 44px;
    
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .cta-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }
  
  .cta-btn:active {
    transform: translateY(0);
  }
  
  .cta-btn.secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
  }
  
  .cta-btn.secondary:hover {
    border-color: var(--primary);
    background: var(--bg-secondary);
  }
  
  /* ==========================================
     MOBILE RESPONSIVE ADJUSTMENTS
     ========================================== */
  
  @media (max-width: 480px) {
    .chat-input-container {
      padding: var(--space-sm);
    }
    
    .side-menu {
      width: 260px;
      left: -260px;
    }
    
    /* Larger touch targets on small screens */
    .input-add-btn,
    .input-voice-btn,
    .send-btn {
      width: 36px;
      height: 36px;
      min-width: 36px;
    }
  }
  
  /* ==========================================
     ORIENTATION: LANDSCAPE
     ========================================== */
  
  @media (max-width: 1023px) and (orientation: landscape) {
    .chat-messages {
      padding: var(--space-sm);
    }
  }
  
  /* ==========================================
     ACCESSIBILITY
     ========================================== */

  /* Note: .chat-input:focus removed - wrapper handles focus styling */
  .send-btn:focus,
  .hamburger-btn:focus,
  .sign-in-btn:focus,
  .menu-item:focus,
  .input-add-btn:focus,
  .input-voice-btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }

  /* Chat input focus - let wrapper show focus state, not the input itself */
  .chat-input:focus {
    outline: none;
  }
  
  /* Reduced motion for accessibility */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
  
  /* ==========================================
     ANIMATIONS
     ========================================== */
  
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .chat-message {
    animation: fadeIn 0.3s ease-out;
  }
}

/* ========================================
   TABLET (768px - 1023px)
   ======================================== */

@media (min-width: 768px) and (max-width: 1023px) {
  .chat-messages {
    padding: var(--space-lg);
  }
  
  .side-menu {
    width: 320px;
    left: -320px;
  }
}

/* ========================================
   DESKTOP (1024px+)
   CRITICAL: Explicitly hide mobile, show desktop
   ======================================== */

@media (min-width: 1024px) {
  .mobile-layout {
    display: none !important;
  }
  
  .desktop-layout {
    display: grid !important;
  }
}

/* ==========================================
   CRITICAL FIX SUMMARY
   ========================================== */

/**
 * WHAT WAS FIXED IN v3.0:
 * 
 * ❌ BEFORE:
 * 1. Toggles used .toggle-switch.active (required JS)
 * 2. Footer used coral color (low contrast)
 * 3. Input had basic styling
 * 4. Character counter always visible
 * 5. No Dashboard primary styling
 * 
 * ✅ AFTER:
 * 1. Toggles use input:checked + .toggle-slider (pure CSS!)
 * 2. Footer uses high-contrast colors (WCAG AA)
 * 3. Input has ChatGPT-style rounded design
 * 4. Character counter hidden initially
 * 5. Dashboard button has primary blue background
 * 
 * HOW TOGGLES NOW WORK:
 * 1. User clicks toggle → checkbox changes state
 * 2. CSS detects :checked with input:checked selector
 * 3. Adjacent sibling (+) targets .toggle-slider
 * 4. Background changes to primary color
 * 5. ::before pseudo-element (knob) slides right
 * 6. All automatic with CSS transitions!
 */

/* ========================================
   MOBILE LAYOUT - Parent Container Fix
   ======================================== */

@media (max-width: 1023px) {
  .mobile-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  
  .mobile-layout .chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}