/**
 * UNIFIED MOBILE CSS
 * Single, coherent mobile experience for all devices
 * Replaces: mobile-professional.css, calm-mobile.css, mobile-optimizations.css
 */

/* ============================================================================
   LOADING AND LOGIN - Full screen coverage
   ============================================================================ */

@media (max-width: 768px) {
  /* Loading screen */
  .loading {
    z-index: 9999998 !important;
  }
  
  body.app-loading .container,
  body.app-loading .flower-decoration,
  body.app-loading .calendar-section,
  body.app-loading .gallery-section,
  body.app-loading .highlights-bar,
  body.app-loading .on-this-day,
  body.app-loading header {
    display: none !important;
  }
  
  /* Login modal */
  .login-modal {
    z-index: 9999999 !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
  
  .login-required .container,
  .login-required .gallery-section,
  .login-required .media-modal,
  .login-required .flower-decoration,
  .login-required .calendar-section,
  .login-required .highlights-bar,
  .login-required .on-this-day,
  .login-required header {
    display: none !important;
  }
}

/* ============================================================================
   GLOBAL MOBILE OPTIMIZATIONS
   ============================================================================ */

@media (max-width: 768px) {
  /* Smooth scrolling */
  body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
  }

  /* Touch optimization */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* Container */
  .container {
    padding: 0.5rem;
    overflow-x: hidden;
  }

  header {
    margin-bottom: 0.5rem;
  }

  /* Reduce decorative elements */
  .flower-decoration {
    width: 60px;
    height: 60px;
    opacity: 0.08;
    animation-duration: 30s;
  }
}

/* ============================================================================
   CALENDAR
   ============================================================================ */

@media (max-width: 768px) {
  .calendar-section {
    padding: 0.5rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
  }

  .calendar-header {
    margin-bottom: 0.5rem;
  }

  .calendar-grid {
    gap: 0.2rem;
  }

  .calendar-day {
    padding: 0.25rem;
    min-height: 60px;
    border-radius: 8px;
  }

  .calendar-day.has-photos::after {
    bottom: 2px;
    right: 2px;
  }
}

/* ============================================================================
   GALLERY - Fixed header, scrollable grid
   ============================================================================ */

@media (max-width: 768px) {
  .gallery-section {
    padding: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .gallery-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1002;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 12px rgba(138, 43, 226, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .gallery-header h2 {
    font-size: 1.1rem;
    margin: 0;
    flex: 1;
  }
  
  .close-btn {
    width: 45px;
    height: 45px;
    font-size: 1.5rem;
    flex-shrink: 0;
  }

  .gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0.5rem;
    padding-top: 80px;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .gallery-item {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(138, 43, 226, 0.12);
  }
  
  .gallery-item img,
  .gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

/* ============================================================================
   MODAL - Full screen
   ============================================================================ */

@media (max-width: 768px) {
  .media-modal {
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
  }

  .modal-content {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    padding: 1rem;
  }

  /* Close button */
  .modal-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 50px;
    height: 50px;
    font-size: 1.8rem;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 3003;
  }

  /* Navigation arrows */
  .modal-nav {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 50%;
  }

  .modal-prev {
    left: 1rem;
  }

  .modal-next {
    right: 1rem;
  }

  /* Modal info */
  .modal-info {
    padding: 16px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-radius: 16px;
  }
}

/* ============================================================================
   COMMENTS SECTION - Slide-up panel
   ============================================================================ */

@media (max-width: 768px) {
  .comments-section {
    height: 33.33vh;
    max-height: 33.33vh;
    background: var(--bg-cream);
    border-top: 3px solid var(--primary-purple);
    box-shadow: 0 -4px 16px rgba(138, 43, 226, 0.4);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .comments-header {
    background: linear-gradient(135deg, var(--primary-purple), var(--accent-violet));
    padding: 12px 16px;
  }

  .comments-header h3 {
    font-size: 0.9rem;
    color: white;
    margin: 0;
  }

  .comments-list {
    padding: 12px;
    max-height: calc(33.33vh - 140px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .comment-item {
    background: white;
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 8px;
    box-shadow: 0 2px 6px rgba(138, 43, 226, 0.15);
  }

  .comment-title {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }

  .comment-text {
    font-size: 0.75rem;
    line-height: 1.3;
  }

  /* Drag handle */
  .comments-section::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 5px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 3px;
    z-index: 10;
  }
}

/* ============================================================================
   TOUCH TARGETS - Minimum 44px
   ============================================================================ */

@media (max-width: 768px) {
  button,
  .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1rem;
  }

  /* Icon buttons */
  .close-btn,
  .modal-close,
  .nav-btn,
  .modal-nav {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Life counter buttons - icon only */
  .life-counter-btn {
    min-height: 44px;
    min-width: 44px;
    border-radius: 50%;
    padding: 0.5rem;
  }

  .life-counter-btn .btn-text {
    display: none;
  }

  .life-counter-btn .btn-icon {
    font-size: 1.2rem;
  }
}

/* ============================================================================
   TYPOGRAPHY - Prevent zoom on focus
   ============================================================================ */

@media (max-width: 768px) {
  body {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
  }

  h1, .title {
    font-size: 1.4rem;
    line-height: 1.2;
  }

  h2 {
    font-size: 1.2rem;
  }

  h3 {
    font-size: 1rem;
  }

  p, .subtitle {
    font-size: 0.95rem;
    line-height: 1.5;
  }

  /* Form inputs - prevent zoom */
  input,
  textarea,
  select {
    font-size: 16px;
    padding: 0.75rem;
    border-radius: 8px;
  }
}

/* ============================================================================
   LANDSCAPE MODE
   ============================================================================ */

@media (max-width: 768px) and (orientation: landscape) {
  .comments-section {
    height: 50vh;
    max-height: 50vh;
  }

  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .modal-content {
    padding: 0.5rem;
  }
}

/* ============================================================================
   SMALL SCREENS (< 480px)
   ============================================================================ */

@media (max-width: 480px) {
  .container {
    padding: 0.3rem;
  }

  .calendar-section {
    padding: 0.4rem;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
    padding-top: 70px;
  }

  .gallery-header h2 {
    font-size: 0.95rem;
  }

  .close-btn {
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
  }

  .modal-nav {
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
  }
}

/* ============================================================================
   SAFE AREAS - Respect device notches
   ============================================================================ */

@media (max-width: 768px) {
  .gallery-header,
  .modal-close {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .gallery-grid {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .comments-form-container {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ============================================================================
   PERFORMANCE - Reduce visual complexity
   ============================================================================ */

@media (max-width: 768px) {
  /* Reduce animations */
  @media (prefers-reduced-motion: no-preference) {
    * {
      animation-duration: 0.3s;
      transition-duration: 0.2s;
    }
  }

  /* Respect user preferences */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ============================================================================
   ADMIN BUTTONS - Proper positioning
   ============================================================================ */

@media (max-width: 480px) {
  .gallery-item .highlight-btn,
  .highlight-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    z-index: 15;
  }
  
  .gallery-item .date-btn,
  .date-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 36px;
    height: 36px;
    z-index: 15;
  }
}



