/* MKV_MOBILE_154 (2026-12-04): CRM en teléfonos. Todo va dentro de @media (max-width:780px):
   en el ordenador y en el iPad no cambia nada. La barra inferior y la hoja «Más» las crea mobile154.js. */
#m154bar,#m154sheet,#m154back,#m154fab{display:none}
@media (max-width:780px){
  html{-webkit-text-size-adjust:100%}
  body{font-size:16px;padding-bottom:calc(74px + env(safe-area-inset-bottom))}
  /* El menú lateral se sustituye por la barra inferior */
  body.m154 .layout>.sidebar{display:none!important}
  body.m154 .layout{display:block}
  #connectionNote{font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-top:4px;padding-bottom:4px}

  /* Barra inferior */
  body.m154 #m154bar{display:flex;position:fixed;left:0;right:0;bottom:0;z-index:9;background:#10283a;
    padding:4px 4px calc(4px + env(safe-area-inset-bottom));box-shadow:0 -4px 18px #00000030}
  #m154bar button{flex:1 1 0;min-width:0;min-height:56px;border:0;background:none;color:#b9cad6;font-family:inherit;font-size:11px;font-weight:600;line-height:1.1;
    display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;border-radius:12px;position:relative;
    padding:4px 2px;-webkit-tap-highlight-color:transparent;cursor:pointer}
  #m154bar button svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
  #m154bar button.on{color:#fff;background:#ffffff1a}
  #m154bar button.on svg{stroke:#f08a3c}
  body.m154sheet-open #m154bar button.on:not(.open){background:none;color:#b9cad6}
  body.m154sheet-open #m154bar button.on:not(.open) svg{stroke:currentColor}
  #m154bar button.open{color:#fff;background:#ffffff26}
  #m154bar button.open svg{stroke:#f08a3c}
  #m154bar button[hidden]{display:none}
  #m154bar .m154n{position:absolute;top:3px;left:calc(50% + 6px);min-width:18px;height:18px;padding:0 5px;border-radius:9px;
    background:#d63b3b;color:#fff;font-size:11px;line-height:18px;font-weight:700}
  #m154bar .m154n:empty{display:none}

  /* Hoja que sube desde abajo */
  body.m154 #m154back{position:fixed;inset:0;background:#0923338c;z-index:11;opacity:0;pointer-events:none;transition:opacity .2s;display:block}
  body.m154 #m154sheet{display:block;position:fixed;left:0;right:0;bottom:0;z-index:12;background:#fff;border-radius:20px 20px 0 0;
    max-height:82vh;overflow-y:auto;-webkit-overflow-scrolling:touch;transform:translateY(105%);transition:transform .25s ease;
    padding:8px 14px calc(16px + env(safe-area-inset-bottom));box-shadow:0 -10px 40px #00000040}
  /* Con la hoja abierta la barra sigue visible encima, para cambiar de pestaña */
  body.m154 #m154sheet{bottom:calc(64px + env(safe-area-inset-bottom));max-height:calc(100vh - 140px);
    transform:translateY(calc(100% + 100px + env(safe-area-inset-bottom)));visibility:hidden;transition:transform .25s ease,visibility 0s .25s}
  body.m154sheet-open #m154sheet{visibility:visible;transition:transform .25s ease}
  body.m154sheet-open #m154bar{z-index:13}
  body.m154sheet-open #m154back{opacity:1;pointer-events:auto}
  body.m154sheet-open #m154sheet{transform:none}
  body.m154sheet-open{overflow:hidden}
  #m154sheet .m154grip{width:44px;height:5px;border-radius:3px;background:#cfd9df;margin:4px auto 10px}
  #m154sheet h3{margin:4px 4px 10px;font-size:20px;color:#10283a}
  #m154sheet h4{margin:16px 4px 6px;font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:#6b808b}
  #m154sheet .m154item{display:flex;align-items:center;gap:10px;width:100%;min-height:52px;padding:10px 14px;margin:0 0 6px;
    border:1px solid #e1e9ee;border-radius:12px;background:#f6f9fb;color:#10283a;font-family:inherit;font-size:16px;font-weight:600;line-height:1.2;text-align:left;cursor:pointer}
  #m154sheet .m154item.on{border-color:#17394b;background:#e6f0f5}
  #m154sheet .m154item.create{color:#b5541c;background:#fff5ee;border-color:#f6d9c4}
  #m154sheet .m154item>span:not([hidden]){margin-left:auto}
  /* «Fichar» siempre a mano: botón naranja encima de la barra, y el primero de la hoja Personal */
  body.m154.m154fab-on #m154fab{display:flex;align-items:center;gap:8px;position:fixed;right:14px;bottom:calc(76px + env(safe-area-inset-bottom));
    z-index:8;min-height:52px;padding:0 20px 0 16px;border:0;border-radius:26px;background:#e8710a;color:#fff;font-family:inherit;
    font-size:16px;font-weight:700;box-shadow:0 6px 18px #00000040;cursor:pointer;-webkit-tap-highlight-color:transparent}
  #m154fab svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}
  body.m154.m154fab-on{padding-bottom:calc(140px + env(safe-area-inset-bottom))}
  body.m154sheet-open #m154fab{display:none!important}
  #m154sheet .m154item.fichar{background:#e8710a;border-color:#e8710a;color:#fff;min-height:58px;font-size:18px}
  #m154sheet .m154close{display:block;width:100%;min-height:48px;margin-top:10px;border:0;border-radius:12px;background:#10283a;color:#fff;font-family:inherit;font-size:16px;font-weight:700}

  /* Campos: letra de 16 px (el iPhone no hace zoom) y sin salirse por la derecha */
  input:not([type=checkbox]):not([type=radio]):not([type=range]),select,textarea{font-size:16px!important;max-width:100%}
  #main select,#main input:not([type=checkbox]):not([type=radio]),#main textarea{max-width:100%;box-sizing:border-box}
  #main input[type=date],#main input[type=time],#main input[type=datetime-local],#main input[type=month],
  .modal input[type=date],.modal input[type=time],.modal input[type=month]{min-height:44px}
  /* Botones de tamaño dedo */
  #main .btn,.modal .btn,#main select,.modal select{min-height:44px}
  .header-actions .btn{min-height:40px}
  #main input[type=checkbox],#main input[type=radio],.modal input[type=checkbox],.modal input[type=radio]{width:22px;height:22px}

  /* Formularios en una columna */
  .editgrid,.ag114-form,.ex83-sign,.ex83-adv,.ex83-staff,.oc-form-grid,.oc-specs,.oc-price-inputs{grid-template-columns:minmax(0,1fr)!important}
  .editgrid>*,.ag114-form>*{grid-column:1/-1!important}

  /* Ventanas = hojas a pantalla completa con Guardar/Cancelar fijos abajo */
  .modal-backdrop{padding:0!important;align-items:stretch!important}
  .modal{width:100%!important;max-width:none!important;max-height:none!important;height:100%;border-radius:0!important;
    padding:18px 16px 0!important;display:flex;flex-direction:column}
  .modal>form{display:flex;flex-direction:column;flex:1 0 auto}
  .modalfoot{position:sticky;bottom:0;z-index:3;background:#fff;margin:auto -16px 0!important;padding:12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top:1px solid #e3eaee;box-shadow:0 -6px 16px #0000000f}
  .modalfoot .btn{flex:1 1 0;min-height:48px;font-size:16px}
  /* Las ventanas de los módulos (<dialog>, nueva cita, enviar por correo): igual, a pantalla completa */
  dialog[open]{position:fixed;inset:0;width:100%!important;max-width:none!important;height:100%;max-height:none!important;margin:0;
    border:0!important;border-radius:0!important;padding:16px 16px 0!important;box-sizing:border-box;overflow-y:auto}
  .ag114-ov,.sh113-ov{padding:0!important;align-items:stretch!important}
  .ag114-box,.sh113-box{max-width:none!important;max-height:none!important;min-height:100%;border-radius:0!important;padding:16px 16px 0!important;box-sizing:border-box}
  .sh113-box{overflow:visible!important}
  .ag114-box,.sh113-box{display:flex;flex-direction:column}
  .ag114-box>.ag114-acts,.sh113-box>.sh113-acts{margin-top:auto!important}
  .sh113-ov{overflow:auto}
  dialog .foot,dialog .lk81-foot,dialog .oc-dialog-footer,dialog[open] .actions:last-child,.ag114-acts,.sh113-acts{position:sticky;bottom:0;z-index:3;
    display:flex;flex-wrap:wrap;gap:8px;background:#fff;margin:16px -16px 0!important;padding:12px 16px calc(12px + env(safe-area-inset-bottom))!important;
    border-top:1px solid #e3eaee;box-shadow:0 -6px 16px #0000000f}
  dialog .foot button,dialog .lk81-foot button,dialog .oc-dialog-footer button,dialog[open] .actions:last-child button,.ag114-acts button,.sh113-acts button{min-height:48px;flex:1 1 auto;font-size:16px}
  .ag114-acts .left{margin-right:0}
  .ag114-dur button{min-height:40px;padding-left:12px;padding-right:12px;font-size:15px}
  dialog .oc-dialog-head button[data-close],dialog [data-close]:not(.foot *){min-width:44px;min-height:44px}
  /* Aviso emergente del calendario: encima de la barra inferior */
  .ag98-pop{left:12px;right:12px!important;bottom:calc(80px + env(safe-area-inset-bottom))!important;max-width:none!important}

  /* Tablas: anchas → se deslizan dentro de su caja; normales → tarjetas (mobile154.js pone data-label) */
  #main .m154wrap{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
  #main table.m154cards,#main table.m154cards tbody,#main table.m154cards tfoot{display:block;width:auto!important;min-width:0!important}
  #main table.m154cards thead,#main table.m154cards tr.m154head{display:none!important}
  #main table.m154cards tr{display:grid;grid-template-columns:1fr 1fr;gap:6px 12px;border:1px solid #e1e9ee;border-radius:12px;padding:10px 12px;margin:0 0 10px;background:#fff}
  #main table.m154cards td,#main table.m154cards th{display:block;width:auto!important;height:auto!important;border:0!important;padding:0!important;
    text-align:left!important;min-width:0;position:static!important;white-space:normal!important;background:none!important}
  #main table.m154cards tr>:first-child,#main table.m154cards tr>:only-child{grid-column:1/-1;font-weight:700;font-size:16px}
  #main table.m154cards tr>:first-child::before{display:none!important}
  #main table.m154cards td[data-label]:not([data-label=""])::before{content:attr(data-label);display:block;font-size:12px;font-weight:700;color:#6b808b;text-transform:uppercase;letter-spacing:.04em}

  /* Selectores a todo el ancho: nunca ensanchan la página */
  #main select{width:100%;min-width:0}
  .pd150-bar,.fc-bar,.ex83-bar,.ag98-bar{flex-wrap:wrap;min-width:0;max-width:100%}
  .pd150-bar>*,.fc-bar>*{min-width:0;max-width:100%}

  /* Personal (Documentos, Fichaje) */
  .pd150-row a,.pd150-row button,#main .fc-b{min-height:44px;display:inline-flex;align-items:center;justify-content:center}
  .pd150-row{flex-wrap:wrap}

  /* Calendarios (Home, Comercial, SAT): la barra de filtros no puede ensanchar la página */
  .ag98-head>*,.ag98-bar{min-width:0;max-width:100%}
  .ag98-bar>*{max-width:100%;min-width:0}

  /* Campos y botones de tamaño dedo en todos los apartados */
  #main input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),
  .modal input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]){min-height:44px}
  .cv131-seg button,.ex83-add button{min-height:44px;padding-left:14px;padding-right:14px}
  /* Filtros de Gestiones / calendarios: etiqueta encima y campo a lo ancho */
  .ag98-bar label:not(:has(input[type=checkbox])){display:flex;flex-direction:column;align-items:stretch;gap:4px;flex:1 1 140px;font-size:14px;font-weight:600}
  .ag98-bar label input,.ag98-bar label select{width:100%}
  .ag98-bar label:has(input[type=checkbox]){display:flex;align-items:center;gap:10px;min-height:44px}

  /* Lista de clientes: cada cliente es una tarjeta (sin deslizar de lado); lo vacío («—») no se muestra */
  .cd55-list .cd55-head{display:none!important}
  .cd55-list .cd55-row{display:flex!important;flex-wrap:wrap;gap:3px 12px;min-width:0!important;width:100%!important;text-align:left}
  .cd55-row>span{min-width:0;font-size:13px;line-height:1.3}
  .cd55-company small{display:block;white-space:normal;overflow-wrap:anywhere}
  .cd55-row>.cd55-company,.cd55-row>span:nth-child(2){flex:1 0 100%}
  .cd55-row>span:nth-child(2){color:#4e6874;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .cd55-row>span:nth-child(3)::before{content:"Incidencias: ";font-weight:700}
  .cd55-row>span:nth-child(4)::before{content:"Pedidos: ";font-weight:700}
  .cd55-row>span:nth-child(5)::before{content:"Ofertas: ";font-weight:700}
  .cd55-row>span.m154empty{display:none}
  /* Cabeceras (ficha de cliente, listas): título arriba y botones debajo, a lo ancho */
  #main .intro{flex-wrap:wrap}
  #main .intro>.actions{flex:1 1 100%}
}
