/* =====================================================================================================
   Shelsy en el celular (≤ 820 px). Capa cargada al final: en computadora no cambia nada.
   · Arriba: logo + negocio activo. Abajo: barra con Chats, Agenda, Resultados y «Más».
   · La bandeja ocupa la pantalla; al tocar un chat se abre en su propia pantalla (← Volver) y la ficha
     del cliente sale como una hoja aparte (html.m-chat-open / html.m-details-open, mobile.js).
   ===================================================================================================== */
.m-tabbar, .m-sheet, .m-sheet-backdrop, .m-back, .m-info, .m-break, .m-details-head { display: none; }

/* Ventana «Avisos en este dispositivo» (push-ui.js), en computadora y celular */
.push-modal .modal-card { max-width: 460px; }
.push-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; color: var(--text); }
.push-status { font-weight: 600; margin: 4px 0; }
.push-actions { flex-wrap: wrap; gap: 8px; }
.push-sound { border-top: 1px solid var(--line); padding-top: 10px; }
.push-sound summary { cursor: pointer; font-weight: 600; color: var(--brand-text); }
.push-sound p { margin: 6px 0 0; }
/* «¿De qué negocios quieres avisos?»: por negocio y por tipo, en este dispositivo */
.push-choice:empty { display: none; }
.push-choice { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; }
.push-choice-head { display: grid; gap: 2px; }
.push-choice-bulk { display: flex; gap: 6px; flex-wrap: wrap; }
.push-choice-rows { display: grid; gap: 6px; max-height: 300px; overflow-y: auto; }
.push-biz { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px; padding: 6px 8px; border-radius: 10px; background: var(--surface-2); }
.push-biz.is-off .push-biz-main span { color: var(--muted); text-decoration: line-through; }
.push-biz-main { display: flex; align-items: center; gap: 8px; cursor: pointer; min-width: 0; }
.push-biz-main span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.push-biz-main small { white-space: nowrap; }
.push-kinds { grid-column: 1 / -1; display: grid; gap: 4px; padding: 4px 0 2px 26px; }
.push-kinds.hidden { display: none; }
.push-kind { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.push-saved:empty { display: none; }

@media (max-width: 820px) {
  :root { --m-tab-h: 60px; }
  html, body { overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; }
  input, select, textarea { font-size: 16px !important; } /* iPhone no hace zoom al escribir */

  /* ---------- Marco: barra superior compacta ---------- */
  .app { display: block !important; padding: 0 !important; padding-bottom: calc(var(--m-tab-h) + env(safe-area-inset-bottom)) !important; min-height: 100dvh; }
  .sidebar { position: sticky !important; top: 0; z-index: 40; display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; align-items: center; gap: 10px;
    width: 100% !important; max-width: 100% !important; height: auto !important; padding: 8px 12px !important; padding-top: calc(8px + env(safe-area-inset-top)) !important;
    border: 0 !important; border-bottom: 1px solid var(--sb-line) !important; border-radius: 0 !important; }
  .sidebar .brand { width: auto !important; margin: 0 !important; flex: none; }
  .sidebar .brand-logo { width: 34px !important; height: 34px !important; }
  .sidebar .brand-text, .sidebar .nav, .sidebar .side-actions, .sidebar .ws-switch label { display: none !important; }
  .sidebar .ws-switch { width: auto !important; flex: 1 1 auto; min-width: 0; margin: 0 !important; }
  .sidebar .ws-switch select { width: 100%; height: 40px; padding: 6px 12px; border-radius: 10px; }
  .content { padding: 12px 12px 18px !important; min-width: 0; }
  .topbar { display: none !important; } /* el negocio está arriba; el estado de conexiones, en «Más» */
  .toast { bottom: calc(var(--m-tab-h) + 14px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }

  /* ---------- Barra inferior ---------- */
  .m-tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    height: calc(var(--m-tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--sb-bg); border-top: 1px solid var(--sb-line); }
  .m-tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: transparent;
    color: var(--sb-muted); font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; min-width: 0; }
  .m-tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .m-tab.active { color: var(--sb-active-text); }
  .m-tab.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand-glow); }
  .m-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--orange); color: #1A0E02;
    font: 700 10.5px/18px var(--mono); text-align: center; }
  .m-dot { position: absolute; top: 9px; left: calc(50% + 9px); width: 8px; height: 8px; border-radius: 50%; background: var(--orange); }

  /* ---------- Hoja «Más» ---------- */
  .m-sheet-backdrop.open { display: block; position: fixed; inset: 0; z-index: 90; background: var(--overlay); }
  .m-sheet.open { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 91; max-height: 86dvh; overflow-y: auto;
    padding: 8px 14px calc(16px + env(safe-area-inset-bottom)); background: var(--surface); color: var(--text); border-radius: 18px 18px 0 0; border-top: 1px solid var(--line);
    animation: m-up .18s ease-out; }
  .m-sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
  .m-sheet h3 { margin: 14px 4px 6px; font: 500 10.5px var(--mono); letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
  .m-sheet-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 50px; padding: 10px 12px; border: 0; border-radius: 12px; background: transparent;
    color: var(--text); font: inherit; font-size: 15.5px; font-weight: 500; text-align: left; cursor: pointer; }
  .m-sheet-item:active, .m-sheet-item.active { background: var(--brand-soft); color: var(--brand-text); }
  .m-sheet-item svg { width: 21px; height: 21px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .m-sheet-item.danger { color: var(--red-text); }
  .m-sheet-status { display: grid; gap: 6px; }
  .m-sheet-status button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
    color: var(--text); font: inherit; font-size: 13.5px; text-align: left; }
  .m-sheet-status .status-dot { flex: none; }
  .m-sheet-role { margin: 10px 4px 0; font-size: 12.5px; color: var(--muted); }
  @keyframes m-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

  /* ---------- Conversaciones: bandeja a pantalla completa ---------- */
  #view-chat .chat-layout { display: block !important; height: auto !important; min-height: 0 !important; background: none !important; border: 0 !important; box-shadow: none !important; overflow: visible; }
  #view-chat .inbox { max-height: none !important; overflow: visible !important; border: 1px solid var(--line) !important; border-radius: 14px !important; }
  #view-chat .inbox-head { padding: 12px 14px; gap: 8px; border-radius: 14px 14px 0 0; }
  #view-chat .inbox-filter { max-width: none; flex: 1 1 100%; }
  .conv-list { padding: 4px; overflow: visible; }
  .conv-item { padding: 12px 10px; gap: 12px; }
  .conv-item .avatar { width: 44px; height: 44px; flex: none; }
  .conv-flags { flex-wrap: wrap; }
  #view-chat .chat, #view-chat .details { display: none !important; }

  /* ---------- El chat abierto: su propia pantalla ---------- */
  html.m-chat-open { overflow: hidden; }
  html.m-chat-open body { overflow: hidden; }
  html.m-chat-open #view-chat .chat { display: flex !important; position: fixed; inset: 0; z-index: 60; height: 100dvh !important; border: 0 !important; border-radius: 0 !important;
    background: var(--surface) !important; padding-top: env(safe-area-inset-top); }
  html.m-chat-open .m-tabbar { display: none; }
  html.m-chat-open .chat-placeholder { display: none; }
  .chat-head { padding: 8px 10px !important; gap: 6px 8px !important; flex-wrap: wrap; }
  .m-back { display: grid; place-items: center; width: 40px; height: 40px; margin-left: -4px; border: 0; border-radius: 50%; background: transparent; color: var(--text); cursor: pointer; flex: none; }
  .m-back svg, .m-info svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .m-back:active, .m-info:active { background: var(--surface-3); }
  .chat-head .avatar { width: 38px; height: 38px; flex: none; }
  .chat-head-info { flex: 1 1 0 !important; min-width: 0 !important; cursor: pointer; }
  .chat-head-info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-info { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-2);
    color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; flex: none; }
  .m-break { display: block; flex-basis: 100%; height: 0; }
  .chat-head > .btn, .chat-head > .more-menu > summary { min-height: 36px; padding: 6px 12px; font-size: 13px; }
  .messages { padding: 14px 10px !important; gap: 10px; overscroll-behavior: contain; }
  .msg, .bubble { max-width: 88%; }
  .chat-image img, .chat-image video { max-width: min(240px, 70vw); }
  .composer { padding: 8px 10px !important; gap: 8px; }
  .template-panel { padding-bottom: calc(6px + env(safe-area-inset-bottom)) !important; }
  .template-panel > summary { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .template-panel[open] { max-height: 60dvh; overflow-y: auto; }
  .composer input { min-height: 44px; border-radius: 22px !important; padding: 0 16px; }
  .composer .btn { min-height: 44px; border-radius: 22px; padding: 0 16px; }
  .template-panel { padding: 6px 12px; font-size: 13px; }
  .template-panel:not([open]) { max-height: 40px; overflow: hidden; }
  #pauseBanner { margin: 0; border-radius: 0; font-size: 13px; }

  /* «⋯ Más» del chat: hoja desde abajo */
  .more-menu[open] > summary::before { content: ""; position: fixed; inset: 0; z-index: 79; background: var(--overlay); cursor: default; }
  .more-menu[open] .more-menu-list { position: fixed !important; left: 8px !important; right: 8px !important; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    z-index: 80; min-width: 0; max-height: 75dvh; overflow-y: auto; padding: 8px; border-radius: 16px; }
  .more-menu-list .btn { min-height: 48px; font-size: 15px; }

  /* Ficha del cliente: hoja a pantalla completa */
  html.m-details-open #view-chat .details { display: flex !important; position: fixed; inset: 0; z-index: 70; height: 100dvh; overflow-y: auto; gap: 12px;
    padding: 0 12px calc(20px + env(safe-area-inset-bottom)); background: var(--bg) !important; }
  .m-details-head { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 2; margin: 0 -12px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    background: var(--surface); border-bottom: 1px solid var(--line); }
  .m-details-head strong { font-size: 16px; }
  html.m-details-open #view-chat .details .panel-card { border-radius: 14px !important; border: 1px solid var(--line) !important; }

  /* ---------- Otras pantallas ---------- */
  .page-head { gap: 10px !important; margin-bottom: 14px; }
  .page-head h1 { font-size: 24px !important; }
  .page-head p:not(.eyebrow) { font-size: 14px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  .campaign-controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important; gap: 10px; }
  .campaign-controls .field { min-width: 0; }
  .campaign-controls input, .campaign-controls select { width: 100%; min-width: 0; }
  .campaign-controls > .btn { grid-column: 1 / -1; justify-self: stretch !important; }
  .kpis { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .kpi { padding: 12px !important; min-width: 0; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .report-section { padding: 14px !important; }
  .agenda-controls { flex-wrap: wrap; gap: 10px; }
  .agenda-detail:not(.hidden) { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 85; max-height: 80dvh; overflow-y: auto; border-radius: 18px 18px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .modal-card { max-width: calc(100vw - 24px); max-height: 88dvh; overflow-y: auto; }
}

@media (max-width: 380px) {
  .m-tab { font-size: 10.5px; }
  .chat-head > .btn, .chat-head > .more-menu > summary { padding: 6px 9px; font-size: 12.5px; }
}
