/* ========================================================
   DevStore — Responsive / Mobile Styles
   Breakpoints: 1024px (tablet-lg), 768px (tablet), 480px (mobile-lg), 360px (mobile-sm)
   ======================================================== */

/* ── Touch & Scroll Improvements ───────────────────────── */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent horizontal overflow globally */
html, body {
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
  position: relative;
  width: 100%;
}

/* Ensure all tables inside overflow wrappers scroll smoothly */
[style*="overflow-x:auto"],
[style*="overflow-x: auto"] {
  -webkit-overflow-scrolling: touch;
}

/* Minimum touch target for interactive elements */
.btn-icon,
.page-btn,
.admin-nav-item,
.filter-option {
  min-height: 44px;
  min-width: 44px;
}

/* ── Inputs: prevent iOS zoom (must be >=16px) ────────── */
.input,
.select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea,
select {
  font-size: 16px !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.search-bar {
  font-size: 16px !important;
  max-width: 100% !important;
}

#newsletter-email {
  min-width: 0 !important;
  width: 100% !important;
}

/* ── Toast: mobile full-width ───────────────────────────── */
@media (max-width: 480px) {
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    min-width: unset;
    max-width: 100%;
    width: 100%;
  }
}

/* ── Modal: mobile bottom-sheet ─────────────────────────── */
@media (max-width: 640px) {
  .modal-overlay {
    align-items: flex-end;
  }

  .modal {
    margin: 0;
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 92vh;
  }

  .modal-header {
    padding: var(--stack-md) var(--stack-md);
  }

  .modal-body {
    padding: var(--stack-md);
  }

  .modal-footer {
    padding: var(--stack-md);
    gap: var(--stack-sm);
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1;
    justify-content: center;
  }

  /* Inside modals: 2-col grids collapse */
  .modal-body div[style*="grid-template-columns:1fr 1fr"],
  .modal-body div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* =====================================================
   ADMIN LAYOUT — SIDEBAR & TOPBAR
   ===================================================== */

@media (max-width: 768px) {

  /* ── Admin Layout ───────────────────────────────────── */
  .admin-layout {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .admin-main {
    overflow: visible;
    width: 100%;
  }

  /* ── Sidebar: off-canvas drawer ─────────────────────── */
  .admin-sidebar {
    position: fixed !important;
    left: -280px;
    top: 0;
    bottom: 0;
    height: 100vh !important;
    width: 280px !important;
    z-index: 300;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex !important;
  }

  .admin-sidebar.open {
    left: 0 !important;
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
  }

  /* ── Sidebar Overlay ───────────────────────────────── */
  .admin-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 299;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease;
  }

  .admin-sidebar-overlay.open {
    display: block;
  }

  /* ── Topbar: mobile layout ─────────────────────────── */
  .admin-topbar {
    height: auto;
    min-height: 64px;
    padding: 0 var(--stack-md);
    flex-wrap: nowrap;
    gap: var(--stack-sm);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .admin-topbar > div:first-child {
    overflow: hidden;
    flex: 1;
    min-width: 0;
  }

  .admin-topbar h2 {
    font-size: 16px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .admin-topbar p {
    display: none;
  }

  /* ── Hamburger button (injected by JS) ─────────────── */
  .admin-hamburger {
    display: inline-flex !important;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
    cursor: pointer;
    background: none;
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius);
    color: var(--on-surface);
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    order: -1;
  }

  .admin-hamburger .bar {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--on-surface);
    border-radius: var(--radius-full);
    transition: all 0.25s ease;
  }

  /* ── Admin Content ─────────────────────────────────── */
  .admin-content {
    padding: var(--stack-md) !important;
    overflow-y: visible;
  }

  /* ── Stats Grid ────────────────────────────────────── */
  .grid-stats {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .stat-card {
    padding: var(--stack-md);
  }

  .stat-card-value {
    font-size: 22px;
  }

  /* ── Dashboard: inline-style grid overrides ────────── */
  .admin-dashboard-charts-row,
  .admin-content > div[style*="2fr 1fr"],
  .admin-content > div[style*="1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Search inputs in toolbars ─────────────────────── */
  .input-with-icon[style*="width:260px"],
  .input-with-icon[style*="width: 260px"] {
    width: 100% !important;
  }

  /* ── Pagination ────────────────────────────────────── */
  .pagination {
    justify-content: center;
  }

  /* ── Quick actions: no slide transform on touch ────── */
  .quick-action:hover {
    transform: none;
  }

  /* ── View Site button: compact on mobile ───────────── */
  .admin-topbar .btn-ghost.btn-sm {
    padding: 8px 10px;
  }

  /* ── Upload zone: reduce padding ───────────────────── */
  .upload-zone {
    padding: 32px var(--stack-lg);
  }
}

/* ── Very small phones (<=400px) ────────────────────────── */
@media (max-width: 400px) {
  .grid-stats {
    grid-template-columns: 1fr !important;
  }

  .admin-topbar .btn-ghost.btn-sm .btn-label-text {
    display: none;
  }

  .admin-content {
    padding: var(--stack-sm) !important;
  }
}

/* =====================================================
   ADMIN — SPECIFIC PAGE LAYOUTS
   ===================================================== */

/* ── Add Product: form + preview grid ───────────────────── */
.admin-add-product-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--gutter);
  align-items: start;
}

@media (max-width: 960px) {
  .admin-add-product-grid {
    grid-template-columns: 1fr;
  }

  .admin-add-product-grid > .preview-sticky {
    position: static !important;
    top: auto !important;
  }
}

/* ── Categories: list + form grid ───────────────────────── */
.admin-categories-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--gutter);
  align-items: start;
}

@media (max-width: 900px) {
  .admin-categories-grid {
    grid-template-columns: 1fr;
  }

  .admin-categories-grid > .cat-form-sticky {
    position: static !important;
    top: auto !important;
  }
}

/* ── Settings: tab nav horizontal on mobile ─────────────── */
@media (max-width: 768px) {
  .settings-layout {
    grid-template-columns: 1fr !important;
  }

  .settings-nav {
    position: static !important;
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .settings-nav::-webkit-scrollbar {
    display: none;
  }

  .settings-nav-item {
    flex-shrink: 0;
    border-left: none !important;
    border-bottom: 2px solid transparent;
    padding: var(--stack-sm) var(--stack-md);
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    text-align: center;
    min-height: 60px;
    justify-content: center;
  }

  .settings-nav-item.active {
    border-bottom-color: var(--primary) !important;
    border-left-color: transparent !important;
  }

  .settings-nav-item .material-symbols-outlined {
    font-size: 20px !important;
  }
}

/* ── Form grids ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr !important;
  }
}

/* ── Data table cells: compact on mobile ────────────────── */
@media (max-width: 600px) {
  .data-table td,
  .data-table th {
    padding: 10px 12px;
  }

  /* Make action buttons slightly bigger */
  .data-table .btn-icon[style*="width:32px"] {
    width: 40px !important;
    height: 40px !important;
  }
}

/* =====================================================
   PUBLIC STORE PAGES
   ===================================================== */

/* ── Topnav ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topnav-inner {
    padding: 0 var(--stack-md);
    height: 56px;
  }

  .nav-logo {
    font-size: 18px;
  }

  .nav-actions {
    gap: var(--stack-sm);
  }

  .mobile-nav {
    padding: var(--stack-md);
    top: 56px;
  }

  .mobile-nav a {
    font-size: 16px;
    padding: 14px 0;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ── Hero section ───────────────────────────────────────── */
@media (max-width: 768px) {
  .hero {
    padding: 32px 0 24px !important;
  }

  .hero::before {
    width: 300px;
    height: 300px;
    top: -40px;
  }

  .hero h1 {
    font-size: clamp(24px, 6vw, 36px) !important;
    line-height: 1.2 !important;
    margin-bottom: var(--stack-md) !important;
  }

  .hero p {
    font-size: 14px !important;
    line-height: 1.5 !important;
    margin-bottom: var(--stack-md) !important;
    padding: 0 var(--stack-md) !important;
    word-break: break-word;
  }

  .search-bar-wrap {
    margin: 0 var(--stack-md);
  }

  .search-bar {
    padding: 14px 100px 14px 44px;
  }

  .search-bar-btn {
    padding: 0 14px;
    font-size: 10px;
  }

  .popular-tags {
    padding: 0 var(--stack-md);
  }
}

/* ── Product grid ───────────────────────────────────────── */
@media (max-width: 768px) {
  .grid-products {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--stack-md);
  }
}

@media (max-width: 480px) {
  .grid-products {
    grid-template-columns: 1fr;
  }
}

/* ── Categories & Product cards layout safety ───────────── */
.category-card,
.product-card,
.card {
  min-width: 0 !important;
}

@media (max-width: 640px) {
  .grid-categories {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: var(--stack-sm) !important;
  }
}

@media (max-width: 480px) {
  .grid-categories {
    grid-template-columns: 1fr !important;
    gap: var(--stack-md) !important;
  }
  
  .category-card {
    padding: var(--stack-md) !important;
  }
}

/* ── Section headers ────────────────────────────────────── */
@media (max-width: 480px) {
  .section-header-title {
    font-size: 22px;
  }
}

/* ── Filter Sidebar (categories page) ───────────────────── */
@media (max-width: 768px) {
  .filter-toggle-btn {
    display: flex !important;
  }

  .filter-sidebar {
    display: none;
  }

  .filter-sidebar.open {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    z-index: 200;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
    animation: slideInLeft 0.25s ease;
  }

  @keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to   { transform: translateX(0); }
  }

  .filter-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 199;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .filter-sidebar-overlay.open {
    display: block;
    animation: fadeIn 0.2s ease;
  }

  /* Categories page layout */
  .categories-layout {
    flex-direction: column !important;
    gap: var(--stack-md) !important;
  }

  .categories-products-area {
    width: 100% !important;
  }
}

/* ── Product Detail Page ────────────────────────────────── */
@media (max-width: 768px) {
  .product-detail-grid {
    grid-template-columns: 1fr !important;
  }

  .gallery-thumbs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    grid-template-columns: repeat(4, 80px);
  }

  .product-purchase-panel {
    position: static !important;
    top: auto !important;
  }

  .product-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }

  .product-tabs::-webkit-scrollbar {
    display: none;
  }

  .product-tab {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .breadcrumb {
    font-size: 11px;
    flex-wrap: wrap;
  }

  .gallery-thumbs {
    grid-template-columns: repeat(4, 70px);
  }

  .code-block {
    padding: var(--stack-md);
  }

  .code-block code {
    font-size: 12px;
  }
}

/* ── Downloads Page ─────────────────────────────────────── */
@media (max-width: 768px) {
  .download-card {
    padding: var(--stack-md) !important;
  }
}

/* ── Footer ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .footer {
    padding: 40px 0 24px;
  }

  .footer-logo {
    font-size: 20px;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: var(--stack-md);
  }

  .footer-socials {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

/* ── Section padding on small screens ───────────────────── */
@media (max-width: 480px) {
  .section {
    padding-top: 40px;
    padding-bottom: 40px;
  }

  .section-sm {
    padding-top: 32px;
    padding-bottom: 32px;
  }

  .container {
    padding-left: var(--stack-md);
    padding-right: var(--stack-md);
  }
}

/* ── Buttons: touch-friendly on very small phones ───────── */
@media (max-width: 380px) {
  .btn-lg {
    padding: 14px 20px;
    font-size: 12px;
  }

  .btn {
    padding: 10px 16px;
  }
}

/* ── Prevent body scroll when drawer is open ────────────── */
body.sidebar-open,
body.filter-open {
  overflow: hidden;
  touch-action: none;
}

/* ── Hover: disable transforms on touch devices ─────────── */
@media (hover: none) {
  .product-card:hover {
    transform: none;
  }

  .card:hover {
    box-shadow: none;
    border-color: var(--outline-variant);
  }
}

/* =====================================================
   UTILITY CLASSES
   ===================================================== */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .show-mobile-flex { display: flex !important; }
}

/* ── Tablet tweaks (769px–1024px) ───────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .admin-sidebar {
    width: 220px !important;
    position: relative !important;
    left: 0 !important;
  }

  .admin-hamburger {
    display: none !important;
  }

  .admin-nav-item {
    font-size: 13px;
    padding: 9px var(--stack-sm);
  }

  .admin-content {
    padding: var(--stack-md) !important;
  }

  .grid-stats {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .admin-content > div[style*="2fr 1fr"],
  .admin-content > div[style*="1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  .admin-add-product-grid {
    grid-template-columns: 1fr 260px;
  }

  .admin-categories-grid {
    grid-template-columns: 1fr 300px;
  }
}
