/* Modo "app" para celular (Android / iPhone): barra superior compacta, barra
   inferior con las secciones principales, hoja "Más" con todo el menú y
   tablas convertidas en tarjetas. Solo aplica a pantallas de celular
   (hasta 600 px); en tablet, iPad y computadora no cambia nada. */

/* Fuera del celular, estas piezas no existen. */
.tabbar,
.hoja-mas,
.hoja-mas-fondo,
.appbar-usuario { display: none; }

@media (max-width: 600px) {
  html { -webkit-text-size-adjust: 100%; }
  body {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  body.con-tabbar { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }

  /* --- Barra superior compacta --- */
  nav.topbar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    min-height: 52px;
    padding: calc(0.4rem + env(safe-area-inset-top)) 0.9rem 0.4rem;
  }
  nav.topbar .links { display: none; }
  nav.topbar .brand { font-size: 1rem; gap: 0.5rem; min-width: 0; }
  nav.topbar .brand .brand-logo { width: 30px; height: 30px; }
  .appbar-usuario {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: #d9f4f0;
    color: #0f766e;
    font: inherit;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
  }

  /* --- Barra inferior --- */
  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    height: calc(60px + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.96);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--gris-borde);
    box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.06);
  }
  .tabbar .tab {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: transparent;
    padding: 6px 2px 4px;
    color: #667085;
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }
  .tabbar .tab:active { transform: scale(0.94); }
  .tabbar .tab.activa { color: #0f766e; }
  .tab-i {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .tab-icono-wrap { position: relative; display: inline-flex; }
  .tab-badge {
    position: absolute;
    top: -5px;
    right: -9px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 9px;
    background: #e11d48;
    color: #fff;
    font-size: 0.64rem;
    font-weight: 700;
    display: grid;
    place-items: center;
    box-sizing: border-box;
  }
  /* "Nueva consulta" destacada al centro */
  .tabbar .tab-principal .tab-mas-circulo {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-top: -16px;
    border-radius: 50%;
    background: #0f766e;
    color: #fff;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.4);
  }
  .tabbar .tab-principal { color: #0f766e; }
  .tabbar .tab-principal .tab-i { stroke-width: 2.2; }

  /* El botón flotante del chat sobra: el chat está en la barra inferior. */
  body.con-tabbar .cx-fab { display: none; }
  body.con-tabbar .ios-install-banner { bottom: calc(60px + env(safe-area-inset-bottom)); }

  /* --- Hoja "Más" (menú completo) --- */
  .hoja-mas-fondo {
    position: fixed;
    inset: 0;
    z-index: 950;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .hoja-mas-fondo:not([hidden]) { display: block; }
  .hoja-mas-fondo.visible { opacity: 1; }
  .hoja-mas {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 960;
    max-height: 86vh;
    max-height: 86dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.25);
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .hoja-mas:not([hidden]) { display: block; }
  .hoja-mas.visible { transform: none; }
  .hoja-asa {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #d0d5dd;
    margin: 4px auto 12px;
  }
  .hoja-usuario {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 4px 14px;
    border-bottom: 1px solid var(--gris-borde);
  }
  .hoja-usuario .appbar-av {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: #d9f4f0;
    color: #0f766e;
    font-weight: 700;
  }
  .hoja-usuario b { display: block; font-size: 1rem; }
  .hoja-usuario small { color: var(--texto-suave); font-size: 0.8rem; }
  .hoja-grupo-titulo {
    margin: 16px 4px 6px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--texto-suave);
  }
  .hoja-enlaces {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .hoja-enlaces a {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 10px 14px;
    border: 1px solid var(--gris-borde);
    border-radius: 12px;
    background: #f8fafc;
    color: #101828;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    box-sizing: border-box;
  }
  .hoja-enlaces a:active { background: #e6f4f1; }
  .hoja-acciones { display: grid; gap: 8px; margin-top: 18px; }
  .hoja-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border-radius: 12px;
    border: 1px solid var(--gris-borde);
    background: #fff;
    color: #101828;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }
  .hoja-btn.instalar { background: #0f766e; border-color: #0f766e; color: #fff; }
  .hoja-btn.salir { color: #b42318; }
  body.hoja-abierta { overflow: hidden; }

  /* --- Formularios y botones más cómodos para el dedo --- */
  input[type="text"], input[type="search"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="password"], input[type="date"], input[type="time"],
  input[type="datetime-local"], select, textarea {
    font-size: 16px; /* evita el zoom automático al enfocar un campo */
    min-height: 44px;
  }
  .btn, button.btn, a.btn { min-height: 44px; }
  /* Buscadores: el cuadro de texto ocupa todo el ancho y lo demás baja. */
  .search-bar { flex-wrap: wrap; }
  .search-bar input[type="text"] { flex: 1 1 100%; min-width: 0; }
  .search-bar select { flex: 1 1 0; min-width: 0; max-width: none !important; }
  .search-bar .btn { flex: 0 0 auto; }
  .container { padding: 0.9rem 0.9rem 1.2rem; }

  /* --- Tablas convertidas en tarjetas (ver movil.js) --- */
  .table-scroll { overflow: visible; margin: 0; padding: 0; }
  .table-scroll table.tabla-tarjetas { min-width: 0; }
  table.tabla-tarjetas,
  table.tabla-tarjetas tbody { display: block; width: 100%; }
  table.tabla-tarjetas thead { display: none; }
  table.tabla-tarjetas tr {
    display: block;
    margin: 0 0 10px;
    padding: 10px 14px;
    border: 1px solid var(--gris-borde);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }
  table.tabla-tarjetas td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 5px 0;
    border: 0;
    text-align: right;
    font-size: 0.9rem;
    word-break: break-word;
  }
  table.tabla-tarjetas td::before {
    content: attr(data-label);
    flex-shrink: 0;
    color: var(--texto-suave);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    text-align: left;
  }
  table.tabla-tarjetas td:first-child {
    display: block;
    padding: 2px 0 6px;
    text-align: left;
    font-size: 1rem;
    font-weight: 700;
  }
  table.tabla-tarjetas td:first-child::before { display: none; }
  table.tabla-tarjetas td.sin-etiqueta { justify-content: flex-end; }
  table.tabla-tarjetas td.sin-etiqueta::before { display: none; }
  table.tabla-tarjetas td.vacio { display: none; }
  table.tabla-tarjetas td .btn-row { justify-content: flex-end; flex-wrap: wrap; }
}

/* App instalada (abierta desde el ícono, sin barra del navegador). */
@media (display-mode: standalone) {
  html { overscroll-behavior-y: contain; }
  nav.topbar, .tabbar, .hoja-mas { -webkit-user-select: none; user-select: none; }
}
