/**
 * IRP Patrimonial - Responsive CSS
 * Media queries para tablet y móvil
 */

/* ========================================
   TABLET (≤1024px)
   ======================================== */
@media (max-width: 1024px) {
  /* Header */
  .header-center {
    display: none;
  }
  
  /* Ocultar splitters en tablet/mobile */
  .panel-splitter {
    display: none !important;
  }
  
  /* Paneles como overlay */
  .panel {
    position: fixed;
    top: var(--header-height);
    bottom: var(--statusbar-height);
    z-index: var(--z-panels);
    transition: transform var(--transition-normal);
    width: var(--panel-width) !important;
    min-width: var(--panel-width) !important;
    max-width: var(--panel-width) !important;
  }
  
  .panel-left {
    left: 0;
    transform: translateX(-100%);
    border-right: none;
    box-shadow: var(--shadow-lg);
  }
  
  .panel-left.show {
    transform: translateX(0);
  }
  
  .panel-right {
    right: 0;
    transform: translateX(100%);
    border-left: none;
    box-shadow: var(--shadow-lg);
  }
  
  .panel-right.show {
    transform: translateX(0);
  }
  
  /* Backdrop para paneles móviles */
  .panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-panels) - 1);
  }
  
  .panel-backdrop.visible {
    display: block;
  }
  
  /* Mostrar botones flotantes de borde */
  .mobile-toggle {
    display: flex;
  }
  
  /* Layer switcher - más arriba en móvil */
  #layer-switcher {
    right: 10px;
    top: calc(var(--header-height) + 10px);
  }
  
  #mincul-switcher,
  #riotinto-pdf-switcher {
    right: 62px;
    top: calc(var(--header-height) + 10px);
  }
  
  /* Panel de elementos - ajustado para móvil */
  .elements-panel {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: 70px;
    max-height: 35vh;
  }
  
  /* Zoom controls */
  .zoom-controls {
    bottom: 120px;
    right: 10px;
  }
  
  /* GPS Panel */
  #gps-panel {
    left: 10px;
    bottom: 130px;
  }
  
  /* Toolbar */
  #toolbar {
    bottom: 80px;
  }
  
  /* UTM Panel */
  #utm-panel {
    top: calc(var(--header-height) + 10px);
  }
  
  /* Search panel */
  #search-panel {
    left: 50%;
    right: auto;
    width: 320px;
    transform: translateX(-50%);
    top: 70px;
  }
  
  /* Polygon controls */
  #polygon-controls {
    left: 10px;
    top: auto;
    bottom: 80px;
    transform: none;
  }
}

/* ========================================
   MOBILE (≤640px)
   ======================================== */
@media (max-width: 640px) {
  /* Variables ajustadas para móvil */
  :root {
    --header-height: 44px;
    --statusbar-height: 24px;
    --panel-width: 100%;
  }
  
  /* Header */
  #header {
    padding: 0 10px;
  }
  
  .header-logo img {
    height: 28px;
  }
  
  .header-logo-text {
    font-size: 16px;
  }
  
  .header-logo-text .subtitle {
    display: none;
  }
  
  .header-right .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
  
  /* Paneles fullscreen */
  .panel {
    width: 100%;
    border-radius: 0;
  }
  
  /* Status bar compacto */
  #statusbar {
    padding: 0 8px;
    font-size: 10px;
  }
  
  .statusbar-item span:not(.coords-value) {
    display: none;
  }
  
  /* Toolbar más compacto */
  #toolbar {
    padding: 4px;
    gap: 2px;
  }
  
  .toolbar-btn {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }
  
  .toolbar-divider {
    margin: 2px;
  }
  
  /* Botones de borde en móvil */
  .mobile-toggle {
    width: 24px;
    height: 56px;
    font-size: 12px;
  }
  
  /* Lista de elementos */
  #elements-list {
    left: 5px;
    right: 5px;
    bottom: 75px;
    max-height: 35vh;
  }
  
  .element-item {
    padding: 6px 8px 6px 12px;
  }
  
  .element-name {
    font-size: 12px;
  }
  
  .element-type {
    font-size: 9px;
  }
  
  /* Search panel */
  #search-panel {
    left: 10px;
    right: 10px;
    width: auto;
    transform: none;
    top: 60px;
  }
  
  /* Polygon controls */
  #polygon-controls {
    left: 10px;
    top: auto;
    bottom: 70px;
    transform: none;
    padding: 8px;
  }
  
  #polygon-controls .btn {
    font-size: 12px;
    padding: 8px 12px;
  }
  
  /* UTM Panel oculto por defecto en móvil */
  #utm-panel {
    display: none;
  }
  
  #utm-panel.visible {
    display: block;
    position: fixed;
    top: auto;
    bottom: 80px;
    left: 10px;
    right: 10px;
    width: auto;
  }
  
  /* Layer switcher */
  #layer-switcher {
    top: calc(var(--header-height) + 5px);
    right: 10px;
    padding: 4px;
    gap: 2px;
  }
  
  #mincul-switcher,
  #riotinto-pdf-switcher {
    top: calc(var(--header-height) + 5px);
    right: 56px;
    padding: 4px;
    gap: 2px;
  }
  
  #layer-switcher .toolbar-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  
  /* Modales */
  .modal {
    max-width: 95%;
    max-height: 95%;
    margin: 10px;
  }
  
  .modal-header {
    padding: 12px 15px;
  }
  
  .modal-title {
    font-size: 14px;
  }
  
  .modal-body {
    padding: 15px;
  }
  
  .modal-footer {
    padding: 12px 15px;
    flex-direction: column;
  }
  
  .modal-footer .btn {
    width: 100%;
  }
  
  /* Toasts */
  #toast-container {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }
  
  .toast {
    min-width: auto;
    max-width: none;
  }
  
  /* Zoom controls */
  .zoom-controls {
    bottom: 140px;
    right: 10px;
  }
  
  .zoom-controls .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  
  /* Iframe overlay */
  .iframe-container {
    width: 95vw;
    height: 95vh;
    border-radius: var(--border-radius);
  }

  .iframe-container.iframe-narrow {
    width: 95vw;
    max-width: none;
  }
  
  .iframe-close {
    width: 36px;
    height: 36px;
    font-size: 16px;
    top: 10px;
    right: 10px;
  }
  
  /* Popup editable */
  .popup-editable {
    min-width: auto;
    width: 280px;
  }
  
  .popup-registros {
    grid-template-columns: 1fr;
  }
  
  /* Color picker */
  .color-picker-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  
  .color-picker-option {
    width: 36px;
    height: 36px;
  }
}

/* ========================================
   LANDSCAPE MOBILE
   ======================================== */
@media (max-width: 640px) and (orientation: landscape) {
  :root {
    --header-height: 40px;
    --statusbar-height: 20px;
  }
  
  #toolbar {
    bottom: 60px;
  }
  
  .mobile-toggle {
    width: 22px;
    height: 48px;
    font-size: 11px;
  }
  
  #elements-list {
    max-height: 50vh;
    bottom: 65px;
  }
  
  #search-panel {
    bottom: 110px;
  }
  
  #polygon-controls {
    left: 10px;
    bottom: 110px;
  }
}

/* ========================================
   PREFERENCIAS DEL SISTEMA
   ======================================== */

/* Reducir movimiento si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   ALTO CONTRASTE
   ======================================== */
@media (prefers-contrast: high) {
  :root {
    --border-color: #607d8b;
  }
  
  .btn-primary {
    border: 2px solid white;
  }
  
  .input:focus {
    box-shadow: 0 0 0 3px white;
  }
}

/* ========================================
   PANTALLAS GRANDES (≥1440px)
   ======================================== */
@media (min-width: 1440px) {
  :root {
    --panel-width: 320px;
  }
  
  .toolbar-btn {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }
}

/* ========================================
   PANTALLAS MUY GRANDES (≥1920px)
   ======================================== */
@media (min-width: 1920px) {
  :root {
    --panel-width: 360px;
    --header-height: 56px;
  }
  
  .header-logo-text {
    font-size: 20px;
  }
  
  #elements-list {
    width: 100%;
  }
}
