/* ==========================================================================
   MOBILE DESIGN SYSTEM & RESPONSIVE LAYOUTS (mobile.css)
   Targets screens under 900px, keeping desktop pixel-perfect.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design System Tokens (Mobile Overrides)
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  :root {
    /* Mobile Typography Scale */
    --font-size-h1: 1.8rem;
    --font-size-h2: 1.4rem;
    --font-size-body: 0.95rem;
    --font-size-small: 0.8rem;
    
    /* Spacing & Layout */
    --mobile-padding-outer: 1rem;
    --mobile-padding-card: 1.25rem;
    --mobile-spacing-y: 1.2rem;
    --mobile-card-gap: 1rem;
    
    /* Safe Touch Target size */
    --touch-target-min: 44px;
    --mobile-border-radius: 16px;
    --mobile-border-radius-sm: 10px;
    
    /* Transitions */
    --mobile-transition-speed: 0.3s;
    --mobile-transition-easing: cubic-bezier(0.4, 0, 0.2, 1);
  }
}

/* --------------------------------------------------------------------------
   2. Responsive Ranges (Media Queries & Spacing Rules)
   -------------------------------------------------------------------------- */

/* --- LAPTOP RANGE (901px - 1399px) --- */
@media (min-width: 901px) and (max-width: 1399px) {
  body {
    font-size: 15px;
  }
  .page-container,
  .dashboard-wrapper {
    width: 92%;
    max-width: 1100px;
    gap: 1.5rem;
  }
}

/* --- TABLET RANGE (601px - 900px) --- */
@media (max-width: 900px) {
  /* Suppress desktop navigation */
  .navbar .nav-links,
  .navbar .logout-btn {
    display: none !important;
  }
  
  /* Make navbar container responsive */
  .navbar {
    padding: 0.8rem 1.2rem !important;
    border-radius: 16px !important;
    gap: 0.5rem !important;
  }

  /* Enforce viewport stabilization and clip horizontal scroll overflows */
  html, body {
    overflow-x: hidden !important;
    max-width: 100% !important;
    position: relative !important;
  }

  /* Prevent background animated elements from causing layout shifts */
  .sky-background,
  .aurora-glow,
  .stars-bg,
  .stars,
  #starsBg,
  #stars,
  .star {
    overflow: hidden !important;
    max-width: 100vw !important;
    pointer-events: none !important;
  }

  /* Safe Area paddings on body & main wrappers */
  body {
    padding-bottom: calc(2.5rem + env(safe-area-inset-bottom)) !important;
  }

  .page-container,
  .dashboard-wrapper {
    width: 95%;
    margin-top: 1rem !important;
    padding-left: env(safe-area-inset-left) !important;
    padding-right: env(safe-area-inset-right) !important;
    gap: var(--mobile-spacing-y) !important;
  }

  /* Universal typographic updates */
  h1, .page-title, .hero-title {
    font-size: var(--font-size-h1) !important;
  }
  
  h2, .card-title, .form-title {
    font-size: var(--font-size-h2) !important;
  }

  /* Make sure inputs and buttons are easily clickable */
  input, select, textarea, button, .btn {
    min-height: var(--touch-target-min);
  }
  
  .nav-link, .tab-btn, .filter-btn {
    min-height: calc(var(--touch-target-min) - 4px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* --- PHONE RANGE (600px and below) --- */
@media (max-width: 600px) {
  .page-container,
  .dashboard-wrapper {
    width: 98%;
    padding-left: max(0.5rem, env(safe-area-inset-left)) !important;
    padding-right: max(0.5rem, env(safe-area-inset-right)) !important;
  }

  /* General Cards Padding */
  .dashboard-card,
  .welcome-card,
  .search-card,
  .ai-answer-card,
  .form-container,
  .setup-card {
    padding: var(--mobile-padding-card) !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  /* Hide decorative stars on mobile if they degrade performance */
  .stars-bg, .stars-container {
    opacity: 0.4;
  }
}

/* --------------------------------------------------------------------------
   3. Landscape Adaptations (max-height: 480px)
   -------------------------------------------------------------------------- */
@media (max-height: 480px) and (max-width: 900px) {
  body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }
  
  .page-container,
  .dashboard-wrapper {
    margin-top: 0.5rem !important;
    gap: 0.8rem !important;
  }
  
  /* Compact headers in landscape */
  .header-section, .hero-section {
    padding: 1rem !important;
  }
  
  .page-title, .hero-title {
    font-size: 1.5rem !important;
  }
}

/* --------------------------------------------------------------------------
   4. Reusable Mobile Utility Classes (Zero CLS layout helpers)
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .m-hide-desktop {
    display: inherit !important;
  }
  .m-show-mobile {
    display: inherit !important;
  }
  .m-flex-col {
    flex-direction: column !important;
  }
  .m-grid-1 {
    grid-template-columns: 1fr !important;
  }
  .m-p-0 {
    padding: 0 !important;
  }
  .m-touch-target {
    min-height: var(--touch-target-min) !important;
  }
  .m-w-100 {
    width: 100% !important;
  }
  /* Prevents horizontal overflow issues */
  .m-overflow-x-hidden {
    overflow-x: hidden !important;
  }
}

@media (min-width: 901px) {
  .m-hide-desktop {
    display: none !important;
  }
  .m-show-mobile {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   5. Reusable Mobile Navigation (Hamburger & Slide Drawer)
   -------------------------------------------------------------------------- */

/* Hamburger Button (Positioned fixed/absolute dynamically in JS) */
.mobile-nav-toggle {
  display: none;
  background: rgba(13, 27, 42, 0.6);
  border: 1px solid rgba(126, 200, 227, 0.25);
  color: var(--accent);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  z-index: 100010;
  padding: 0;
  align-items: center;
  justify-content: center;
  transition: all 0.3s var(--mobile-transition-easing);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mobile-nav-toggle:hover {
  background: rgba(74, 144, 217, 0.2);
  border-color: var(--accent);
}

.mobile-nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Three lines menu animation */
.hamburger-box {
  width: 22px;
  height: 14px;
  position: relative;
  display: inline-block;
}

.hamburger-inner,
.hamburger-inner::before,
.hamburger-inner::after {
  width: 22px;
  height: 2px;
  background-color: var(--accent);
  position: absolute;
  transition-property: transform;
  transition-duration: 0.15s;
  transition-timing-function: ease;
  border-radius: 2px;
}

.hamburger-inner {
  top: 50%;
  transform: translateY(-50%);
}

.hamburger-inner::before {
  content: "";
  top: -6px;
}

.hamburger-inner::after {
  content: "";
  bottom: -6px;
}

/* Hamburger Active/Open State */
.mobile-nav-toggle.open .hamburger-inner {
  transform: rotate(45deg);
}

.mobile-nav-toggle.open .hamburger-inner::before {
  top: 0;
  opacity: 0;
}

.mobile-nav-toggle.open .hamburger-inner::after {
  bottom: 0;
  transform: rotate(-90deg);
}

/* Mobile Slide Drawer Containers */
.mobile-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 100000;
  display: none; /* Controlled by JS */
  opacity: 0;
  overflow: hidden !important;
  transition: opacity var(--mobile-transition-speed) var(--mobile-transition-easing);
}

.mobile-drawer-overlay.open {
  opacity: 1 !important;
}

/* Blurred backdrop */
.mobile-drawer-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 15, 26, 0.45);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  cursor: pointer;
}

/* Drawer panel structure */
.mobile-drawer-panel {
  position: absolute;
  top: 0;
  width: 80%;
  max-width: 320px;
  height: 100%;
  background: rgba(13, 27, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 0 35px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  transition: transform var(--mobile-transition-speed) var(--mobile-transition-easing);
  
  /* Support iPhone Safe Areas inside the panel */
  padding-top: max(1.2rem, env(safe-area-inset-top));
  padding-bottom: max(1.2rem, env(safe-area-inset-bottom));
}

/* RTL Slide-in behavior */
[dir="rtl"] .mobile-drawer-panel {
  right: 0;
  transform: translateX(100%);
  border-left: 1px solid rgba(126, 200, 227, 0.2);
}

[dir="rtl"] .mobile-drawer-overlay.open .mobile-drawer-panel {
  transform: translateX(0);
}

/* LTR Slide-in behavior */
[dir="ltr"] .mobile-drawer-panel {
  left: 0;
  transform: translateX(-100%);
  border-right: 1px solid rgba(126, 200, 227, 0.2);
}

[dir="ltr"] .mobile-drawer-overlay.open .mobile-drawer-panel {
  transform: translateX(0);
}

/* Drawer Header (Brand + Close button) */
.mobile-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid rgba(126, 200, 227, 0.1);
  flex-shrink: 0;
}

.mobile-drawer-brand {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  text-shadow: 0 0 10px rgba(126, 200, 227, 0.3);
}

.mobile-drawer-close {
  background: rgba(13, 27, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-color);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  line-height: 1;
  transition: all 0.3s ease;
}

.mobile-drawer-close:hover {
  background: #ff6b6b;
  color: #0D1B2A;
  box-shadow: 0 0 10px rgba(255, 107, 107, 0.4);
}

/* Scrollable Drawer List area */
.mobile-drawer-body {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}

.mobile-drawer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 0;
  margin: 0;
}

.mobile-drawer-link {
  color: var(--text-color);
  text-decoration: none;
  font-size: 1.1rem;
  padding: 0.75rem 1.2rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  transition: all 0.25s ease;
  min-height: var(--touch-target-min);
  background: transparent;
  border: 1px solid transparent;
}

/* RTL Link text alignment */
[dir="rtl"] .mobile-drawer-link {
  text-align: right;
  justify-content: flex-start;
}

/* LTR Link text alignment */
[dir="ltr"] .mobile-drawer-link {
  text-align: left;
  justify-content: flex-start;
}

.mobile-drawer-link:hover,
.mobile-drawer-link.active {
  color: var(--accent);
  background: rgba(126, 200, 227, 0.1);
  border-color: rgba(126, 200, 227, 0.15);
}

.mobile-drawer-link.active {
  font-weight: 600;
  text-shadow: 0 0 10px rgba(126, 200, 227, 0.4);
  box-shadow: inset 0 0 15px rgba(126, 200, 227, 0.05);
}

/* Pin Logout to bottom */
.mobile-drawer-footer {
  padding: 1.5rem;
  border-top: 1px solid rgba(126, 200, 227, 0.1);
  flex-shrink: 0;
}

.mobile-drawer-logout {
  width: 100%;
  border-color: rgba(255, 107, 107, 0.4);
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.05);
  border: 1px solid rgba(255, 107, 107, 0.2);
  padding: 0.8rem;
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s ease;
  min-height: var(--touch-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.mobile-drawer-logout:hover {
  background: #ff6b6b;
  color: #0D1B2A;
  box-shadow: 0 0 15px rgba(255, 107, 107, 0.4);
}

/* Prevent body scrolling when drawer is active */
body.drawer-open {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* --------------------------------------------------------------------------
   6. Accessibility: Reduced Motion Overrides
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  ::before,
  ::after {
    animation-delay: -1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    background-attachment: initial !important;
    scroll-behavior: auto !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
  }
  
  .mobile-drawer-panel {
    transform: none !important;
  }
}

/* Show Hamburger toggle below 900px breakpoint */
@media (max-width: 900px) {
  .mobile-nav-toggle {
    display: flex;
  }
}

/* ==========================================================================
   7. Dashboard-Specific Overrides (index.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Dynamic Grid layout for dashboard cards */
  #dashboardWrapper .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.2rem !important;
  }

  /* Specific Card Ordering & Span overrides */
  #dashboardWrapper .dashboard-grid > section:nth-of-type(1) { 
    grid-column: span 2 !important;
    order: 1 !important; 
  } /* Days of Love (Counter) */

  #dashboardWrapper .dashboard-grid > section.checkin-card { 
    grid-column: span 1 !important;
    order: 2 !important; 
    min-height: 180px !important;
    margin: 0 !important;
  } /* Check-in widget */

  #dashboardWrapper .dashboard-grid > section:nth-of-type(4) { 
    grid-column: span 1 !important;
    order: 3 !important; 
    min-height: 180px !important;
  } /* Partner View Card */

  #dashboardWrapper .dashboard-grid > section:nth-of-type(2) { 
    grid-column: span 2 !important;
    order: 4 !important; 
  } /* Today's Mood Slider widget */

  #dashboardWrapper .dashboard-grid > section.menu-grid-card { 
    grid-column: span 2 !important;
    order: 5 !important; 
  } /* Navigation Grid launcher */

  /* Title header bars compacting */
  #dashboardWrapper .dashboard-header-bar {
    font-size: 2.2rem !important;
    margin-top: 0.5rem !important;
  }
  
  #dashboardWrapper .header-separator {
    width: 80% !important;
    margin: 0.8rem auto 1.5rem auto !important;
  }

  /* Welcome card compacting & Search layout */
  #dashboardWrapper .welcome-card {
    padding: 1.25rem !important;
  }
  
  #dashboardWrapper .welcome-card .greeting-text-container {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1.2rem !important;
  }

  #dashboardWrapper .welcome-card .greeting-title {
    font-size: 1.8rem !important;
    text-align: center;
  }

  #dashboardWrapper .welcome-card #greetingSubtitle {
    text-align: center;
    font-size: 0.85rem !important;
  }

  #dashboardWrapper .quick-search-wrapper {
    max-width: 100% !important;
  }

  #dashboardWrapper .quick-search-wrapper input {
    font-size: 1rem !important;
    padding: 0.85rem 1.4rem !important;
    min-height: 44px;
  }

  /* Days of Love Counter Card scaling */
  #dashboardWrapper .counter-display {
    gap: 0.5rem !important;
  }
  
  #dashboardWrapper .counter-unit {
    padding: 0.8rem 0.2rem !important;
  }
  
  #dashboardWrapper .counter-val {
    font-size: 1.8rem !important;
  }

  #dashboardWrapper .counter-lbl {
    font-size: 0.65rem !important;
  }

  /* Check-in Widget customization */
  #dashboardWrapper .checkin-card {
    padding: 1rem !important;
  }

  #dashboardWrapper .checkin-header-label {
    font-size: 0.8rem !important;
    margin-bottom: 0 !important;
  }

  #dashboardWrapper .checkin-circle {
    width: 68px !important;
    height: 68px !important;
    font-size: 1.5rem !important;
    margin: 10px auto !important;
  }

  #dashboardWrapper .checkin-hint {
    font-size: 0.75rem !important;
    margin-top: 5px !important;
    line-height: 1.25 !important;
  }

  #dashboardWrapper .checkin-time-text {
    font-size: 0.75rem !important;
  }

  /* Partner View Card customization */
  #dashboardWrapper #partnerStatusArea {
    gap: 0.5rem !important;
  }

  #dashboardWrapper .partner-info-row {
    font-size: 0.8rem !important;
    padding-bottom: 0.4rem !important;
  }
  
  #dashboardWrapper .partner-info-lbl {
    font-size: 0.8rem !important;
  }

  #dashboardWrapper .partner-dimmed-text {
    font-size: 0.8rem !important;
    margin: 1rem 0 !important;
  }

  /* Today's Mood Card Widget */
  #dashboardWrapper #moodQuestionLabel {
    font-size: 1.35rem !important;
    text-align: center;
  }
  
  #dashboardWrapper .mood-live-value {
    font-size: 3rem !important;
  }
  
  #dashboardWrapper #saveMoodBtn.mood-save-btn {
    padding: 0.75rem 2.2rem !important;
    font-size: 0.95rem !important;
    min-height: 44px;
    width: 100% !important;
    max-width: 180px !important;
  }

  /* Main App Launcher Navigation Grid */
  #dashboardWrapper .nav-menu-list {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.8rem !important;
  }

  #dashboardWrapper .nav-menu-item {
    padding: 1rem 0.5rem !important;
    gap: 0.5rem !important;
    border-radius: 16px !important;
  }

  #dashboardWrapper .nav-menu-item .nav-icon-wrapper {
    width: 44px !important;
    height: 44px !important;
  }
  
  #dashboardWrapper .nav-menu-item .nav-icon-wrapper svg {
    width: 20px !important;
    height: 20px !important;
  }

  #dashboardWrapper .nav-menu-item .nav-title {
    font-size: 0.95rem !important;
    font-weight: 600 !important;
  }

  #dashboardWrapper .nav-menu-item .nav-desc {
    display: none !important; /* Hide description to prevent text bloat on phone grids */
  }
}

/* --- Phone range grid adjustment --- */
@media (max-width: 600px) {
  #dashboardWrapper .nav-menu-list {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* --- Extremely small phones compatibility (< 360px) --- */
@media (max-width: 360px) {
  #dashboardWrapper .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
  
  #dashboardWrapper .dashboard-grid > section.checkin-card,
  #dashboardWrapper .dashboard-grid > section:nth-of-type(4) { 
    grid-column: span 2 !important;
  }
}

/* ==========================================================================
   8. Memories Page Specific Overrides (memories.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Compact memories header */
  .memories-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1rem !important;
    text-align: center;
    margin-bottom: 0.5rem;
  }

  .memories-header .page-title {
    font-size: 1.8rem !important;
  }

  .memories-header .add-memory-btn {
    width: 100% !important;
    padding: 0.8rem 1.5rem !important;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem !important;
  }

  /* Grid Layout: 2-column on tablets, 1-column on phones */
  .memories-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.2rem !important;
  }

  /* Memory Card Optimizations */
  .memory-card {
    border-radius: var(--mobile-border-radius) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
  }

  .memory-card:active {
    transform: scale(0.97) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
  }

  .memory-img-wrapper {
    height: 160px !important; /* Balanced for 2-columns on tablets */
  }

  .memory-details {
    padding: 1rem !important;
    gap: 0.4rem !important;
  }

  .memory-date {
    font-size: 0.8rem !important;
  }

  .memory-title {
    font-size: 1.05rem !important;
    line-height: 1.4 !important;
  }

  .memory-location {
    font-size: 0.8rem !important;
    margin-top: 0.3rem !important;
  }

  /* Modals Structure Overrides */
  .modal-overlay .modal-card {
    width: 95% !important;
    max-height: 92dvh !important;
    border-radius: var(--mobile-border-radius) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Forms & Body Scroller */
  .modal-body {
    padding: 1.25rem 1rem !important;
    gap: 1rem !important;
  }

  .form-group {
    gap: 0.3rem !important;
  }

  .form-label {
    font-size: 0.85rem !important;
  }

  .form-input {
    padding: 0.75rem 1rem !important;
    font-size: 0.95rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
  }

  /* Sticky Footer in Form modals */
  .modal-footer {
    padding: 0.8rem 1rem 1.2rem 1rem !important;
    background: rgba(13, 27, 42, 0.95) !important;
    border-top: 1px solid rgba(126, 200, 227, 0.1) !important;
  }

  .submit-form-btn {
    padding: 0.85rem !important;
    font-size: 1rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
    min-height: 44px;
  }

  /* Close button adjustments */
  .modal-close-btn {
    width: 36px !important;
    height: 36px !important;
    font-size: 1.1rem !important;
    top: 0.8rem !important;
    left: 0.8rem !important;
  }

  /* --------------------------------------------------------------------------
     Embedded Map Picker (Modal)
     -------------------------------------------------------------------------- */
  #mapSelectModalOverlay .modal-card {
    max-width: 95% !important;
    padding: 1.25rem !important;
    gap: 0.8rem !important;
  }

  #mapSelectModalOverlay h3 {
    font-size: 1.3rem !important;
    margin-bottom: 0.5rem !important;
  }

  /* Responsive map container inside picker */
  #mapSelectModalOverlay div[style*="height: 350px"] {
    height: 280px !important; /* Compact map on portrait mobile */
  }

  #mapSelectModalOverlay .filter-btn {
    padding: 0.3rem 0.6rem !important;
    font-size: 0.75rem !important;
    min-height: 32px !important;
  }

  /* Safe margins around the map to allow scroll escape */
  #pickerMap {
    border-radius: 8px !important;
  }
}

/* --- Phones Portrait range grid --- */
@media (max-width: 600px) {
  .memories-grid {
    grid-template-columns: 1fr !important; /* 1-column layout for detailed, premium photo album feel */
    gap: 1.5rem !important;
  }

  .memory-img-wrapper {
    height: 220px !important; /* Large, generous image sizing for photos */
  }

  .memory-title {
    font-size: 1.15rem !important;
  }
}

/* --- Mobile Landscape adaptations (low vertical space) --- */
@media (max-height: 520px) and (max-width: 900px) {
  /* Compact Modal general heights */
  .modal-overlay .modal-card {
    max-height: 94dvh !important;
  }

  .modal-header {
    padding: 0.5rem 1rem !important;
  }
  
  .form-title {
    font-size: 1.25rem !important;
    margin-bottom: 0 !important;
  }

  .modal-body {
    padding: 0.6rem 1rem !important;
    gap: 0.8rem !important;
  }

  .modal-footer {
    padding: 0.5rem 1rem !important;
  }

  .modal-close-btn {
    width: 32px !important;
    height: 32px !important;
    font-size: 1rem !important;
    top: 0.4rem !important;
    left: 0.4rem !important;
  }

  /* Compact View Full Memory Modal in Landscape */
  #viewModalOverlay .view-img {
    max-height: 110px !important; /* Avoid cutting off descriptive text */
  }

  #viewModalOverlay .view-content {
    padding: 0.8rem 1.2rem !important;
    gap: 0.4rem !important;
  }

  #viewModalOverlay .view-title {
    font-size: 1.3rem !important;
  }

  #viewModalOverlay .view-desc {
    max-height: 80px !important;
    font-size: 0.9rem !important;
    line-height: 1.4 !important;
  }

  #viewModalOverlay .view-actions {
    margin-top: 0.3rem !important;
    gap: 0.5rem !important;
  }

  #viewModalOverlay .view-actions button {
    padding: 0.4rem 1rem !important;
    min-height: 32px !important;
  }

  /* Map Picker modal landscape compacting */
  #mapSelectModalOverlay div[style*="height: 350px"],
  #mapSelectModalOverlay div[style*="height: 280px"] {
    height: 160px !important; /* Shrunk height in landscape to fit coordinate text and confirm btn */
  }

  #mapSelectModalOverlay h3 {
    font-size: 1.15rem !important;
  }

  #confirmCoordsBtn {
    margin-top: 0.5rem !important;
    padding: 0.5rem !important;
    min-height: 38px !important;
  }
}

/* ==========================================================================
   9. Map Page Specific Overrides (map.html)
   ========================================================================== */
/* Default styles for desktop (hidden) */
.mobile-map-tabs {
  display: none;
}

@media (max-width: 900px) {
  /* Compact Hero Section and margins */
  .hero-section {
    padding: 1.5rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 0.8rem !important;
  }

  .hero-title {
    font-size: 1.8rem !important;
  }

  .hero-subtitle {
    font-size: 0.95rem !important;
    line-height: 1.5 !important;
  }

  .journey-container {
    gap: 0.5rem !important;
  }

  .distance-text {
    font-size: 1.25rem !important;
  }

  .journey-btn {
    padding: 0.6rem 1.8rem !important;
    font-size: 0.95rem !important;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Compact Year Filters */
  .year-filters {
    gap: 0.4rem !important;
    margin-bottom: 0.5rem !important;
  }

  .year-filters .filter-btn {
    padding: 0.4rem 0.8rem !important;
    min-height: 38px !important;
    font-size: 0.85rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
  }

  /* --------------------------------------------------------------------------
     Mobile Tab Switcher Bar
     -------------------------------------------------------------------------- */
  .mobile-map-tabs {
    display: flex !important;
    background: rgba(30, 58, 95, 0.4) !important;
    border: 1px solid rgba(126, 200, 227, 0.15) !important;
    border-radius: 14px !important;
    padding: 0.3rem !important;
    gap: 0.4rem !important;
    width: 100% !important;
    margin-bottom: 0.8rem !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
  }

  .mobile-tab-btn {
    flex: 1 !important;
    background: transparent !important;
    border: 1px solid transparent !important;
    color: var(--text-muted) !important;
    padding: 0.6rem 1rem !important;
    border-radius: 10px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.5rem !important;
    min-height: 40px !important;
    font-family: var(--font-sans) !important;
    transition: all 0.3s var(--mobile-transition-easing) !important;
  }

  .mobile-tab-btn svg {
    transition: transform 0.3s ease !important;
  }

  .mobile-tab-btn.active {
    background: var(--primary-blue) !important;
    color: #0D1B2A !important;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.3) !important;
  }

  .mobile-tab-btn.active svg {
    transform: scale(1.1) !important;
  }

  /* --------------------------------------------------------------------------
     Dynamic Layout Switching (Map vs. List)
     -------------------------------------------------------------------------- */
  .map-grid {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
    margin-bottom: 1rem !important;
  }

  /* Show Map View active state */
  .map-grid.show-map-view .map-wrapper {
    display: block !important;
  }
  .map-grid.show-map-view .sidebar-panel {
    display: none !important;
  }

  /* Show Memories View active state */
  .map-grid.show-memories-view .map-wrapper {
    display: none !important;
  }
  .map-grid.show-memories-view .sidebar-panel {
    display: flex !important;
  }

  /* Map Panel sizing in Mobile mode */
  .map-wrapper {
    height: 55vh !important;
    min-height: 380px !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  /* Memories Sidebar Panel styling in Mobile mode */
  .sidebar-panel {
    width: 100% !important;
    height: 55vh !important;
    min-height: 380px !important;
    padding: 1.2rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  .sidebar-title {
    font-size: 1.35rem !important;
    margin-bottom: 0.5rem !important;
  }

  .sidebar-stats {
    font-size: 0.8rem !important;
    color: var(--accent) !important;
    padding-bottom: 0.5rem !important;
    border-bottom: 1px dashed rgba(126, 200, 227, 0.1) !important;
  }

  /* Large thumb-friendly memory cards list */
  .memory-list {
    gap: 0.75rem !important;
  }

  .memory-item {
    background: rgba(13, 27, 42, 0.6) !important;
    border: 1px solid rgba(126, 200, 227, 0.15) !important;
    border-radius: var(--mobile-border-radius-sm) !important;
    padding: 1rem !important;
    gap: 0.4rem !important;
    min-height: 64px !important;
    transition: transform 0.2s ease, border-color 0.2s ease !important;
  }

  .memory-item:active {
    transform: scale(0.98) !important;
    border-color: var(--accent) !important;
  }

  .item-loc {
    font-size: 0.8rem !important;
  }

  .item-title {
    font-size: 1rem !important;
    color: var(--text-color) !important;
  }

  .item-date {
    font-size: 0.75rem !important;
  }

  /* --------------------------------------------------------------------------
     Touch-friendly Leaflet Popup modifications
     -------------------------------------------------------------------------- */
  .leaflet-popup-content-wrapper {
    border-radius: 16px !important;
  }

  .leaflet-popup-content {
    width: 230px !important;
  }

  .popup-img {
    height: 100px !important;
  }

  .popup-body {
    padding: 0.8rem !important;
    gap: 0.4rem !important;
  }

  .popup-meta {
    font-size: 0.7rem !important;
  }

  .popup-title {
    font-size: 1rem !important;
  }

  .popup-desc {
    font-size: 0.8rem !important;
    line-height: 1.35 !important;
  }

  .popup-btn {
    padding: 0.6rem !important;
    font-size: 0.85rem !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 10px !important;
  }
}

/* --- Mobile Landscape adaptations (low vertical space) --- */
@media (max-height: 520px) and (max-width: 900px) {
  .hero-section {
    padding: 0.8rem 1rem !important;
  }

  .hero-title {
    font-size: 1.4rem !important;
  }

  .hero-subtitle {
    display: none !important; /* Hide subtitle to preserve landscape height */
  }

  .journey-container {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 1.5rem !important;
  }

  .distance-text {
    font-size: 1.15rem !important;
  }

  .journey-btn {
    padding: 0.4rem 1.2rem !important;
    min-height: 36px !important;
    font-size: 0.85rem !important;
  }

  /* Tab switcher height sizing */
  .mobile-map-tabs {
    margin-bottom: 0.5rem !important;
  }

  .mobile-tab-btn {
    min-height: 36px !important;
    padding: 0.4rem 1rem !important;
  }

  /* Compact grid panels in Landscape */
  .map-wrapper {
    height: 45vh !important;
    min-height: 200px !important;
  }

  .sidebar-panel {
    height: 45vh !important;
    min-height: 200px !important;
    padding: 0.8rem !important;
  }

  .sidebar-title {
    font-size: 1.15rem !important;
  }

  .sidebar-stats {
    padding-bottom: 0.3rem !important;
  }

  .memory-list {
    gap: 0.5rem !important;
  }

  .memory-item {
    padding: 0.6rem 0.8rem !important;
    min-height: 50px !important;
  }

  /* Landscape Popup tweaks */
  .popup-img {
    height: 70px !important;
  }
  .popup-body {
    padding: 0.5rem !important;
  }
  .popup-desc {
    -webkit-line-clamp: 1 !important; /* Shorter description in landscape map popup */
  }
  .popup-btn {
    min-height: 36px !important;
    padding: 0.4rem !important;
  }
}

/* ==========================================================================
   10. Novel Page Specific Overrides (novel.html)
   ========================================================================= */
@media (max-width: 900px) {
  /* Page Header compacting */
  .novel-header {
    margin-bottom: 0.5rem !important;
  }

  .novel-header h1 {
    font-size: 2rem !important;
  }

  .novel-header p {
    font-size: 0.9rem !important;
    line-height: 1.4 !important;
  }

  /* --------------------------------------------------------------------------
     Bookshelf & Episode Grid
     -------------------------------------------------------------------------- */
  .bookshelf-actions {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.8rem !important;
    text-align: center;
    margin-bottom: 1.5rem !important;
  }

  .bookshelf-actions h2 {
    font-size: 1.35rem !important;
  }

  #btnOpenStarredQuotes.btn-secondary {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px;
  }

  .bookshelf-grid {
    gap: 1.25rem !important;
  }

  .episode-card {
    padding: 1.25rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  .episode-badge {
    padding: 0.4rem 1.2rem !important;
    font-size: 0.75rem !important;
  }

  .episode-header {
    margin-top: 1rem !important;
    margin-bottom: 0.8rem !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.3rem !important;
  }

  .episode-title {
    font-size: 1.3rem !important;
  }

  .episode-meta {
    gap: 0.5rem !important;
  }

  .badge-mood {
    padding: 0.2rem 0.6rem !important;
    font-size: 0.75rem !important;
  }

  .badge-date {
    font-size: 0.75rem !important;
  }

  .episode-summary {
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
    margin-bottom: 1rem !important;
    padding-right: 0.6rem !important;
  }

  .scene-quick-list {
    padding: 0.8rem !important;
    margin-bottom: 1rem !important;
    gap: 0.4rem !important;
  }

  .scene-quick-item {
    font-size: 0.8rem !important;
  }

  .episode-action-row .btn-primary {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px;
    padding: 0.8rem !important;
    font-size: 0.95rem !important;
  }

  /* --------------------------------------------------------------------------
     Immersive Reader Mode (Medium / Apple Books style)
     -------------------------------------------------------------------------- */
  .reader-card {
    padding: 1rem 0.5rem !important;
    background: transparent !important; /* Full immersion: remove distracting panels */
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
  }

  .reader-toolbar {
    margin-bottom: 1.8rem !important;
    padding-bottom: 0.8rem !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1rem !important;
  }

  #btnBackToBookshelf.btn-secondary {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px;
  }

  .reader-episode-info {
    text-align: center !important;
  }

  .reader-episode-info div {
    justify-content: center !important;
  }

  .reader-episode-title {
    font-size: 1.6rem !important;
    text-align: center;
  }

  /* Scenes Container tuning */
  .reader-scenes-container {
    gap: 2rem !important;
  }

  .scene-card {
    gap: 1rem !important;
  }

  .scene-header-info {
    font-size: 0.8rem !important;
    padding-bottom: 0.4rem !important;
  }

  /* Reader Typography (prioritize comfort) */
  .scene-content {
    font-size: 1.2rem !important;
    line-height: 1.95 !important;
    padding: 0 0.4rem !important;
    text-align: justify !important;
    text-justify: inter-word !important;
  }

  /* Collectible Golden Quote blocks */
  .golden-quote-block {
    background: rgba(255, 215, 0, 0.04) !important;
    border-right: 3px solid #FFD700 !important;
    border-left: none !important;
    padding: 0.85rem 1.1rem !important;
    margin: 1.2rem 0.4rem !important;
    border-radius: 12px !important;
    gap: 0.8rem !important;
  }

  .quote-text {
    font-size: 1.05rem !important;
    line-height: 1.55 !important;
    color: #FFD700 !important;
  }

  .quote-author {
    font-size: 0.75rem !important;
  }

  .btn-star-quote {
    font-size: 1.6rem !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Unsent Letter Section */
  .unsent-letter-section {
    margin-top: 2.5rem !important;
    padding-top: 1.5rem !important;
  }

  .letter-toggle-btn {
    padding: 1rem !important;
    font-size: 0.95rem !important;
    min-height: 48px !important;
    border-radius: 12px !important;
  }

  .letter-body {
    padding: 1.25rem 1rem !important;
    margin-top: 1rem !important;
    border-radius: 12px !important;
  }

  .letter-disclaimer {
    padding: 0.5rem 0.8rem !important;
    font-size: 0.75rem !important;
    margin-bottom: 1rem !important;
    gap: 0.4rem !important;
  }

  .letter-content {
    font-size: 1.1rem !important;
    line-height: 1.85 !important;
  }

  .letter-signature {
    margin-top: 1rem !important;
    font-size: 0.85rem !important;
  }
}

/* --- Mobile Landscape overrides (low height, readable column width) --- */
@media (max-height: 520px) and (max-width: 900px) {
  /* Bookshelf view tweaks in Landscape */
  .bookshelf-actions {
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
  }

  #btnOpenStarredQuotes.btn-secondary {
    width: auto !important;
    min-height: 36px !important;
  }

  /* Reader view column centering for optimal line length */
  .reader-card {
    max-width: 580px !important; /* Kindle-like line width is easier to track in wide viewports */
    margin: 0 auto !important;
    padding: 0.5rem !important;
  }

  .reader-toolbar {
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 1.2rem !important;
  }

  #btnBackToBookshelf.btn-secondary {
    width: auto !important;
    min-height: 36px !important;
    padding: 0.4rem 1.2rem !important;
  }

  .reader-episode-info {
    text-align: right !important;
  }

  .reader-episode-info div {
    justify-content: flex-end !important;
  }

  .reader-episode-title {
    font-size: 1.4rem !important;
  }

  /* Compact text sizing in Landscape */
  .scene-content {
    font-size: 1.15rem !important;
    line-height: 1.85 !important;
  }

  .golden-quote-block {
    margin: 0.8rem 0.4rem !important;
    padding: 0.6rem 1rem !important;
  }

  .quote-text {
    font-size: 1rem !important;
  }

  .btn-star-quote {
    min-width: 36px !important;
    min-height: 36px !important;
  }
}

/* ==========================================================================
   11. AI Companion Page Specific Overrides (ask-archive.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Header Section */
  .header-section {
    padding: 1.25rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  .header-section h1 {
    font-size: 1.8rem !important;
  }

  .header-section p {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  /* Chat Search Composer Card */
  .search-card {
    padding: 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 1rem !important;
  }

  .search-input-wrapper {
    flex-direction: column !important;
    gap: 0.8rem !important;
  }

  .search-input {
    padding: 0.85rem 1.2rem !important;
    font-size: 1rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
    min-height: 48px !important;
    box-shadow: inset 0 1px 5px rgba(0,0,0,0.4) !important;
  }

  .magic-btn {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    justify-content: center !important;
    padding: 0.8rem !important;
    font-size: 1rem !important;
    min-height: 44px !important;
    border-radius: var(--mobile-border-radius-sm) !important;
    box-shadow: 0 4px 10px rgba(126, 200, 227, 0.25) !important;
  }

  /* Suggested Prompt chips horizontal carousel */
  .suggestion-tags {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    justify-content: flex-start !important;
    padding: 0.4rem 0.2rem !important;
    gap: 0.6rem !important;
    width: 100% !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .suggestion-tags::-webkit-scrollbar {
    display: none !important;
  }

  .suggestion-tag {
    flex-shrink: 0 !important;
    padding: 0.45rem 1.1rem !important;
    font-size: 0.85rem !important;
    border-radius: 20px !important;
  }

  /* Loader & Thinking status */
  .loader-container {
    padding: 3rem 1.5rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  #loadingText {
    font-size: 1rem !important;
    line-height: 1.45 !important;
    text-align: center;
  }

  /* Results and AI Answer formatting */
  .ai-answer-card {
    padding: 1.25rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 1.5rem !important;
  }

  .ai-header-badge {
    font-size: 0.8rem !important;
    padding: 0.3rem 1rem !important;
  }

  .ai-answer-text {
    font-size: 1.05rem !important;
    line-height: 1.7 !important;
    text-align: justify;
  }

  .dates-panel,
  .excerpts-panel {
    padding-top: 1.2rem !important;
  }

  .dates-title,
  .excerpts-title {
    font-size: 0.95rem !important;
  }

  .date-badge {
    padding: 0.35rem 0.8rem !important;
    font-size: 0.85rem !important;
    border-radius: 8px !important;
  }

  /* Chat Excperts bubble bounds */
  .excerpts-list {
    max-height: 400px !important;
  }

  .excerpt-bubble {
    max-width: 92% !important;
    padding: 0.8rem 1rem !important;
    border-radius: 16px !important;
  }

  .excerpt-bubble.sina {
    border-top-right-radius: 2px !important;
  }

  .excerpt-bubble.taqwa {
    border-top-left-radius: 2px !important;
  }

  .excerpt-sender {
    font-size: 0.75rem !important;
  }

  .excerpt-text {
    font-size: 0.95rem !important;
    line-height: 1.45 !important;
  }

  .excerpt-time {
    font-size: 0.7rem !important;
  }

  .refresh-btn {
    padding: 0.4rem 1rem !important;
    font-size: 0.85rem !important;
    min-height: 38px !important;
  }
}

/* --- Mobile Landscape overrides (low height, inline composer) --- */
@media (max-height: 520px) and (max-width: 900px) {
  .header-section {
    padding: 0.6rem 1rem !important;
  }

  .header-section h1 {
    font-size: 1.4rem !important;
  }

  .header-section p {
    display: none !important; /* Hide subtitle to preserve landscape space */
  }

  .search-card {
    padding: 0.75rem !important;
    gap: 0.5rem !important;
  }

  /* Inline horizontal search in landscape mode */
  .search-input-wrapper {
    flex-direction: row !important;
    gap: 0.5rem !important;
  }

  .search-input {
    flex-grow: 1 !important;
    padding: 0.5rem 1rem !important;
    min-height: 38px !important;
  }

  .magic-btn {
    width: auto !important;
    min-height: 38px !important;
    padding: 0.4rem 1.2rem !important;
  }

  .suggestion-tags {
    padding: 0.2rem !important;
  }

  .suggestion-tag {
    padding: 0.35rem 0.9rem !important;
    font-size: 0.8rem !important;
  }

  .loader-container {
    padding: 1.5rem !important;
  }
}

/* ==========================================================================
   11. Journal Page Specific Overrides (journal.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Header Section */
  .header-section {
    padding: 1.25rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  .header-section h1 {
    font-size: 1.8rem !important;
  }

  .header-section p {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  /* Tab Filter & Actions Container */
  .tab-container {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 1rem !important;
    gap: 1rem !important;
    border-radius: 16px !important;
  }

  .tabs-links {
    width: 100% !important;
    display: flex !important;
    gap: 0.4rem !important;
  }

  .tab-btn {
    flex: 1 !important;
    padding: 0.55rem 0.6rem !important;
    font-size: 0.85rem !important;
    text-align: center !important;
    min-height: 38px !important;
  }

  .action-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px !important;
    padding: 0.75rem !important;
    border-radius: 20px !important;
  }

  /* --------------------------------------------------------------------------
     Lined Paper Diary Card Mobile Scales
     -------------------------------------------------------------------------- */
  .journals-grid {
    gap: 1.5rem !important;
  }

  .diary-card {
    padding: 1.25rem !important;
    /* Scale down vintage binder stripe on phones to save space */
    border-left: 12px solid #8e44ad !important;
    border-radius: 12px !important;
    gap: 1.2rem !important;
  }

  .diary-card::before {
    left: -12px !important;
    width: 12px !important;
    border-top-left-radius: 12px !important;
    border-bottom-left-radius: 12px !important;
  }

  .diary-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.4rem !important;
    padding-bottom: 0.4rem !important;
  }

  .diary-meta-title {
    font-size: 1.25rem !important;
  }

  .diary-period-badge {
    font-size: 0.8rem !important;
    padding: 0.1rem 0.6rem !important;
  }

  .diary-mood-stamp {
    top: 10px !important;
    left: 10px !important;
    font-size: 1.35rem !important;
    padding: 0.15rem 0.5rem !important;
    border-width: 2px !important;
  }

  /* Intimate diary text reading comfort */
  .diary-summary {
    font-size: 1.05rem !important;
    line-height: 28px !important; /* Keep aligned to notepad lines background */
    color: var(--paper-text) !important;
  }

  .diary-section-title {
    font-size: 1rem !important;
    margin-top: 0.5rem !important;
  }

  .diary-highlights {
    padding-right: 1.25rem !important;
    gap: 0.4rem !important;
  }

  .diary-highlights li {
    font-size: 0.95rem !important;
    line-height: 28px !important; /* Keep aligned to notepad lines background */
  }

  /* Intimate Quote Bubble */
  .diary-quote-card {
    max-width: 95% !important;
    margin: 1rem 0 !important;
    padding: 0.5rem 1rem !important;
    font-size: 1rem !important;
    line-height: 1.6 !important;
  }

  .diary-footer {
    padding-top: 0.8rem !important;
  }

  .regenerate-action-btn {
    min-height: 38px !important;
    padding: 0.4rem 1rem !important;
    font-size: 0.8rem !important;
  }

  /* Loader styling */
  .loader-container {
    padding: 3rem 1.5rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }
}

/* --- Mobile Landscape overrides (low height, readable column width) --- */
@media (max-height: 520px) and (max-width: 900px) {
  /* Compact tab layout in Landscape */
  .tab-container {
    flex-direction: row !important;
    align-items: center !important;
    padding: 0.6rem 1.2rem !important;
  }

  .tabs-links {
    width: auto !important;
  }

  .tab-btn {
    min-height: 36px !important;
    padding: 0.4rem 1.2rem !important;
  }

  .action-btn {
    width: auto !important;
    min-height: 36px !important;
    padding: 0.4rem 1.5rem !important;
  }

  /* Diary card column centering for optimal line length */
  .diary-card {
    max-width: 600px !important; /* Kindle style: comfortable text columns in wide displays */
    margin: 0 auto !important;
    padding: 1.5rem !important;
  }

  .diary-mood-stamp {
    top: 15px !important;
    left: 15px !important;
    font-size: 1.5rem !important;
  }
}

/* ==========================================================================
   12. Search Page Specific Overrides (search.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Search Card Composer */
  .search-card {
    padding: 1.25rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 1rem !important;
  }

  .search-card h1 {
    font-size: 1.8rem !important;
  }

  .search-card p {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  .search-form {
    flex-direction: column !important;
    gap: 0.8rem !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-top: 0.2rem !important;
  }

  .search-input {
    padding: 0.85rem 1.2rem !important;
    font-size: 1rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
    min-height: 48px !important;
  }

  .search-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px !important;
    padding: 0.8rem !important;
    font-size: 1rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
  }

  /* Suggested queries horizontal chips list */
  .suggestions {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    justify-content: flex-start !important;
    padding: 0.4rem 0.2rem !important;
    gap: 0.5rem !important;
    width: 100% !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    margin-top: 0.2rem !important;
  }

  .suggestions::-webkit-scrollbar {
    display: none !important;
  }

  .suggestions span {
    display: none !important; /* Hide "suggested searches:" text on small screens to save space */
  }

  .suggestion-pill {
    flex-shrink: 0 !important;
    padding: 0.45rem 1rem !important;
    font-size: 0.85rem !important;
    border-radius: 20px !important;
  }

  /* --------------------------------------------------------------------------
     Results Category Panels & Cards
     -------------------------------------------------------------------------- */
  .results-container {
    gap: 1.5rem !important;
  }

  .category-section {
    padding: 1.25rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 1rem !important;
  }

  .category-title {
    font-size: 1.25rem !important;
    padding-bottom: 0.4rem !important;
  }

  .category-count {
    font-size: 0.75rem !important;
    padding: 0.15rem 0.6rem !important;
  }

  .results-list {
    gap: 0.8rem !important;
  }

  .result-item {
    padding: 1rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
    gap: 0.4rem !important;
    transition: transform 0.2s ease, border-color 0.2s ease !important;
  }

  /* Tactile feedback */
  .result-item:active {
    transform: scale(0.98) !important;
    border-color: var(--accent) !important;
  }

  .result-meta {
    font-size: 0.75rem !important;
  }

  .result-title {
    font-size: 1.05rem !important;
    line-height: 1.4 !important;
  }

  .result-snippet {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  .action-link-pill {
    padding: 0.25rem 0.7rem !important;
    font-size: 0.75rem !important;
  }

  /* Empty state */
  .results-container .empty-state {
    padding: 3rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    font-size: 1rem !important;
    line-height: 1.5 !important;
  }
}

/* --- Mobile Landscape overrides (low height, inline composer) --- */
@media (max-height: 520px) and (max-width: 900px) {
  .search-card {
    padding: 0.75rem !important;
    gap: 0.5rem !important;
  }

  .search-card h1 {
    font-size: 1.4rem !important;
  }

  .search-card p {
    display: none !important; /* Hide subtitle to preserve landscape space */
  }

  /* Inline horizontal search in landscape mode */
  .search-form {
    flex-direction: row !important;
    gap: 0.5rem !important;
  }

  .search-input {
    flex-grow: 1 !important;
    padding: 0.5rem 1rem !important;
    min-height: 38px !important;
  }

  .search-btn {
    width: auto !important;
    min-height: 38px !important;
    padding: 0.4rem 1.5rem !important;
  }

  .suggestions {
    padding: 0.2rem !important;
    margin-top: 0 !important;
  }

  .suggestion-pill {
    padding: 0.35rem 0.9rem !important;
    font-size: 0.8rem !important;
  }

  /* Search results centering in Landscape for optimal line lengths */
  .category-section {
    max-width: 600px !important; /* Raycast/Spotlight centered search results */
    margin: 0 auto !important;
    width: 100% !important;
  }
}

/* ==========================================================================
   13. Shared Goals Page Specific Overrides (goals.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Goals Page Header */
  .goals-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1.2rem !important;
    text-align: center;
  }

  .goals-header h1 {
    font-size: 1.8rem !important;
  }

  .goals-header p {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  .add-goal-btn {
    width: 100% !important;
    padding: 0.8rem 1.5rem !important;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem !important;
  }

  /* Segmented Category Toggles */
  .filters-row {
    display: flex !important;
    width: 100% !important;
    background: rgba(30, 58, 95, 0.4) !important;
    border: 1px solid rgba(126, 200, 227, 0.15) !important;
    border-radius: 14px !important;
    padding: 0.3rem !important;
    gap: 0.4rem !important;
    margin-bottom: 1.2rem !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
  }

  .filters-row .filter-btn {
    flex: 1 !important;
    padding: 0.5rem 0.2rem !important;
    font-size: 0.8rem !important;
    border-radius: 10px !important;
    min-height: 36px !important;
    text-align: center !important;
    border: none !important;
    background: transparent !important;
    color: var(--text-muted) !important;
    transition: all 0.3s ease !important;
  }

  .filters-row .filter-btn.active {
    background: var(--primary-blue) !important;
    color: #0D1B2A !important;
    box-shadow: 0 4px 10px rgba(74, 144, 217, 0.3) !important;
  }

  /* --------------------------------------------------------------------------
     Goals Cards Grid (1-column on phone, 2-column on tablet)
     -------------------------------------------------------------------------- */
  .goals-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.25rem !important;
  }

  .goal-card {
    padding: 1.2rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 0.8rem !important;
    transition: transform 0.2s ease, border-color 0.2s ease !important;
  }

  /* Tactile feedback */
  .goal-card:active {
    transform: scale(0.98) !important;
  }

  .goal-title {
    font-size: 1.15rem !important;
    line-height: 1.4 !important;
  }

  .goal-category {
    font-size: 0.75rem !important;
    padding: 0.2rem 0.5rem !important;
  }

  .goal-desc {
    font-size: 0.85rem !important;
    line-height: 1.4 !important;
  }

  .progress-meta {
    font-size: 0.8rem !important;
  }

  .status-badge {
    font-size: 0.75rem !important;
    padding: 0.2rem 0.75rem !important;
  }

  .goal-footer {
    font-size: 0.75rem !important;
    padding-top: 0.6rem !important;
  }

  .goal-actions button {
    padding: 0.4rem 0.8rem !important;
    min-height: 34px !important;
    font-size: 0.75rem !important;
  }

  /* Empty state */
  .goals-grid .empty-state {
    padding: 3rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    font-size: 1rem !important;
    line-height: 1.5 !important;
  }

  /* --------------------------------------------------------------------------
     Touch-friendly progress slider (in Form Modal)
     -------------------------------------------------------------------------- */
  .progress-slider {
    height: 12px !important; /* Thicker track to touch easily */
  }

  .progress-slider::-webkit-slider-thumb {
    width: 26px !important; /* Larger thumb */
    height: 26px !important;
    box-shadow: 0 0 12px var(--accent) !important;
  }
}

/* --- Phones Portrait range grid --- */
@media (max-width: 600px) {
  .goals-grid {
    grid-template-columns: 1fr !important; /* 1-column layout for details reading */
    gap: 1.2rem !important;
  }
}

/* --- Mobile Landscape overrides (low height, readable column width) --- */
@media (max-height: 520px) and (max-width: 900px) {
  /* Compact headers and actions in Landscape */
  .goals-header {
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
  }

  .add-goal-btn {
    width: auto !important;
    min-height: 36px !important;
    padding: 0.4rem 1.2rem !important;
  }

  .filters-row {
    margin-bottom: 0.8rem !important;
  }

  .filters-row .filter-btn {
    min-height: 32px !important;
    padding: 0.3rem 1rem !important;
  }

  /* Centered goals list in Landscape for comfortable reading columns */
  .goal-card {
    max-width: 580px !important;
    margin: 0 auto !important;
    width: 100% !important;
  }
}

/* ==========================================================================
   14. Statistics Page Specific Overrides (statistics.html)
   ========================================================================== */
@media (max-width: 900px) {
  /* Hero Section compacting */
  .hero-section {
    padding: 1.5rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  .hero-section h1 {
    font-size: 1.8rem !important;
  }

  .hero-section p {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  /* Segmented Platform Selector Toggles */
  #tabAll, #tabWhatsapp, #tabInstagram {
    flex: 1 !important;
    text-align: center !important;
    padding: 0.55rem 0.5rem !important;
    font-size: 0.85rem !important;
    min-height: 38px !important;
    min-width: 70px !important;
    border-radius: 10px !important;
  }

  #btnRefresh {
    width: 100% !important;
    margin-right: 0 !important;
    margin-top: 0.6rem !important;
    justify-content: center !important;
    min-height: 44px !important;
    display: inline-flex;
    align-items: center;
    border-radius: 12px !important;
  }

  /* Compact Platform summary cards */
  .panel-card {
    padding: 1.25rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
    gap: 1rem !important;
  }

  .panel-title {
    font-size: 1.2rem !important;
    padding-bottom: 0.4rem !important;
  }

  /* --------------------------------------------------------------------------
     KPI Summary Grid (2-columns on phone)
     -------------------------------------------------------------------------- */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1rem !important;
  }

  .stat-card {
    padding: 1rem !important;
    border-radius: var(--mobile-border-radius-sm) !important;
  }

  /* Active press feedback */
  .stat-card:active {
    transform: scale(0.97) !important;
  }

  .stat-icon {
    font-size: 1.6rem !important;
  }

  .stat-label {
    font-size: 0.8rem !important;
  }

  .stat-val {
    font-size: 1.7rem !important;
  }

  #statFirstDate,
  #statActiveMonth,
  #statActiveDay {
    font-size: 1.2rem !important;
    padding: 0.2rem 0 !important;
  }

  /* Frequency Progress bars */
  .freq-item {
    gap: 0.2rem !important;
  }

  .freq-header {
    font-size: 0.85rem !important;
  }

  .freq-bar-bg {
    height: 6px !important;
  }

  /* Chart Cards & Containers */
  .charts-grid {
    gap: 1.25rem !important;
  }

  .chart-card {
    padding: 1.25rem 1rem !important;
    border-radius: var(--mobile-border-radius) !important;
  }

  .chart-card h3 {
    font-size: 1.1rem !important;
    text-align: center;
  }

  /* Lock height of chart canvas to prevent overflow */
  .chart-container {
    height: 220px !important;
  }
}

/* --- Mobile Landscape overrides (low height, readable width columns) --- */
@media (max-height: 520px) and (max-width: 900px) {
  /* Platform toggles horizontal fit */
  #btnRefresh {
    width: auto !important;
    margin-top: 0 !important;
    margin-right: auto !important;
    min-height: 36px !important;
    padding: 0.4rem 1.2rem !important;
  }

  /* Dashboard Panel column centering */
  .panel-card,
  .chart-card {
    max-width: 600px !important;
    margin: 0 auto !important;
    width: 100% !important;
  }
}

/* ==========================================================================
   15. Remaining Subpages & Global Design system Unification Overrides
   ========================================================================== */
@media (max-width: 900px) {
  /* --------------------------------------------------------------------------
     A. Global Card, Button & Input Design Unification
     -------------------------------------------------------------------------- */
  .dashboard-card,
  .welcome-card,
  .search-card,
  .ai-answer-card,
  .form-container,
  .setup-card,
  .panel-card,
  .chart-card,
  .episode-card,
  .result-item,
  .stat-card,
  .goal-card,
  .diary-card,
  .timeline-card,
  .memory-card,
  .letter-card,
  .envelope-box,
  .import-card,
  .platform-option,
  .custom-upload-box {
    border-radius: var(--mobile-border-radius) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25) !important;
    padding: var(--mobile-padding-card) !important;
  }

  /* Universal active state touch feedback on all clickable blocks */
  .result-item:active,
  .stat-card:active,
  .goal-card:active,
  .diary-card:active,
  .timeline-card:active,
  .memory-card:active,
  .platform-option:active,
  .custom-upload-box:active,
  .episode-card:active {
    transform: scale(0.97) !important;
    transition: transform 0.15s ease !important;
  }

  /* Unify button height and safe targets */
  .action-btn,
  .add-goal-btn,
  .submit-form-btn,
  .search-btn,
  .magic-btn,
  .btn-submit,
  .logout-btn {
    min-height: 44px !important;
    border-radius: 30px !important;
  }

  /* --------------------------------------------------------------------------
     B. Page Specific: On This Day (this-day.html)
     -------------------------------------------------------------------------- */
  .timeline-dot {
    width: 44px !important;
    height: 44px !important;
    font-size: 0.9rem !important;
    border-width: 2px !important;
    box-shadow: 0 0 10px rgba(126, 200, 227, 0.3) !important;
  }

  .timeline-item {
    gap: 0.8rem !important;
  }

  .timeline-container::before {
    right: 22px !important; /* Align line center behind 44px dot */
  }

  .today-date-badge {
    font-size: 0.9rem !important;
    padding: 0.4rem 1.2rem !important;
  }

  /* --------------------------------------------------------------------------
     C. Page Specific: Daily Message (message.html)
     -------------------------------------------------------------------------- */
  .letter-title {
    font-size: 1.8rem !important;
  }

  .message-text {
    font-size: 1.12rem !important;
    line-height: 1.8rem !important;
  }

  .message-textarea {
    min-height: 100px !important;
    font-size: 0.95rem !important;
  }

  /* --------------------------------------------------------------------------
     D. Page Specific: Relationship Timeline (timeline.html)
     -------------------------------------------------------------------------- */
  /* Shift vertical timeline line to the side on phone */
  @media (max-width: 768px) {
    .timeline::after {
      left: 20px !important;
    }
    .timeline-container {
      width: 100% !important;
      padding-left: 45px !important;
      padding-right: 10px !important;
      left: 0 !important;
    }
    .timeline-container::after {
      left: 11px !important;
      right: auto !important;
    }
  }

  /* --------------------------------------------------------------------------
     E. Page Specific: Data Importer (import.html)
     -------------------------------------------------------------------------- */
  .platform-icon {
    font-size: 2.8rem !important;
  }

  .platform-name {
    font-size: 1.2rem !important;
  }

  .custom-upload-box {
    padding: 2rem 1rem !important;
  }

  .custom-upload-icon {
    font-size: 2.4rem !important;
  }
}

/* ==========================================================================
   16. Premium Polish System Rules (Toasts, Skeletons, reading progress, orbit spin)
   ========================================================================== */

/* --- A. Global Toast Notification System Styles --- */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100030;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 90%;
  max-width: 380px;
  pointer-events: none;
}

.toast-item {
  background: rgba(13, 27, 42, 0.85);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid rgba(126, 200, 227, 0.25);
  border-radius: 30px;
  padding: 0.75rem 1.5rem;
  color: var(--text-color);
  font-family: 'Cairo', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.25);
  pointer-events: auto;
  direction: rtl;
  text-align: right;
}

.toast-item.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  border-color: rgba(46, 204, 113, 0.45) !important;
  box-shadow: 0 10px 25px rgba(46, 204, 113, 0.15), 0 0 12px rgba(46, 204, 113, 0.1) !important;
}

.toast-error {
  border-color: rgba(231, 76, 60, 0.45) !important;
  box-shadow: 0 10px 25px rgba(231, 76, 60, 0.15), 0 0 12px rgba(231, 76, 60, 0.1) !important;
}

.toast-heart {
  border-color: rgba(74, 144, 217, 0.45) !important;
  box-shadow: 0 10px 25px rgba(74, 144, 217, 0.15), 0 0 12px rgba(74, 144, 217, 0.1) !important;
}

/* --- B. Reading Scroll Progress Bar --- */
.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-blue), var(--accent));
  z-index: 100020;
  width: 0%;
  transition: width 0.1s ease;
}

/* --- C. Shimmer Loading Skeletons --- */
.skeleton-glow {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.12) 37%, rgba(255, 255, 255, 0.05) 63%) !important;
  background-size: 400% 100% !important;
  animation: skeleton-shimmer 1.4s ease infinite !important;
  border-radius: 12px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* --- D. Premium Orbit Spinners --- */
.spinner {
  border: 3px solid rgba(126, 200, 227, 0.1) !important;
  border-left-color: var(--accent) !important;
  border-top-color: var(--primary-blue) !important;
  width: 50px !important;
  height: 50px !important;
  border-radius: 50% !important;
  animation: premium-spin 1s cubic-bezier(0.5, 0, 0.5, 1) infinite !important;
  box-shadow: 0 0 15px rgba(126, 200, 227, 0.25) !important;
  background: transparent !important;
  margin: 3rem auto !important;
}

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

/* --- E. Glassmorphic Modal Opening Scale Animation --- */
.modal-overlay {
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
  transition: opacity 0.3s ease !important;
}

.modal-card {
  transform: scale(0.9) translateY(20px) !important;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease !important;
}

.modal-overlay.show .modal-card {
  transform: scale(1) translateY(0) !important;
}











