/* ═══════════════════════════════════════════════════════
   SELLPOINT POS — RESPONSIVE STYLES
   Breakpoints:
     ≥ 1600px  → Large monitor / TV
     ≥ 1920px  → Ultra-wide / 4K
     ≤ 1280px  → Laptop medium
     ≤ 1024px  → Tablet / small laptop
     ≤ 768px   → Large phone / portrait tablet
     ≤ 480px   → Phone
═══════════════════════════════════════════════════════ */

/* ══════════════════════════════════════
   LARGE SCREENS ≥ 1600px (TV / Big Monitor)
══════════════════════════════════════ */
@media (min-width: 1600px) {
  html { font-size: 15.5px; }
  :root { --sidebar-width: 256px; --topbar-height: 64px; }

  .section { padding: 2.25rem 2.75rem; }
  .pos-ticket-panel { width: 380px; min-width: 360px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 1rem; }
  .product-card-img { width: 88px; height: 88px; }
  .stats-grid { grid-template-columns: repeat(6, 1fr); }
  .charts-grid { grid-template-columns: 2fr 1fr 1fr; }
  .modal { max-width: 620px; }
}

@media (min-width: 1920px) {
  html { font-size: 16.5px; }
  :root { --sidebar-width: 280px; --topbar-height: 68px; }

  .section { padding: 2.75rem 3.5rem; }
  .pos-ticket-panel { width: 440px; min-width: 420px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 1.1rem; }
  .product-card-img { width: 100px; height: 100px; }
}

/* ══════════════════════════════════════
   LAPTOP MEDIUM ≤ 1280px
══════════════════════════════════════ */
@media (max-width: 1280px) {
  :root { --sidebar-width: 210px; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .pos-ticket-panel { width: 290px; min-width: 270px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}

/* ══════════════════════════════════════
   TABLET / SMALL LAPTOP ≤ 1024px
══════════════════════════════════════ */
@media (max-width: 1024px) {
  /* Auto-collapse sidebar to icon-only */
  .sidebar {
    width: 64px !important;
    min-width: 64px !important;
    position: relative;
  }
  .sidebar .nav-label,
  .sidebar .logo-text,
  .sidebar .seller-info { display: none !important; }
  .sidebar .sidebar-header { justify-content: center; padding: 1rem 0; }
  .sidebar .nav-item { justify-content: center; padding: 0.65rem 0; }
  .sidebar .seller-profile { justify-content: center; padding: 0.65rem 0; }

  /* When sidebar-toggle re-opens it on tablet */
  .sidebar.force-open {
    width: var(--sidebar-width) !important;
    min-width: var(--sidebar-width) !important;
    position: absolute; height: 100%; z-index: 200;
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  }
  .sidebar.force-open .nav-label,
  .sidebar.force-open .logo-text,
  .sidebar.force-open .seller-info { display: block !important; }
  .sidebar.force-open .sidebar-header { justify-content: flex-start; padding: 1.35rem 1.1rem 1.1rem; }
  .sidebar.force-open .nav-item { justify-content: flex-start; padding: 0.6rem 0.75rem; }
  .sidebar.force-open .seller-profile { justify-content: flex-start; padding: 0.6rem 0.75rem; }

  .section { padding: 1.25rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr 1fr; }
  .charts-grid .chart-card.wide { grid-column: span 2; }
  .pos-ticket-panel { width: 270px; min-width: 250px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .section-header { flex-wrap: wrap; }
}

/* ══════════════════════════════════════
   LARGE PHONE / PORTRAIT TABLET ≤ 768px
══════════════════════════════════════ */
@media (max-width: 768px) {
  html { font-size: 13px; }

  /* Sidebar becomes a slide-over drawer */
  .sidebar {
    position: fixed !important;
    top: 0; left: 0; height: 100%;
    width: var(--sidebar-width) !important;
    min-width: var(--sidebar-width) !important;
    transform: translateX(-100%);
    transition: transform 0.22s ease, width 0.22s ease;
    z-index: 300;
    box-shadow: none;
  }
  .sidebar .nav-label,
  .sidebar .logo-text,
  .sidebar .seller-info { display: block !important; }
  .sidebar .sidebar-header { justify-content: flex-start; padding: 1.35rem 1.1rem 1.1rem; }
  .sidebar .nav-item { justify-content: flex-start; padding: 0.6rem 0.75rem; }
  .sidebar .seller-profile { justify-content: flex-start; padding: 0.6rem 0.75rem; }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,0.25);
  }

  /* Overlay backdrop when sidebar open on mobile */
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.45); z-index: 299;
  }
  .sidebar-backdrop.active { display: block; }

  /* Main content takes full width */
  .main-content { width: 100%; }

  /* Topbar compact */
  .topbar { padding: 0 0.85rem; gap: 0.6rem; }
  .topbar-date { display: none; }

  /* Sections */
  .section { padding: 1rem; }
  .section-header h2 { font-size: 1.1rem; }
  .section-header-actions { width: 100%; justify-content: space-between; }

  /* Dashboard */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
  .charts-grid { grid-template-columns: 1fr; gap: 0.75rem; }
  .charts-grid .chart-card.wide { grid-column: 1; }

  /* POS — stacked layout: products on top, ticket slides up */
  #section-pos.active { flex-direction: column !important; }
  .pos-layout { flex-direction: column; height: 100%; }
  .pos-products-panel { flex: 1; min-height: 0; padding: 0.75rem 0.75rem 5rem; }
  .pos-ticket-panel {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 210;
    width: 100% !important; min-width: 0 !important;
    border-left: none; border-top: 2px solid var(--border);
    max-height: 75vh; flex-shrink: 0;
    display: none;   /* hidden until toggle */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -6px 32px rgba(0,0,0,0.14);
  }
  .ticket-tabs-wrap { display: none; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.55rem; }
  .product-card { padding: 0.65rem 0.5rem; }
  .product-card-img { width: 64px; height: 64px; }

  /* Floating ticket toggle button */
  .mobile-ticket-toggle {
    display: flex !important;
    position: fixed; bottom: 1.5rem; right: 1rem; z-index: 250;
    background: var(--primary); color: #fff; border: none;
    border-radius: 50px; padding: 0.65rem 1.2rem;
    font-size: 0.875rem; font-weight: 700;
    box-shadow: 0 4px 20px rgba(0,0,0,0.22);
    align-items: center; gap: 0.45rem;
    transition: background var(--transition), transform var(--transition);
  }
  .mobile-ticket-toggle:hover { background: var(--primary-dark); transform: translateY(-2px); }

  /* Modals — full screen on mobile */
  .modal {
    width: 100% !important; max-width: 100% !important;
    max-height: 95vh !important;
    bottom: 0; top: auto; left: 0 !important;
    transform: translateY(4%) !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
  }
  .modal.visible { transform: translateY(0) !important; }

  /* Tables — scrollable */
  .inventory-table-wrap,
  .reports-content .report-section-box { overflow-x: auto; }
  .data-table th, .data-table td { padding: 0.55rem 0.65rem; white-space: nowrap; }

  /* Period tabs — smaller */
  .period-btn { padding: 5px 12px; font-size: 0.77rem; }

  /* Settings panels — single column */
  .settings-layout { flex-direction: column; }
}

/* ══════════════════════════════════════
   PHONE ≤ 480px
══════════════════════════════════════ */
@media (max-width: 480px) {
  html { font-size: 12.5px; }
  :root { --topbar-height: 54px; }

  .topbar { padding: 0 0.65rem; }
  .btn-primary { padding: 0.5rem 0.85rem; font-size: 0.82rem; }

  /* Dashboard: single column */
  .stats-grid { grid-template-columns: 1fr; gap: 0.55rem; }

  /* POS products — 2 cols */
  .products-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .product-card-img { width: 56px; height: 56px; }
  .pos-ticket-panel { max-height: 55vh; }

  /* Tickets/forms: single column */
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid .span2 { grid-column: 1 !important; }

  /* Ticket actions */
  .ticket-actions { grid-template-columns: 1fr; }
  .ticket-actions .btn-primary.wide { grid-column: 1; }

  /* Section padding */
  .section { padding: 0.75rem; }
  .section-header { margin-bottom: 1rem; }

  /* Payment modal */
  .payment-methods { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .payment-method-btn { padding: 0.7rem 0.5rem; }

  /* Stat cards compact */
  .stat-card { padding: 0.9rem 1rem; }
  .stat-value { font-size: 1.3rem !important; }

  /* Topbar: hide date and show only icon buttons */
  .topbar-date { display: none; }

  /* Users grid: single column */
  .users-grid { grid-template-columns: 1fr !important; }
}

/* ══════════════════════════════════════
   MOBILE INTERACTIVE IMPROVEMENTS (iPhone XR ~414px)
   Mejorar controles táctiles y espaciado
══════════════════════════════════════ */
@media (max-width: 768px) {
  /* Touch-friendly buttons (mínimo 44x44px iOS) */
  button, .btn, .btn-primary, .btn-secondary, .btn-danger, 
  input[type="submit"], input[type="button"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Modal padding para mejor lectura */
  .modal-body { padding: 1.15rem; }
  .modal-header { padding: 1rem 1.15rem; }
  .modal-footer { padding: 1rem 1.15rem; gap: 0.6rem; }

  /* QR Modal optimizado para móvil */
  #qr-modal .modal-body { 
    padding: 1.25rem; 
    max-height: 80vh; 
    overflow-y: auto; 
  }
  #qr-local-wrap, #qr-public-wrap {
    padding: 1rem 0.5rem;
  }
  #qr-local-img, #qr-public-img {
    max-width: 180px !important;
    height: auto;
  }

  /* Form inputs más grandes para tocar */
  input[type="text"], 
  input[type="number"], 
  input[type="password"],
  input[type="email"],
  select, textarea {
    min-height: 44px;
    font-size: 16px; /* Evitar zoom automático iOS */
    padding: 0.6rem 0.85rem;
  }

  /* Tables — mejorar scroll horizontal */
  .data-table-wrap, .inventory-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Stat cards — espaciado vertical */
  .stat-card {
    padding: 1.1rem 1rem;
  }
  .stat-label {
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
  }
  .stat-value {
    font-size: 1.6rem;
    line-height: 1.2;
  }

  /* Product cards — mejor tap targets */
  .product-card {
    min-height: 120px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }
  .product-card:active {
    transform: scale(0.97);
  }

  /* Ticket items — espaciado */
  .ticket-item {
    padding: 0.75rem 0.65rem;
    min-height: 56px;
  }

  /* Search bars — legibles */
  .search-box input {
    font-size: 16px;
    min-height: 44px;
  }

  /* Section headers — wrap flexible */
  .section-header {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .section-header-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 0.6rem;
  }
}

/* ══════════════════════════════════════
   MOBILE TICKET TOGGLE (hidden on desktop)
══════════════════════════════════════ */
.mobile-ticket-toggle { display: none; }
