/**
 * Frontend Mobile-First Styles
 * Gonzaga's Art & Shine - Site público
 * Base: mobile, enhance: tablet/desktop
 */

/* ===== MOBILE BASE (default) ===== */
:root {
  --touch-min: 44px;
  --spacing-mobile: 1rem;
  --spacing-section: 2rem;
}

/* Prevent horizontal overflow */
html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

/* Fluid typography - mobile first */
h1 {
  font-size: clamp(1.75rem, 5vw, 3rem);
  line-height: 1.2;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
}

h3 {
  font-size: clamp(1.25rem, 3vw, 2rem);
}

/* Touch targets - mínimo 44px para botões e controlos */
button, input[type="submit"], input[type="button"], .btn, .filter-toggle-btn {
  min-height: var(--touch-min);
}

.mobile-nav-link {
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
}

.filter-checkbox, .filter-radio {
  min-width: 22px;
  min-height: 22px;
}

/* Container com padding seguro (notch) */
.container, .main-content, .catalog-container {
  padding-left: max(var(--spacing-mobile), env(safe-area-inset-left));
  padding-right: max(var(--spacing-mobile), env(safe-area-inset-right));
}

/* ===== MOBILE NAV (drawer) ===== */
@media (max-width: 768px) {
  .mobile-nav, .mobile-nav-content {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .mobile-nav-header {
    padding-left: max(1rem, env(safe-area-inset-left));
  }

  .mobile-nav-links {
    padding-left: max(0.5rem, env(safe-area-inset-left));
  }
}

/* ===== HEADER MOBILE ===== */
@media (max-width: 768px) {
  .header-container {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .logo h1 {
    font-size: 1.25rem;
  }

  /* Search wrapper: icon + expandable bar */
  .header-search-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
  }

  /* Search icon button - visible by default */
  .mobile-search-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0.75rem;
    background: none;
    border: none;
    color: #c0a080;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
  }

  .mobile-search-toggle:hover {
    background: rgba(192, 160, 128, 0.1);
  }

  .mobile-search-toggle[aria-expanded="true"] {
    display: none !important;
  }

  /* Search bar - collapsed by default on mobile */
  .header-search {
    display: none;
    flex: 1;
    min-width: 0;
    align-items: center;
    gap: 0.5rem;
    position: relative;
  }

  .header-search.expanded {
    display: flex !important;
    flex: 1 1 auto;
    min-width: 0;
    animation: search-expand 0.25s ease-out;
  }

  .header-search.expanded .search-container {
    flex: 1;
    min-width: 0;
  }

  .header-search.expanded .search-input {
    width: 100%;
  }

  @keyframes search-expand {
    from { opacity: 0; max-width: 0; }
    to { opacity: 1; max-width: 100%; }
  }

  .header-search .search-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
    padding-right: 2.5rem;
  }

  .mobile-search-close {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: none;
    border: none;
    color: #c0a080;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 6px;
    flex-shrink: 0;
  }

  .mobile-search-close:hover {
    background: rgba(192, 160, 128, 0.15);
  }

  .mobile-nav-toggle {
    min-width: 44px;
    min-height: 44px;
    padding: 0.75rem;
    flex-shrink: 0;
  }
}

/* Desktop: mesmo padrão mobile - ícone que expande ao clicar */
@media (min-width: 769px) {
  .header-search-wrapper {
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  /* Ícone de pesquisa visível (como no mobile) */
  .mobile-search-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    padding: 0.5rem;
    background: none;
    border: none;
    color: #c0a080;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
  }

  .mobile-search-toggle:hover {
    background: rgba(192, 160, 128, 0.1);
  }

  .mobile-search-toggle[aria-expanded="true"] {
    display: none !important;
  }

  /* Barra colapsada por defeito, expande ao clicar */
  .header-search {
    display: none;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    max-width: 320px;
    min-width: 200px;
  }

  .header-search.expanded {
    display: flex !important;
    animation: search-expand 0.25s ease-out;
  }

  .header-search .search-container {
    flex: 1;
    min-width: 0;
  }

  .header-search .search-input {
    width: 100%;
    min-height: 36px;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    font-size: 0.95rem;
    box-sizing: border-box;
  }

  .mobile-search-close {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    color: #c0a080;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 6px;
  }

  .mobile-search-close:hover {
    background: rgba(192, 160, 128, 0.15);
  }
}

/* ===== HERO MOBILE ===== */
@media (max-width: 768px) {
  .hero {
    height: 55vh;
    min-height: 260px;
    padding: 0;
  }

  .hero .hero-content {
    padding: max(1rem, env(safe-area-inset-top)) 0.75rem 0;
  }

  .hero-tagline {
    font-size: clamp(0.9rem, 4.5vw, 1.15rem);
    padding: 0.5rem 1rem;
  }
}

@media (max-width: 480px) {
  .hero {
    height: 50vh;
    min-height: 220px;
  }
}

/* ===== CATALOG MOBILE ===== */
@media (max-width: 768px) {
  .catalog-main {
    padding: 0;
    overflow-x: hidden;
  }

  .catalog-container {
    padding: 1rem 0.75rem;
  }

  .catalog-header {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
    margin-bottom: 1.5rem;
  }

  .header-left {
    text-align: center;
  }

  .page-title {
    font-size: 1.5rem;
  }

  .page-subtitle {
    font-size: 0.9rem;
  }

  .header-right {
    flex-direction: column;
    gap: 0.75rem;
  }

  .filter-toggle-btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    min-height: 48px;
  }

  .results-count {
    justify-content: center;
  }

  /* Catalog controls - sort & view toggle */
  .catalog-controls {
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .catalog-controls-left {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .catalog-controls-left label {
    width: 100%;
    font-size: 0.9rem;
  }

  .sort-select {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
  }

  .view-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Sidebar drawer - mobile: scroll só no conteúdo (árvore de famílias tocável) */
  .catalog-sidebar.filter-drawer {
    width: 100%;
    max-width: 100%;
    top: 0;
    height: 100vh;
    max-height: 100vh;
    padding: 0;
    padding-top: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
  }

  .catalog-sidebar.filter-drawer .sidebar-header {
    flex-shrink: 0;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .catalog-sidebar.filter-drawer .sidebar-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 1rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }

  .sidebar-close {
    min-width: 44px;
    min-height: 44px;
  }

  .filter-option {
    padding: 0.25rem 0;
  }

  .family-tree-toggle {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    touch-action: manipulation;
  }

  .family-tree-row {
    align-items: center;
  }

  .family-tree-label {
    touch-action: manipulation;
  }

  .family-tree-toggle-spacer {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .family-tree-bulk-btn {
    min-height: 44px;
    padding: 0.5rem 0.85rem;
    font-size: 0.7rem;
  }

  .family-tree-toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .filter-label {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .catalog-chips {
    line-height: 1.5;
  }

  .catalog-chip-remove {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-filter-apply, .btn-filter-clear {
    min-height: 48px;
    padding: 0.75rem 1rem;
  }

  /* Product grid - 2 cols on mobile */
  .products-grid.grid-view,
  .catalog-grid.grid-view {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .product-item {
    min-width: 0;
  }

  .product-card {
    min-width: 0;
    overflow: hidden;
  }

  .product-info {
    padding: 0.75rem;
  }

  .product-reference, .product-family {
    font-size: 0.75rem;
  }

  .product-price {
    font-size: 1rem;
  }

  .product-title {
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
}

/* ===== FEATURED / HOMEPAGE MOBILE ===== */
@media (max-width: 768px) {
  .featured-section {
    padding: 1.5rem 0;
  }

  .section-header h2 {
    font-size: 1.5rem;
  }

  .featured-carousel {
    padding: 0 10px;
    margin: 20px auto;
  }

  .slick-slide {
    padding: 0 8px;
  }

  .featured-section .product-item,
  .featured-carousel .product-item,
  .slick-slide .product-item {
    max-width: 100% !important;
  }

  .featured-section .product-card,
  .featured-carousel .product-card,
  .slick-slide .product-card {
    max-width: 100% !important;
  }

  .slick-prev, .slick-next {
    width: 36px;
    height: 36px;
    z-index: 10;
  }

  .slick-prev { left: 5px; }
  .slick-next { right: 5px; }
}

/* ===== FOOTER MOBILE ===== */
@media (max-width: 768px) {
  .main-footer {
    padding: 2rem 1rem;
  }

  .footer-container {
    flex-direction: column;
    gap: 2rem;
    text-align: center;
  }

  .footer-section h3 {
    font-size: 1.1rem;
  }

  .social-links, .footer-links {
    justify-content: center;
  }

  .social-links a, .footer-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
  }

  .copyright {
    margin-top: 2rem;
    padding-top: 1.5rem;
    font-size: 0.85rem;
    text-align: center;
  }
}

/* ===== PRODUCT DETAIL MOBILE ===== */
@media (max-width: 768px) {
  .product-detail-page,
  .product-detail-v2,
  .catalog-product-detail {
    padding: 1rem 0;
  }

  .product-gallery, .product-info-section {
    padding: 0 1rem;
  }

  .gallery-thumbnails {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .thumbnail {
    flex-shrink: 0;
    min-width: 60px;
  }

  .btn-add-cart, .btn-quick-view {
    min-height: 48px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
  }
}

/* ===== COLLECTIONS MOBILE ===== */
@media (max-width: 768px) {
  .collections-page {
    padding: 1rem;
  }

  .collections-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
}

/* ===== ABOUT PAGE MOBILE ===== */
@media (max-width: 768px) {
  .about-content {
    padding: 1rem;
  }

  .about-content img {
    margin: 1rem 0;
  }
}

/* ===== SAFE AREA (notched phones) ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .main-footer {
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }

  .floating-filter-btn {
    bottom: max(20px, env(safe-area-inset-bottom));
  }

  .mobile-nav-toggle {
    margin-right: env(safe-area-inset-right);
  }
}

/* ===== TABLET (768px - 991px) ===== */
@media (min-width: 769px) and (max-width: 991px) {
  .products-grid.grid-view,
  .catalog-grid.grid-view {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
  }

  .catalog-container {
    padding: 1.5rem 1rem;
  }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 768px) and (orientation: landscape) {
  .hero {
    min-height: 70vh;
  }

  .mobile-nav {
    overflow-y: auto;
  }
}
