/* =======================================================
   MOTCHILL RESPONSIVE V2 (Homepage-first, Mobile-first)
   Scope: Header + Homepage layout only
   Notes: Desktop base stays in motchill-optimized.css
======================================================= */

/* ------------------------------
   CSS Variables (safe defaults)
------------------------------ */
:root {
  --gap-xxs: 6px;
  --gap-xs: 8px;
  --gap-sm: 10px;
  --gap-md: 14px;
  --gap-lg: 20px;
  --header-height: 60px;
  --icon-size: clamp(36px, 10vw, 44px);
}

/* ------------------------------
   MOBILE (default ≤ 767px)
   Mobile-first styles
------------------------------ */
html, body {
  overflow-x: hidden;
}

/* Strong mobile header override to avoid desktop conflicts (flex version) */
@media (max-width: 767px) {
  body .motchill-top-bar { 
    display: flex !important; 
    align-items: center; 
    justify-content: space-between;
    position: relative;
    padding-left: 8px; /* tighten left padding to move hamburger further left */
  }
  body .motchill-top-bar > * { min-width: 0; }
  body .motchill-top-bar .mobile-buttons { 
    order: 1; 
    margin: 0 !important; 
    flex: 0 0 auto;
    position: relative;
    left: 0;
    margin-left: -4px; /* subtle nudge to the far left */
  }
  body .motchill-top-bar .motchill-logo { 
    order: 2; 
    margin: 0 !important; 
    flex: 1 1 auto; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
  }
  body .motchill-top-bar .motchill-logo a { display: inline-flex; align-items: center; justify-content: center; }
  body .motchill-top-bar .motchill-logo img { max-height: 34px; height: 34px; width: auto; }
  body .motchill-top-bar .mobile-search-button { 
    order: 3; 
    margin: 0 !important; 
    flex: 0 0 auto;
    position: relative;
    right: 0;
  }
}

/* Header layout (mobile/tablet): flex – left fixed, center fluid, right fixed */
.motchill-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  min-height: var(--header-height);
  padding: 10px 12px;
  position: relative;
  z-index: 1001;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Left: hamburger container */
.mobile-buttons { 
  display: flex; 
  align-items: center; 
  flex: 0 0 var(--icon-size); 
  position: relative;
}
.mobile-hamburger {
  width: var(--icon-size); 
  height: var(--icon-size);
  display: flex; 
  align-items: center; 
  justify-content: center;
  background: rgba(255,255,255,0.1); 
  border: 1px solid rgba(255,255,255,0.2); 
  color: #fff; 
  font-size: 16px;
  border-radius: 8px; 
  cursor: pointer; 
  transition: all 0.3s ease;
  position: relative;
  z-index: 10;
}
.mobile-hamburger:hover { 
  background: rgba(221,0,63,0.8); 
  border-color: #DD003F;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(221,0,63,0.3);
}
.mobile-hamburger:active {
  transform: scale(0.95);
}

/* Center: logo */
.motchill-logo { flex: 1 1 auto; display: flex; justify-content: center; align-items: center; text-align: center; min-width: 0; }

/* Right: search button (only icon on mobile) */
.mobile-search-button { 
  display: flex; 
  align-items: center; 
  justify-content: flex-end; 
  flex: 0 0 var(--icon-size); 
  position: relative;
}
.mobile-search {
  width: var(--icon-size); 
  height: var(--icon-size);
  display: flex; 
  align-items: center; 
  justify-content: center;
  background: rgba(255,255,255,0.1); 
  border: 1px solid rgba(255,255,255,0.2); 
  color: #fff; 
  font-size: 16px;
  border-radius: 8px; 
  cursor: pointer; 
  transition: all 0.3s ease;
  position: relative;
  z-index: 10;
}
.mobile-search:hover { 
  background: rgba(221,0,63,0.8); 
  border-color: #DD003F;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(221,0,63,0.3);
}
.mobile-search:active {
  transform: scale(0.95);
}

/* Hide desktop-only header blocks on mobile */
@media (max-width: 767px) {
  .motchill-search-section, .motchill-user-actions, .motchill-nav { display: none !important; }
  /* Hide mobile nav by default; it will show inside sidebar */
  .mobile-nav { display: none !important; }
  .mobile-sidebar .mobile-nav { display: block !important; }
  
  /* Force show mobile search container on mobile */
  .mobile-search-container { 
    display: block !important; 
    visibility: visible !important;
    opacity: 1 !important;
  }
}

/* Mobile search dropdown */
.mobile-search-container { 
  position: relative; 
  z-index: 2000;
  display: block !important; /* Force show on mobile */
}
.mobile-search-dropdown { 
  position: fixed; 
  left: 12px; 
  right: 12px; 
  top: 70px; 
  z-index: 2000; 
  display: none; 
  visibility: hidden;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  background: rgba(26,26,26,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(221,0,63,0.3);
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.mobile-search-dropdown.active { 
  display: block !important; 
  visibility: visible !important;
  opacity: 1 !important;
  transform: translateY(0);
}
.mobile-search-input { 
  width: 100%; 
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 12px 16px;
  color: #fff;
  font-size: 16px;
  transition: all 0.3s ease;
}
.mobile-search-input:focus {
  outline: none;
  border-color: #DD003F;
  background: rgba(255,255,255,0.15);
  box-shadow: 0 0 0 2px rgba(221,0,63,0.2);
}
.mobile-search-input::placeholder {
  color: rgba(255,255,255,0.6);
}

/* Mobile search form styling */
.mobile-search-form {
  position: relative;
}
.mobile-search-input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}
.mobile-search-submit {
  background: #DD003F;
  border: none;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 16px;
  min-width: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-search-submit:hover {
  background: #b80035;
  transform: scale(1.05);
}
.mobile-search-submit:active {
  transform: scale(0.95);
}
.mobile-search-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.3s ease;
  z-index: 10;
  opacity: 0.8;
}
.mobile-search-close:hover {
  background: rgba(221,0,63,0.8);
  border-color: #DD003F;
  opacity: 1;
}

/* Mobile sidebar and overlay styles */
@media (max-width: 767px) {
  .mobile-sidebar { 
    position: fixed; 
    left: 0; 
    top: 0; 
    bottom: 0; 
    width: 280px; 
    background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
    border-right: 2px solid #DD003F;
    transform: translateX(-100%); 
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); 
    z-index: 1900; 
    overflow-y: auto; 
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .mobile-sidebar.active { 
    transform: translateX(0); 
  }
  .mobile-overlay { 
    position: fixed; 
    left: 0; 
    top: 0; 
    right: 0; 
    bottom: 0; 
    background: rgba(0,0,0,0.7); 
    display: none; 
    z-index: 1850; 
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
  }
  .mobile-overlay.active { 
    display: block; 
    opacity: 1;
  }
  
  /* Mobile menu items styling */
  .mobile-menu-header {
    padding: 20px;
    border-bottom: 1px solid rgba(221,0,63,0.3);
    background: rgba(221,0,63,0.1);
  }
  .mobile-menu-title {
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    margin: 0;
    text-align: center;
  }
  .mobile-menu-item {
    display: block;
    padding: 15px 20px;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s ease;
    font-size: 16px;
  }
  .mobile-menu-item:hover {
    background: rgba(221,0,63,0.2);
    color: #DD003F;
    padding-left: 30px;
  }
  .mobile-submenu {
    display: none;
    background: rgba(0,0,0,0.3);
  }
  .mobile-submenu.active {
    display: block;
  }
  .mobile-submenu-item {
    display: block;
    padding: 12px 40px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: all 0.3s ease;
    font-size: 14px;
  }
  .mobile-submenu-item:hover {
    background: rgba(221,0,63,0.15);
    color: #fff;
    padding-left: 50px;
  }
}

/* Homepage grid: 2 cols on mobile */
/* Flex-based layout: Mobile 2 items/row (50%) */
.homepage-main .list-films,
.homepage-layout .homepage-main .list-films,
body .homepage-main .list-films { display: flex; flex-wrap: wrap; gap: var(--gap-sm); }
/* Mobile: 2 items – neutralize legacy layout and enforce 2 columns */
.homepage-main .list-films .item,
.homepage-layout .homepage-main .list-films .item,
body .homepage-main .list-films .item {
  box-sizing: border-box;
  float: none;
  width: auto;
  flex: 0 0 calc(50% - var(--gap-sm));
  max-width: calc(50% - var(--gap-sm));
}
.list-films .item,
.list-films .item a,
.list-films .item .inner,
.list-films .item .poster { width: 100%; max-width: 100%; display: block; }
.list-films .item img { width: 100%; height: 180px; object-fit: cover; display: block; }

/* Section spacing */
.homepage-layout { display: block; padding: var(--gap-sm); }
.homepage-section { margin-bottom: var(--gap-md); padding: 15px !important; }

/* Sidebar full-width under main on small screens */
.homepage-main, .homepage-sidebar { width: 100%; max-width: 100%; }

/* Make homepage items stretch full width of .homepage-section */
.homepage-section .list-films { width: 100%; }
.homepage-section .list-films .item { margin-left: 0; margin-right: 0; }

/* ------------------------------
   PHABLET (550px – 767px): 3 items/row
------------------------------ */
@media (min-width: 550px) and (max-width: 767px) {
  .homepage-main .list-films { gap: var(--gap-md) !important; }
  .homepage-main .list-films .item { float: none !important; width: auto !important; flex: 0 0 calc(33.333% - var(--gap-md)) !important; max-width: calc(33.333% - var(--gap-md)) !important; }
}

/* ------------------------------
   TABLET (768px – 1023px): 4 items/row, full-width layout
------------------------------ */
@media (min-width: 768px) and (max-width: 1023px) {
  .motchill-top-bar { grid-template-columns: var(--icon-size) 1fr var(--icon-size); padding: 12px 20px; }

  /* 4 items per row on tablet */
  .homepage-main .list-films { gap: var(--gap-lg); }
  .homepage-main .list-films .item { float: none; width: auto; flex: 0 0 calc(25% - var(--gap-lg)); max-width: calc(25% - var(--gap-lg)); }

  /* Keep main + sidebar stacked on tablet */
  .homepage-layout { display: block; }
  .homepage-main, .homepage-sidebar { flex: none; width: 100%; max-width: 100%; }
}

/* (Removed tablet breakpoint to keep file lean and focused on Mobile + Desktop) */

/* ------------------------------
   DESKTOP (≥ 1024px)
------------------------------ */
@media (min-width: 1024px) {
  /* Desktop header pieces are primarily in motchill-optimized.css */
  .mobile-buttons, .mobile-search-button, .mobile-search-container, .mobile-nav { display: none; }
  .motchill-search-section, .motchill-nav { display: block; }

  /* Homepage layout: 70/30 split */
  .homepage-layout { display: flex; gap: var(--gap-lg); align-items: flex-start; }
  .homepage-main { flex: 0 0 70%; max-width: 70%; }
  .homepage-sidebar { flex: 0 0 30%; max-width: 30%; }

  /* Desktop 4 items/row (25%) */
  .homepage-main .list-films { gap: var(--gap-lg); }
  /* Desktop: 4 items */
  .homepage-main .list-films .item { flex: 0 0 calc(25% - var(--gap-lg)); max-width: calc(25% - var(--gap-lg)); }
  .list-films .item img { height: 240px; }
}

/* ------------------------------
   Utilities
------------------------------ */
/* Utility visibility helpers (kept minimal) */
.mobile-only { display: block; }
@media (min-width: 1024px) { .mobile-only { display: none; } }
.desktop-only { display: none; }
@media (min-width: 1024px) { .desktop-only { display: block; } }


/* ------------------------------
   Mobile Enforcement Override (last win)
------------------------------ */
@media (max-width: 549px) {
  body .homepage-main .list-films { display: flex; flex-wrap: wrap; gap: var(--gap-sm); }
  body .homepage-main .list-films > .item {
    float: none;
    width: auto;
    flex: 0 0 calc(50% - var(--gap-sm));
    max-width: calc(50% - var(--gap-sm));
  }
  /* Footer overflow fix */
  #footer, .footer, .phimus-footer { overflow: hidden; }
  #footer img, #footer iframe, .footer img, .footer iframe, .phimus-footer img, .phimus-footer iframe { max-width: 100%; height: auto; }
  #footer .footer-content { display: flex; flex-direction: column; gap: var(--gap-sm); }
}

/* ------------------------------
   Homepage-only header fixes (do not affect other pages)
------------------------------ */
@media (max-width: 767px) {
  /* Restore original home header width */
  body.home .motchill-top-bar { display: flex !important; justify-content: space-between; align-items: center; width: 33% !important; box-sizing: border-box; }
  body.home .motchill-top-bar .mobile-buttons { display: flex !important; justify-self: start; }
  body.home .motchill-top-bar .motchill-logo { display: flex !important; justify-self: center; margin: 0 !important; }
  body.home .motchill-top-bar .mobile-search-button { display: flex !important; justify-self: end; }
  body.home .motchill-search-section, body.home .motchill-user-actions, body.home .motchill-nav { display: none !important; }
  body.home .mobile-nav { display: block !important; }
}
