/* ================================================================
   HappyHost Admin — Mobile CSS  (cargado después de site.css)
   ================================================================
   Breakpoints:
     • phones  : max-width 575.98px
     • tablets : 576px – 991.98px
     • desktop : min-width 992px (sin cambios)

   Estrategia:
     1.  Sidebar   → touch targets 44 px, dvh fix para iOS
     2.  Navbar    → hamburguer touch-friendly
     3.  App main  → padding razonable + safe-area-inset
     4.  Tabla Reservas (Admin) → oculta 12 columnas en < 576 px,
                                  muestra sólo: Prop / Huésped / Check-in / Pendiente / Acciones
     5.  Formulario reserva → columna única en phones
     6.  Barra de búsqueda  → apilada en phones
     7.  KPI grid  → 2 columnas en phones (no 1)
     8.  Calendário → controles, stats, grilla
     9.  Inputs / botones → mínimo 44 px touch target
    10.  Bottom Nav → barra fija en la parte inferior (phones)
    11.  Otras tablas / hh-tbl / superficies
    12.  Utilidades: show-mobile / hide-mobile
    13.  iOS 100dvh fix
   ================================================================ */


/* ════════════════════════════════════════════════════════════════
   1. FUNDAMENTOS GLOBALES
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 991.98px) {
  /* Evitar pull-to-refresh accidental dentro del app */
  body { overscroll-behavior-y: contain; }

  /* Scroll suave en anclas */
  html { scroll-behavior: smooth; }
}


/* ════════════════════════════════════════════════════════════════
   2. NAVBAR — hamburguer + usuario
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 991.98px) {

  /* Botón hamburguer — 44 × 44 px mínimo */
  .sb-toggle {
    min-width:  44px;
    min-height: 44px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Dropdown usuario más holgado para touch */
  .hh-user-dropdown .dropdown-toggle {
    min-height: 44px;
    padding: .55rem 1rem;
  }

  /* La navbar no puede envolver a 2 líneas: el saludo quedaba
     montado sobre el contenido de la página. Una sola línea,
     y el nombre largo se corta con puntos suspensivos. */
  .navbar > .container-fluid {
    flex-wrap: nowrap;
  }
  .hh-user-dropdown .dropdown-toggle {
    max-width: 38vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}


/* ════════════════════════════════════════════════════════════════
   3. SIDEBAR — touch targets + dvh + blur overlay
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 991.98px) {

  /* Ancho: cómodo en phones pequeños */
  :root { --sidebar-w: min(280px, 82vw); }

  /* Ítems de nav — mínimo 44 px de alto */
  .sb-item {
    padding: 11px 14px;
    min-height: 44px;
    align-items: center;
  }

  .sb-logout-btn {
    padding: 11px 14px;
    min-height: 44px;
    align-items: center;
  }

  /* Ícono — mismo tamaño que desktop, corregir background-size */
  .sb-icon {
    width: 28px;
    height: 28px;
    background-size: 24px 24px;
  }

  /* Overlay con sutil blur */
  .sb-overlay {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
  }

  .sidebar.sb-open {
    box-shadow: 6px 0 32px rgba(0, 0, 0, .2);
  }
}

/* iOS dvh fix para que el sidebar realmente ocupe toda la pantalla */
@supports (height: 100dvh) {
  @media (max-width: 991.98px) {
    .sidebar {
      height: 100dvh;
    }
    .app-layout {
      min-height: calc(100dvh - var(--nav-h));
    }
  }
}


/* ════════════════════════════════════════════════════════════════
   4. APP MAIN — padding + espacio para bottom-nav
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {
  .app-main {
    padding: 12px 10px;
    /* Espacio para la bottom-nav fija */
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 576px) and (max-width: 991.98px) {
  .app-main {
    padding: 18px 16px;
  }
}


/* ════════════════════════════════════════════════════════════════
   5. TABLA DE RESERVAS (Admin) — columnas prioritarias en phones
   ════════════════════════════════════════════════════════════════ */

/*
   Estructura real de columnas de .tbl-res:
   1 Propiedad | 2 Portal | 3 Huésped | 4 Pers.
   5 Check-in  | 6 Check-out | 7 Noches | 8 Total USD
   9 %Com. | 10 Com.HH | 11 Neto Prop. | 12 Seña
   13 Saldo Ef. | 14 Saldo Tr. | 15 Payo | 16 Pendiente | 17 Acciones

   En < 576 px mostramos: 1, 3, 5, 16, 17
   Ocultamos: 2, 4, 6–15
*/

@media (max-width: 575.98px) {

  /* --- Columnas que se ocultan --- */
  .tbl-res th:nth-child(2), .tbl-res td:nth-child(2),   /* Portal     */
  .tbl-res th:nth-child(4), .tbl-res td:nth-child(4),   /* Pers.      */
  .tbl-res th:nth-child(6), .tbl-res td:nth-child(6),   /* Check-out  */
  .tbl-res th:nth-child(n+7):nth-child(-n+15),           /* cols 7–15  */
  .tbl-res td:nth-child(n+7):nth-child(-n+15) {
    display: none;
  }

  /* --- Tabla ocupa todo el ancho disponible --- */
  .tbl-res {
    width: 100%;
    font-size: .84rem;
  }

  /* Columna Propiedad — negrita y un poco más compacta */
  .tbl-res td:nth-child(1) {
    font-size: .82rem;
    max-width: 110px;
    white-space: normal;
    word-break: break-word;
  }

  /* Chip "Pendiente" — destacado en verde/rojo */
  .tbl-res td:nth-child(16) {
    font-weight: 700;
    font-size: .82rem;
  }

  /* Nota debajo del encabezado del card de tabla */
  .adm-card-hd::after {
    content: "Mostrando columnas principales • abre editar para ver todo";
    display: block;
    width: 100%;
    font-size: .62rem;
    color: var(--adm-muted, #6B8A95);
    font-weight: 400;
    margin-top: 3px;
    letter-spacing: .01em;
  }
}

/* Scroll horizontal mejorado para tablas en tablets */
@media (max-width: 767.98px) {

  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #DCE6E9 transparent;
    border-radius: 12px;
  }

  .table-responsive::-webkit-scrollbar { height: 4px; }
  .table-responsive::-webkit-scrollbar-thumb {
    background: #DCE6E9;
    border-radius: 2px;
  }

  /* Scroll interno del card de reservas */
  .adm-card > div[style*="overflow-x"] {
    border-radius: 0 0 12px 12px;
  }
}


/* ════════════════════════════════════════════════════════════════
   6. FORMULARIO DE RESERVA — columna única en phones
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  /* Cada campo toma el 100% */
  .adm-row {
    gap: 10px;
  }

  .adm-field {
    flex: 1 1 100% !important;
    min-width:  unset !important;
    max-width:  unset !important;
    width: 100% !important;
  }

  /* Inputs con 44 px de alto para touch */
  .ad-input,
  .ad-select,
  .ad-number {
    padding: 12px 11px;
    font-size: .92rem;
    min-height: 44px;
  }

  .ars-input {
    padding: 12px 11px;
    min-height: 44px;
  }

  /* Cotización ARS */
  .ars-cotiz { width: 80px !important; }

  /* Card del formulario — menos padding */
  .adm-form-card {
    padding: 14px 12px;
    margin-bottom: 14px;
  }

  /* Botones del formulario — ancho completo */
  .adm-btn-g,
  .adm-btn-c {
    display: block;
    width: 100%;
    text-align: center;
    padding: 13px 16px;
    font-size: .95rem;
    min-height: 48px;
    border-radius: 10px;
  }

  .adm-btn-c { margin-top: 8px; }
}


/* ════════════════════════════════════════════════════════════════
   7. BARRA DE BÚSQUEDA Y FILTROS
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .adm-search {
    padding: 12px;
    margin-bottom: 8px;
  }

  .adm-search-row {
    gap: 8px;
  }

  /* Todos los filtros ocupan 100% */
  .adm-sf {
    flex: 1 1 100%;
    min-width: unset;
  }

  .adm-sf input,
  .adm-sf select {
    padding: 11px;
    min-height: 44px;
    font-size: .92rem;
  }

  /* Botón "Buscar" ancho completo */
  .adm-search-row .adm-btn-g,
  .adm-search-row .hh-btn--primary {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }
}


/* ════════════════════════════════════════════════════════════════
   8. KPI CARDS — 2 columnas en phones (no 1)
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

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

  .hh-kpi {
    padding: 11px 12px;
    gap: 10px;
    border-radius: 10px;
  }

  .hh-kpi-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: .95rem;
  }

  .hh-kpi-val { font-size: 1rem; }
  .hh-kpi-lbl { font-size: .58rem; }
  .hh-kpi-sub { font-size: .62rem; }
}


/* ════════════════════════════════════════════════════════════════
   9. PAGE HEADER — compacto en phones
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .hh-ph         { margin-bottom: 14px; }
  .hh-ph-row     { gap: 8px; margin-bottom: 12px; }
  .hh-ph-title   { font-size: 1.25rem; }
  .hh-ph-sub     { font-size: .78rem; }
  .adm-ph-title  { font-size: 1.3rem; }

  .hh-ph-actions {
    width: 100%;
    gap: 8px;
  }

  .hh-ph-actions .hh-btn {
    flex: 1;
    justify-content: center;
    min-height: 40px;
  }
}


/* ════════════════════════════════════════════════════════════════
   10. BOTONES — touch targets universales
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 767.98px) {

  /* Botones principales */
  .btn,
  .hh-btn {
    min-height: 40px;
  }

  /* Acciones inline en tablas — más fácil de tocar */
  .table .btn {
    min-height: 34px;
    padding: .38rem .7rem;
  }

  form[method="post"] button[name="handler"] {
    min-height: 36px;
    padding: .42rem .78rem;
  }
}


/* ════════════════════════════════════════════════════════════════
   11. CALENDARIO — controles, stats, grilla
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  /* Controles */
  .hh-cal-controls {
    padding: 10px 12px;
    gap: 10px;
  }

  .hh-cal-prop-select { min-width: 100%; }

  .hh-cal-nav {
    width: 100%;
    justify-content: space-between;
  }

  .hh-cal-nav-label {
    min-width: 120px;
    font-size: .88rem;
  }

  .hh-cal-btn {
    min-width: 38px;
    min-height: 38px;
  }

  /* Stats — 2 columnas */
  .hh-cal-stats { gap: 8px; }

  .hh-cal-stat {
    min-width: calc(50% - 4px);
    padding: 10px 12px;
  }

  .hh-cal-stat-val { font-size: 1.1rem; }

  /* Grilla de días — scroll horizontal */
  .hh-cal-grid-wrap { padding: 10px 8px; }

  .hh-cal-grid {
    grid-template-columns: repeat(7, minmax(78px, 1fr));
    min-width: 546px;
  }

  .hh-cal-day {
    min-height: 72px;
    padding: 4px 5px;
  }
}


/* ════════════════════════════════════════════════════════════════
   12. FORMULARIOS BOOTSTRAP — inputs y checks
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .form-control,
  .form-select {
    padding: 11px .85rem;
    min-height: 44px;
    font-size: .95rem;
  }

  .form-label {
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 4px;
  }

  /* Checkboxes / radio más tocables */
  .form-check {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 0;
  }

  .form-check-input {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin: 0;
    cursor: pointer;
  }

  /* Columnas Bootstrap — stack completo */
  .row > .col-md-3,
  .row > .col-md-4,
  .row > .col-md-6,
  .row > .col-lg-3,
  .row > .col-lg-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}


/* ════════════════════════════════════════════════════════════════
   13. OWNER PAGE — propietario
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .owner-page .summary-card {
    padding: 12px 14px;
    border-radius: 14px;
  }

  .owner-page .summary-title      { font-size: 1rem; }
  .owner-page .summary-rendir-amount { font-size: 1.45rem; }
  .owner-page .summary-kv         { margin-right: .8rem; }
}


/* ════════════════════════════════════════════════════════════════
   14. SUPERFICIES — hh-surface / hh-card / adm-card
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .hh-surface    { border-radius: 10px; }
  .hh-surface-hd { padding: 10px 14px; }
  .hh-surface-bd { padding: 14px; }

  .hh-card        { border-radius: 14px; }
  .hh-card-header { padding: 12px 14px; }
  .hh-card-body   { padding: 14px; }

  .adm-card    { border-radius: 10px; }
  .adm-card-hd {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 6px;
  }
}


/* ════════════════════════════════════════════════════════════════
   15. TABLAS HH-TBL — comisiones, gastos, etc.
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .hh-tbl th {
    font-size: .6rem;
    padding: 7px 10px;
    white-space: nowrap;
  }

  .hh-tbl td {
    font-size: .79rem;
    padding: 7px 10px;
  }

  .hh-tbl-total td,
  .hh-tbl-subtotal td {
    font-size: .77rem;
  }

  /* Tablas Bootstrap — mismo tratamiento */
  .table {
    font-size: .82rem;
    border-radius: 12px;
  }

  .table > :not(caption) > * > * {
    padding: .38rem .48rem;
  }

  .table thead th {
    font-size: .68rem;
  }
}


/* ════════════════════════════════════════════════════════════════
   16. BOTTOM NAVIGATION — acceso rápido en phones
   ════════════════════════════════════════════════════════════════ */

.mobile-bottom-nav {
  display: none; /* oculto por defecto, activa CSS en phones */
}

@media (max-width: 767.98px) {

  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* Altura base + safe area para iPhone con notch */
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--hh-dark, #1E3F4E);
    border-top: 1px solid rgba(255,255,255,.07);
    align-items: stretch;
    justify-content: space-around;
    z-index: 1100;
    box-shadow: 0 -4px 20px rgba(0,0,0,.2);
  }

  .mbn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 3px;
    text-decoration: none !important;
    color: rgba(255, 255, 255, .5);
    transition: color .15s ease;
    min-height: 44px;
    padding: 6px 2px;
    cursor: pointer;
    position: relative;
    border: none;
    background: transparent;
    font-family: 'Space Grotesk', sans-serif;
  }

  .mbn-item.active,
  .mbn-item:hover,
  .mbn-item:focus {
    color: #ffffff;
    text-decoration: none !important;
  }

  /* Indicador activo — línea superior */
  .mbn-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 18%;
    right: 18%;
    height: 2px;
    background: var(--hh-olive, #5BA4B0);
    border-radius: 0 0 3px 3px;
  }

  .mbn-icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .mbn-icon svg {
    width: 22px;
    height: 22px;
    display: block;
  }

  .mbn-label {
    font-size: .57rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    line-height: 1;
    display: block;
  }
}


/* ════════════════════════════════════════════════════════════════
   17. PROMOCIONES — form
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  /* Grid de propiedades — 2 columnas */
  .promo-props-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px;
  }
}


/* ════════════════════════════════════════════════════════════════
   18. ALOJAMIENTOS — ocultar columnas OTA en phones
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 575.98px) {

  .table th.aloj-ota-col,
  .table td.aloj-ota-col {
    display: none;
  }
}


/* ════════════════════════════════════════════════════════════════
   19. UTILIDADES MOBILE
   ════════════════════════════════════════════════════════════════ */

/* Visibilidad selectiva */
.d-mobile-none   { display: none !important; }
.d-mobile-block  { display: block !important; }
.d-mobile-flex   { display: flex !important; }

@media (min-width: 768px) {
  .d-mobile-none  { display: block !important; }
  .d-mobile-block { display: none !important; }
  .d-mobile-flex  { display: none !important; }
}

/* Tipografía mobile */
@media (max-width: 575.98px) {
  .text-mobile-sm { font-size: .8rem !important; }
  .text-mobile-xs { font-size: .72rem !important; }
}

/* Ancho completo en phones */
@media (max-width: 575.98px) {
  .w-mobile-full { width: 100% !important; }
}


/* ════════════════════════════════════════════════════════════════
   8. CALENDARIO GANTT — mobile
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 991.98px) {

  /* Encabezado de página: título arriba, controles abajo */
  .hh-cal-page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
  }
  .hh-cal-page-head > div:first-child .hh-ph-eye { font-size: .58rem; }
  .hh-cal-page-head > div:first-child [style*="font-size:1.5rem"] {
    font-size: 1.15rem !important;
  }
  .hh-cal-head-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
  }
  /* Ocultar el resumen de noches/ocupación en mobile (ocupa demasiado) */
  .hh-cal-summary { display: none; }

  /* Contenedor principal — altura adaptada */
  .hh-gcal-outer {
    height: calc(100dvh - 180px);
    min-height: 280px;
    /* NO usar -webkit-overflow-scrolling:touch → rompe position:sticky en iOS */
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scrollbar-gutter: auto;
  }
  .hh-gcal-outer::-webkit-scrollbar { display: none; }

  /* Barra de scroll horizontal inferior — más discreta en mobile */
  .hh-gcal-xscroll {
    height: 4px;
    margin-top: 3px;
    border-radius: 2px;
    overflow: hidden;
  }
  .hh-gcal-xscroll > div { height: 4px; }

  /* Celdas de días y contenedor: touch-action para scroll libre */
  .hh-gcal-days-cont {
    touch-action: pan-x pan-y;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Nombre de propiedad más compacto */
  .hh-gcal-prop-name { font-size: .65rem; }
  .hh-gcal-prop-icon { width: 24px; height: 24px; font-size: .7rem; border-radius: 6px; }

  /* Botón compacto — ocultar en mobile (siempre está en modo compacto) */
  #gcal-compact-btn { display: none; }
}

/* Phones pequeños — aún más compacto */
@media (max-width: 575.98px) {
  .hh-cal-page-head > div:first-child [style*="font-size:1.5rem"] {
    font-size: 1rem !important;
  }
  .hh-gcal-outer {
    height: calc(100dvh - 160px);
  }
}
