/* mobile.css — Oroprop HiperSabueso — Mobile-first responsive */
/* Breakpoints: xs<480, sm<640, md<768, lg<1024 */

/* ============================================================
   SIDEBAR MOBILE
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --rp-sidebar-w: 0px;
  }

  /* Sidebar: hidden off-canvas by default */
  .sidebar {
    transform: translateX(-100%);
    width: 260px !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
    box-shadow: 4px 0 30px rgba(0,0,0,0.8);
  }

  /* Sidebar shown when body has sidebar-open class */
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* Overlay when sidebar is open */
  body.sidebar-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    backdrop-filter: blur(2px);
  }

  /* Main content: full width */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 12px !important;
  }

  /* Top header adjustment */
  .top-header {
    padding-left: 60px !important;
  }
}


/* ============================================================
   HERO SECTION MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .hero-section {
    height: 85vh !important;
    min-height: 400px !important;
  }

  .hero-content {
    padding: 20px !important;
    padding-top: 70px !important;
  }

  .hero-title {
    font-size: clamp(24px, 6vw, 48px) !important;
    line-height: 1.2 !important;
  }

  .hero-subtitle {
    font-size: clamp(12px, 3vw, 16px) !important;
  }

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

  .hero-stat-value {
    font-size: clamp(18px, 4vw, 28px) !important;
  }
}

/* ============================================================
   PROPERTY CARDS MOBILE
   ============================================================ */
@media (max-width: 768px) {
  /* Cards grid: 1 column */
  .props-grid,
  .property-grid,
  [class*="grid"][class*="col"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Ensure card images don't overflow */
  .prop-card img,
  .property-card img {
    width: 100% !important;
    height: 180px !important;
    object-fit: cover !important;
  }

  /* Sabueso scanner */
  .scanner-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .prop-card img,
  .property-card img {
    height: 160px !important;
  }
}

/* ============================================================
   FILTERS & SEARCH BAR MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .filters-bar,
  .search-filters {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .filter-row {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .filter-row input,
  .filter-row select {
    width: 100% !important;
    min-width: unset !important;
  }

  /* Range slider label */
  .range-label {
    font-size: 11px !important;
  }
}

/* ============================================================
   DÓLAR MODULE MOBILE
   ============================================================ */
@media (max-width: 640px) {
  .cotiz-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .dolar-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
    padding-bottom: 4px !important;
  }

  .dolar-tab {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }
}

@media (max-width: 420px) {
  .cotiz-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   BARRIOS MODULE MOBILE
   ============================================================ */
@media (max-width: 900px) {
  /* Stack the two-column layout */
  .barrios-module > div > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  #barrio-detalle {
    min-height: unset !important;
  }
}

@media (max-width: 640px) {
  .barrio-stat {
    padding: 8px !important;
  }

  .barrio-stat-val {
    font-size: 16px !important;
  }
}

/* ============================================================
   COMPARADOR MOBILE
   ============================================================ */
@media (max-width: 768px) {
  #comp-slots {
    grid-template-columns: 1fr !important;
  }

  /* Comparativa charts */
  #comp-tabla-container > div:last-child {
    grid-template-columns: 1fr !important;
  }

  /* Table horizontal scroll */
  #comp-tabla {
    font-size: 11px !important;
  }

  .comp-th,
  .comp-td {
    padding: 8px 6px !important;
  }
}

/* ============================================================
   WAR ROOM MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .war-room-grid,
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   CHARTS MOBILE
   ============================================================ */
@media (max-width: 640px) {
  canvas {
    max-height: 200px !important;
  }
}

/* ============================================================
   MODAL MOBILE
   ============================================================ */
@media (max-width: 640px) {
  .modal,
  .modal-container {
    width: 95vw !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
    margin: 0 auto !important;
  }
}

/* ============================================================
   SECTION HEADER MOBILE
   ============================================================ */
@media (max-width: 640px) {
  h2 {
    font-size: clamp(18px, 5vw, 28px) !important;
  }

  h3 {
    font-size: clamp(14px, 4vw, 20px) !important;
  }
}

/* ============================================================
   TABLES MOBILE — horizontal scroll
   ============================================================ */
@media (max-width: 640px) {
  .table-responsive,
  .overflow-x-auto {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  table {
    min-width: 500px;
  }

  /* Exception: comparador already handles this */
  #comp-tabla {
    min-width: unset;
  }
}

/* ============================================================
   NOTIFICATIONS/TOASTS MOBILE
   ============================================================ */
@media (max-width: 480px) {
  #notification-container {
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    width: auto !important;
  }
}

/* ============================================================
   CRM & PANELS MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .crm-grid,
  .panel-grid,
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .crm-lead-card {
    padding: 12px !important;
  }
}

/* ============================================================
   CALCULADORAS MOBILE
   ============================================================ */
@media (max-width: 640px) {
  .calc-grid {
    grid-template-columns: 1fr !important;
  }

  .calc-result {
    font-size: clamp(20px, 5vw, 32px) !important;
  }
}

/* ============================================================
   MAPS MOBILE — Leaflet
   ============================================================ */
@media (max-width: 768px) {
  #map,
  .leaflet-container {
    height: 300px !important;
  }
}

/* ============================================================
   GLOBAL UTILITY FIXES
   ============================================================ */

/* Prevent horizontal overflow on all screens */
body {
  overflow-x: hidden;
}

/* Better tap targets */
@media (max-width: 768px) {
  button,
  .btn,
  .nav-item,
  a[role="button"] {
    min-height: 40px;
    min-width: 40px;
  }

  input,
  select,
  textarea {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
  }
}

/* ============================================================
   SAFE AREA (iPhone notch/home bar)
   ============================================================ */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================================
   TOURS 360 / COMMUTE / ALERTAS WA MOBILE
   ============================================================ */
@media (max-width: 768px) {
  /* Tours: gallery strip horizontal scroll */
  #tours-gallery-strip {
    gap: 6px !important;
    padding-bottom: 8px !important;
  }

  /* Pannellum viewer: full width on mobile */
  #pannellum-viewer {
    border-radius: 8px !important;
  }

  /* Commute: shortcuts wrap */
  #commute-shortcuts {
    gap: 6px !important;
  }

  #commute-shortcuts button {
    padding: 6px 10px !important;
    font-size: 11px !important;
  }

  /* Commute chart: reduce height */
  #commute-chart-canvas {
    max-height: 180px !important;
  }

  /* Alertas WA: form stacks */
  .awa-form-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   PROP DETALLE MODAL MOBILE
   ============================================================ */
@media (max-width: 640px) {
  #prop-detalle-overlay .pd-modal {
    width: 100vw !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    max-height: 100dvh !important;
  }

  #prop-detalle-overlay .pd-gallery img {
    height: 200px !important;
  }

  #prop-detalle-overlay .pd-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  #prop-detalle-overlay .pd-actions {
    flex-direction: column !important;
  }

  #prop-detalle-overlay .pd-actions button,
  #prop-detalle-overlay .pd-actions a {
    width: 100% !important;
    text-align: center !important;
  }
}

/* ============================================================
   SABUESO PRO CARD ACTIONS MOBILE
   ============================================================ */
@media (max-width: 480px) {
  .sp-card-actions {
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  .sp-action-btn {
    flex: 1 !important;
    min-width: calc(50% - 4px) !important;
    font-size: 11px !important;
    padding: 6px 4px !important;
  }

  .sp-action-detalle {
    flex: 100% !important;
  }
}

/* ============================================================
   GENERADOR DOCUMENTOS MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .gd-body {
    flex-direction: column !important;
  }

  .gd-sidebar {
    width: 100% !important;
    min-width: unset !important;
    max-height: 280px !important;
  }
}

/* ============================================================
   SABUESO PRO — QUICK FILTER PILLS MOBILE
   ============================================================ */
@media (max-width: 768px) {
  #sp-quick-filters {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px !important;
    scrollbar-width: none;
    gap: 6px !important;
  }
  #sp-quick-filters::-webkit-scrollbar { display: none; }
  .sp-quick-btn { flex-shrink: 0 !important; }

  /* Card actions: horizontal scroll en lugar de saltar a 2 cols */
  .sp-card-actions {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px !important;
    padding-bottom: 2px !important;
  }
  .sp-card-actions::-webkit-scrollbar { display: none; }
  .sp-action-btn { flex-shrink: 0 !important; }
}

/* ============================================================
   TABS — HORIZONTAL SCROLL MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0 !important; }
}

/* ============================================================
   MAPA — CONTROLES SCROLL MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .mapa-controls-panel {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mapa-controls-panel::-webkit-scrollbar { display: none; }
  .mapa-btn { flex-shrink: 0 !important; }
  .mapa-legend { display: none !important; }
  #mapa-leaflet { height: 340px !important; }
}

/* ============================================================
   SCORE BREAKDOWN OVERLAY MOBILE
   ============================================================ */
@media (max-width: 640px) {
  /* El overlay del score breakdown usa insertAdjacentHTML al body */
  div[style*="position:fixed"][style*="inset:0"][style*="z-index:99"] > div {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh !important;
    border-radius: 20px 20px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    top: auto !important;
    transform: none !important;
    overflow-y: auto !important;
  }
}

/* ============================================================
   CURRENCY TOGGLE SIDEBAR MOBILE
   ============================================================ */
@media (max-width: 768px) {
  #sidebar-currency {
    padding: 8px !important;
  }
  #sidebar-currency > div:last-of-type {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
  }
  #sidebar-currency button {
    font-size: 11px !important;
    padding: 5px 4px !important;
    text-align: center !important;
  }
}

/* ============================================================
   TOUCH — TAP TARGET SIZE
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
  .nav-item { padding: 13px 16px !important; }
  .tab { padding: 10px 14px !important; }
  .sp-action-btn { min-height: 36px !important; }
  .mapa-btn { min-height: 36px !important; padding: 8px 14px !important; }
  /* Disable hover animations on touch */
  .sp-card:hover { transform: none !important; }
}

/* ============================================================
   HERO CSS FALLBACK — cuando WebGL no está disponible
   ============================================================ */
@keyframes heroBgShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes heroParticle {
  0%   { transform: translateY(0) scale(1); opacity: 0.6; }
  100% { transform: translateY(-100vh) scale(0.3); opacity: 0; }
}

.hero-css-fallback {
  background: linear-gradient(
    135deg,
    #020510 0%,
    #0a0f1e 20%,
    #050e1f 40%,
    #020a18 60%,
    #030b1a 80%,
    #020510 100%
  );
  background-size: 300% 300%;
  animation: heroBgShift 12s ease infinite;
  position: relative;
  overflow: hidden;
}

/* Neon city grid overlay */
.hero-css-fallback::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,229,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,229,255,0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
}

/* Glowing horizon line */
.hero-css-fallback::after {
  content: '';
  position: absolute;
  bottom: 35%;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(0,229,255,0.4) 30%, rgba(0,102,255,0.6) 50%, rgba(0,229,255,0.4) 70%, transparent 100%);
  box-shadow: 0 0 20px rgba(0,229,255,0.3), 0 0 60px rgba(0,102,255,0.2);
  pointer-events: none;
}
