/* ==========================================================================
   GMR KIT · OMNI-DEVICE RESPONSIVE ARCHITECTURE (SCUM OPS)
   Breakpoints:
     1. Big Screens / 4K / TV (>= 1600px)
     2. Standard Desktop & Laptops (1181px - 1599px)
     3. Medium Laptops & Tablets Landscape (901px - 1180px)
     4. Tablets Portrait (641px - 900px)
     5. Smartphones & Handhelds (<= 640px)
   ========================================================================== */

/* --------------------------------------------------------------------------
   01. REGLAS BASE DE CONTENCIÓN Y FLUJO
   -------------------------------------------------------------------------- */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

.main-layout {
  width: 100%;
  max-width: 1620px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   02. PANTALLAS GRANDES, TELEVISORES Y 4K (>= 1600px)
   -------------------------------------------------------------------------- */
@media (min-width: 1600px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 28px;
    padding: 24px 32px;
  }

  .full-equip-list {
    grid-template-columns: repeat(auto-fill, minmax(430px, 1fr));
    gap: 20px;
  }

  .outfits-list {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 18px;
  }

  .catalog-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
  }

  /* Ajuste de escala ergonómica para TV a distancia */
  body.density-compact .main-layout {
    max-width: 1440px;
    grid-template-columns: minmax(0, 1fr) 360px;
  }
}

/* --------------------------------------------------------------------------
   03. PORTÁTILES Y DESKTOPS ESTÁNDAR (1181px - 1599px)
   -------------------------------------------------------------------------- */
@media (min-width: 1181px) and (max-width: 1599px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 20px;
    padding: 20px 24px;
  }

  .full-equip-list {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
  }

  .outfits-list {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
  }

  .catalog-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }
}

/* --------------------------------------------------------------------------
   04. TABLETS HORIZONTAL Y PORTÁTILES PEQUEÑOS (901px - 1180px)
   (MANTIENE 2 COLUMNAS PARA QUE EL COFRE NO SE PIERDA ABAJO)
   -------------------------------------------------------------------------- */
@media (min-width: 901px) and (max-width: 1180px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 16px;
    padding: 16px;
  }

  .full-equip-list {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
  }

  .outfits-list {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
  }

  .catalog-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  .clean-header {
    padding: 10px 16px;
  }

  .nav-tab-btn {
    padding: 7px 12px;
    font-size: 0.75rem;
  }

  .btn-optics-toggle,
  .btn-density-toggle {
    padding: 6px 10px;
    font-size: 0.72rem;
  }
}

/* --------------------------------------------------------------------------
   05. TABLETS VERTICAL Y FOLDABLES (641px - 900px)
   -------------------------------------------------------------------------- */
@media (min-width: 641px) and (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 14px 16px 95px;
    gap: 16px;
  }

  /* Ocultar panel cofre en flujo normal y usar drawer / dock */
  .cart-sticky-panel:not(.mobile-open) {
    display: none;
  }

  .mobile-cart-dock {
    display: block;
  }

  .full-equip-list,
  .outfits-list {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
  }

  .catalog-grid {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 10px;
  }
}

/* --------------------------------------------------------------------------
   06. MÓVILES Y PANTALLAS PEQUEÑAS (<= 640px)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  /* Header Ultra-Optimizado para Pulgar */
  .clean-header {
    padding: 8px 10px;
  }

  .header-inner {
    flex-direction: column;
    gap: 8px;
  }

  /* Fila 1: Logo Marca + Acciones Compactas */
  .brand-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .brand-name {
    font-size: 1.15rem;
  }

  .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: nowrap;
  }

  /* Ocultar texto largo en botones de cabecera móvil y dejar iconos tácticos */
  .btn-optics-toggle {
    padding: 6px 8px;
    font-size: 0.7rem;
  }
  .btn-optics-toggle #opticsLabelText {
    display: none;
  }

  .btn-density-toggle {
    padding: 6px 8px;
  }
  .btn-density-toggle .density-label {
    display: none;
  }

  .header-stat {
    display: none; /* Se visualiza limpiamente en el dock inferior */
  }

  .btn-audio {
    width: 32px;
    height: 32px;
    padding: 0;
  }

  /* Fila 2: Pestañas con Swipe Táctil */
  .header-nav {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    gap: 6px;
    width: 100%;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .header-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-tab-btn {
    padding: 6px 11px;
    font-size: 0.74rem;
    flex-shrink: 0;
  }
  .nav-tab-btn .nav-badge {
    padding: 1px 5px;
    font-size: 0.65rem;
  }

  /* Layout Principal con espacio para el Dock Flotante */
  .main-layout {
    grid-template-columns: 1fr;
    padding: 10px 10px calc(85px + env(safe-area-inset-bottom, 12px));
    gap: 12px;
  }

  .cart-sticky-panel:not(.mobile-open) {
    display: none;
  }

  /* Tarjeta de Búsqueda y Chips en Carrusel Swipe */
  .search-card {
    padding: 12px 10px;
    gap: 10px;
  }

  .search-box-wrap {
    padding: 0 10px;
    height: 42px;
  }

  .search-input {
    font-size: 0.82rem;
  }

  .search-quick-tags {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    gap: 6px;
    width: 100%;
    padding-bottom: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .search-quick-tags::-webkit-scrollbar {
    display: none;
  }

  .btn-quick-tag {
    flex-shrink: 0;
    padding: 4px 8px;
    font-size: 0.68rem;
  }

  .categories-shelf {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    gap: 6px;
    padding-bottom: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .categories-shelf::-webkit-scrollbar {
    display: none;
  }

  .cat-pill {
    flex-shrink: 0;
    padding: 5px 9px;
    font-size: 0.72rem;
  }

  /* Tarjetas de Armas Full Equip en Móvil */
  .full-equip-list {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .fe-card {
    padding: 12px 10px;
    gap: 10px;
    border-radius: 4px;
  }

  .fe-card-top {
    display: flex;
    gap: 10px;
    align-items: center;
  }

  .fe-render-box {
    width: 82px;
    height: 68px;
    flex-shrink: 0;
    padding: 4px;
  }

  .fe-top-meta {
    gap: 4px;
    min-width: 0;
    flex: 1;
  }

  .fe-title {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .fe-desc {
    font-size: 0.72rem;
    line-height: 1.35;
    margin: 0;
  }

  .fe-components-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
  }

  .fe-comp-item {
    font-size: 0.65rem;
    padding: 3px 5px;
  }
  .fe-comp-item img {
    width: 18px;
    height: 18px;
  }

  .fe-card-footer {
    display: flex;
    gap: 6px;
    margin-top: 4px;
  }

  .btn-card-inspect {
    width: 38%;
    padding: 9px 4px;
    font-size: 0.68rem;
    justify-content: center;
  }

  .btn-equip-weapon {
    width: 62%;
    padding: 9px 6px;
    font-size: 0.72rem;
    justify-content: center;
  }

  /* Outfits en Móvil */
  .outfits-list {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .outfit-card {
    padding: 12px 10px;
    gap: 8px;
  }

  .outfit-components-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
  }

  .outfit-card-footer .btn-equip-outfit {
    padding: 10px 8px;
    font-size: 0.74rem;
    width: 100%;
    justify-content: center;
  }

  /* Catálogo General en Móvil (Grid de 2 Columnas Nítidas) */
  .catalog-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .grid-card {
    padding: 8px;
    border-radius: 4px;
  }

  .card-thumb-wrap {
    height: 70px;
  }

  .card-name {
    font-size: 0.72rem;
    min-height: 28px;
  }

  /* Dock Táctico Flotante Móvil */
  .mobile-cart-dock {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 850;
    background: rgba(8, 11, 16, 0.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--tac-orange);
    box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.8), 0 0 15px var(--tac-orange-glow);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 8px));
  }

  .mobile-dock-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .mobile-dock-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
  }

  .mobile-dock-icon {
    font-size: 1.3rem;
    color: var(--tac-orange-bright);
  }

  .mobile-dock-stats {
    display: flex;
    flex-direction: column;
  }

  .mobile-dock-title {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    font-weight: 800;
    color: #fff;
  }

  .mobile-dock-sub {
    font-size: 0.62rem;
    color: var(--tac-orange-bright);
  }

  .mobile-dock-btn-copy {
    background: var(--grad-orange);
    color: #000;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 800;
    padding: 8px 14px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 0 10px var(--tac-orange-glow);
  }

  /* Cajón Desplegable del Cofre en Móvil (.mobile-open) */
  .cart-sticky-panel.mobile-open {
    display: flex !important;
    flex-direction: column;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    max-height: 88vh !important;
    width: 100% !important;
    z-index: 900 !important;
    background: #090d14 !important;
    border-top: 2px solid var(--tac-orange) !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.95) !important;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 12px));
    animation: ueDrawerSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }

  @keyframes ueDrawerSlideUp {
    0% { transform: translateY(100%); }
    100% { transform: translateY(0); }
  }

  .mobile-cart-backdrop.active {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 890;
  }

  /* Modal de Inspección en Pantallas Móviles */
  #weaponInspectorModal {
    padding: 6px;
  }

  .inspector-chassis {
    width: 100%;
    max-height: 96vh;
    border-radius: 6px;
  }

  .inspector-header {
    padding: 12px 14px;
  }

  .inspector-title {
    font-size: 1rem;
  }

  .inspector-body {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
    max-height: calc(96vh - 120px);
  }

  .inspector-stage {
    min-height: 180px;
    padding: 12px;
  }

  .inspector-weapon-img {
    max-height: 140px;
  }

  .inspector-footer {
    padding: 10px 14px;
  }

  .btn-inspector-add {
    width: 100%;
    justify-content: center;
    font-size: 0.76rem;
    padding: 10px;
  }
}
