/* CRM Campsa en celular y tablet: barra de pestañas abajo como app, leads como tarjetas,
   ficha a pantalla completa y nada se sale del ancho de la pantalla. */
#barraMovil, #tabbar, #btnFiltros { display: none; }
.filtrosLeads { display: contents; }
@media (max-width: 820px) {
  /* Sin scroll de lado, pero que la que se deslice sea la página y no el <body>: con «overflow-x:hidden» en los dos,
     el body se volvía una caja con scroll propio (en iPhone no se escondía la barra de Safari ni se regresaba arriba al cambiar de vista) */
  html { overflow-x: hidden; }
  body { overflow-x: hidden; overflow-x: clip; }
  input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea { font-size: 16px !important; }  /* sin zoom automático en iPhone */
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; align-content: start; }
  #barraMovil { align-self: start; }
  aside { display: none !important; }
  main { padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); min-width: 0; }
  h2 { font-size: 20px; }
  .sub { font-size: 13px; margin-bottom: 12px; }

  /* Barra de arriba */
  #barraMovil { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 15; background: var(--negro); color: #fff;
    padding: max(10px, env(safe-area-inset-top)) 14px 10px; }
  #barraMovil img { height: 26px; }
  #barraMovil b { flex: 1; font-size: 15px; font-weight: 600; color: var(--oro2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #barraMovil button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff; font-weight: 700; cursor: pointer; }

  /* Pestañas abajo */
  #tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: #fff; border-top: 1px solid var(--linea); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgba(0,0,0,.06); }
  #tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; border: 0; background: none; color: #8a8579; font-size: 11px; font-weight: 600; padding: 4px 0; cursor: pointer; }
  #tabbar button svg { width: 24px; height: 24px; }
  #tabbar button.act { color: #9a7424; }
  #tabbar button.act svg { stroke-width: 2.2; }
  #tabbar .globo { position: absolute; top: 0; left: calc(50% + 6px); margin: 0; font-size: 10px; min-width: 17px; padding: 0 5px; }
  body.wa-pantalla #tabbar, body.wa-pantalla #barraMovil, body.ficha-abierta #tabbar { display: none; }

  /* Hoja "Más" */
  .hojaMas { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; }
  .hojaMas > div { width: 100%; background: #fff; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    max-height: 88vh; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; }
  .hojaMas .quien { padding: 4px 4px 12px; border-bottom: 1px solid var(--linea); margin-bottom: 6px; }
  .hojaMas .quien b { display: block; font-size: 16px; }
  .hojaMas button.op { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; padding: 13px 6px; font-size: 15.5px; font-weight: 500; text-align: left; border-radius: 10px; cursor: pointer; }
  .hojaMas button.op:active { background: #f4f2ec; }
  .hojaMas button.op svg { width: 22px; height: 22px; color: #9a7424; }

  /* Resumen del semáforo: tarjetas compactas que se deslizan */
  .tarjetas { display: flex; overflow-x: auto; gap: 8px; margin: 0 -14px 12px; padding: 2px 14px; scrollbar-width: none; }
  .tarjetas::-webkit-scrollbar { display: none; }
  .tarjetas .tarjeta { flex: none; min-width: 118px; padding: 10px 12px; }
  .tarjeta b { font-size: 22px; }

  /* Filtros: buscador siempre; lo demás detrás de "Filtros" */
  .barra { gap: 8px; }
  .barra input[type=search] { max-width: none; flex: 1 1 100%; }
  .filtrosLeads { display: none; width: 100%; gap: 8px; grid-template-columns: 1fr 1fr; }
  .filtrosLeads.ver { display: grid; }
  .filtrosLeads select { width: 100%; }
  #btnFiltros { display: inline-flex !important; }
  .barra .espacio { display: none; }

  /* Leads como tarjetas */
  .tabla:has(#filas) { border: 0; background: none; box-shadow: none; overflow: visible; }
  .tabla:has(#filas) table { min-width: 0; }
  .tabla { -webkit-overflow-scrolling: touch; }
  #filas tr[data-id] { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; column-gap: 6px; row-gap: 6px; background: #fff;
    border: 1px solid var(--linea); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--sombra); }
  #filas tr[data-id] td { padding: 0; border: 0; }
  #filas tr[data-id] td:nth-child(2) { grid-column: 1 / 4; grid-row: 1; min-width: 0; }
  #filas tr[data-id] td:nth-child(2) b { font-size: 15.5px; }
  #filas tr[data-id] td:nth-child(1) { grid-column: 4; grid-row: 1; text-align: right; font-size: 12.5px; white-space: nowrap; }
  #filas tr[data-id] td:nth-child(3) { grid-column: 1; grid-row: 2; }
  #filas tr[data-id] td:nth-child(4) { grid-column: 2; grid-row: 2; }
  #filas tr[data-id] td:nth-child(6) { grid-column: 3 / 5; grid-row: 2; text-align: right; font-size: 12.5px; color: var(--suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #filas tr[data-id] td.ocultaMovil { display: none; }
  .tabla:has(#filas) thead { display: none; }
  #filas tr:not([data-id]) td { display: block; background: #fff; border-radius: 14px; }

  /* Ficha del lead a pantalla completa */
  .ficha { width: 100%; overscroll-behavior: contain; padding: calc(14px + env(safe-area-inset-top)) 14px calc(30px + env(safe-area-inset-bottom)); box-shadow: none; }
  .ficha h3 { font-size: 19px; padding-right: 40px; }
  .ficha .cerrar { width: 40px; height: 40px; border-radius: 50%; background: #fff; border: 1px solid var(--linea); top: calc(10px + env(safe-area-inset-top)); right: 12px; font-size: 18px; }
  .ficha .caja .botones .btn, .ficha #fAct .btn.oro { flex: 1 1 auto; padding: 12px 14px; font-size: 15px; text-align: center; }
  .prop .acciones button { font-size: 13px; padding: 7px 10px; }
  .ag-item { grid-template-columns: 50px 1fr; } .ag-acc { grid-column: 1 / -1; justify-content: flex-start; }

  /* Indicadores, Equipo y Ajustes */
  .graficas { grid-template-columns: minmax(0, 1fr); }
  .barritas div { grid-template-columns: 96px 1fr 36px; }
  .horario { grid-template-columns: 70px minmax(0, 1fr) minmax(0, 1fr); }
  .horario input { min-width: 0; padding-left: 8px; padding-right: 4px; }   /* las horas no se salen de la pantalla */
  .modal { align-items: end; padding: 0; }
  .modal > div { border-radius: 18px 18px 0 0; max-height: 92vh; max-height: 92dvh; overscroll-behavior: contain; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }

  /* WhatsApp entre las dos barras */
  main:has(> #vista.wa-main) { padding: 0 0 calc(64px + env(safe-area-inset-bottom)) !important; }
  #vista.wa-main .wa { height: calc(100vh - var(--alto-barra, 52px) - var(--alto-tabs, 64px)); height: calc(100dvh - var(--alto-barra, 52px) - var(--alto-tabs, 64px)); border-radius: 0; }

  /* Propiedades y 360: el panel ocupa justo el espacio entre las dos barras y la página de atrás no se mueve
     (antes el panel y la página se deslizaban juntos y se perdía uno) */
  body[data-vista="propiedades"] { overflow: hidden; overscroll-behavior: none; }
  html:has(> body[data-vista="propiedades"]), html:has(> body.wa-pantalla) { overflow: hidden; overscroll-behavior: none; }
  body[data-vista="propiedades"] main { padding: 0 !important; }
  body[data-vista="propiedades"] #vista > .barra { display: none; }
  body[data-vista="propiedades"] iframe.panel { position: fixed; left: 0; right: 0; width: 100%; top: var(--alto-barra, 52px);
    height: calc(100vh - var(--alto-barra, 52px) - var(--alto-tabs, 64px)); height: calc(100dvh - var(--alto-barra, 52px) - var(--alto-tabs, 64px));
    border: 0; border-radius: 0; z-index: 5; }
  .aviso { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .wa-busca input, .wa-titulo select { font-size: 16px; }                 /* sin zoom en iPhone */
  .ag-acc .btn.peq, .prop .acciones .btn, #agLista .btn.peq { min-height: 40px; padding: 8px 12px; } /* botones a tamaño de dedo */
  /* Botones chiquitos dentro del texto (copiar NID, nombres en Inconsistencias): más área para el dedo sin mover nada */
  .copiaNid, li > button[data-lead] { position: relative; }
  .copiaNid::after, li > button[data-lead]::after { content: ""; position: absolute; inset: -10px -4px; }
}
