/* Layout de celular do TomZap. Tudo aqui só vale em telas de até 760px de largura:
   o layout do computador não é afetado. A navegação (barra de baixo e "Mais") vem de app/celular.js. */

#tzMobileNav, #tzMobileMore, .tzm-filter-toggle, #tzmViewToggle { display: none; }

@media (max-width: 760px) {
  html { overflow-x: hidden; }
  body { width: 100%; max-width: 100%; overflow-x: clip !important; overflow-y: visible !important; } /* a janela (e não o body) é quem rola */
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .app, .main { width: 100%; max-width: 100vw; }
  .main { min-width: 0; }

  /* ---------- Nada pode ser mais largo que a tela (senão o celular "encolhe" ou corta a página) ---------- */
  .content .toolbar .themes, .content .toolbar .switch, .content .toolbar .density { display: none !important; }
  .drawer { transform: none !important; visibility: hidden; opacity: 0; pointer-events: none; transition: opacity .15s !important; }
  body.open .drawer { visibility: visible; opacity: 1; pointer-events: auto; }
  body:not(.tzm-page-conversations) #tzmViewToggle { display: none !important; }
  .auth-screen { padding: 16px !important; overflow-y: auto; }
  .auth-card { width: 100% !important; max-width: 420px; padding: 24px 20px !important; box-sizing: border-box; }
  .auth-card input { font-size: 16px !important; } /* evita o zoom automático do iPhone */
  .auth-card h2 { font-size: 22px; }

  /* Botão lista/grade no topo (app/celular.js) */
  #tzmViewToggle { display: grid !important; place-items: center; }
  #tzmViewToggle svg { display: block; }

  /* ---------- Topo compacto ---------- */
  .top { position: sticky; top: 0; z-index: 30; height: 56px !important; padding: 0 12px !important; gap: 8px; }
  .top > div:first-child { min-width: 0; }
  .top #todayLabel { display: none; }
  .top h1 { font-size: 17px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0 !important; }
  .top-actions { gap: 6px !important; flex-shrink: 0; }
  .top-actions > :not(.avatar):not(.round):not(.global-theme-control) { display: none !important; } /* ex.: "Sincronizado" */
  .top-actions .round { width: 34px; height: 34px; }
  .top-actions .tzm-hide-mobile { display: none !important; } /* lupa do topo: a busca fica na própria tela */

  /* ---------- Barra de navegação de baixo ---------- */
  #tzMobileNav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface, #fff); border-top: 1px solid var(--tz-outline-divider);
    box-shadow: 0 -6px 20px #0f172a14;
  }
  #tzMobileNav button {
    display: grid; justify-items: center; gap: 2px; border: 0; background: transparent;
    color: var(--muted); font-size: 10.5px; font-weight: 600; padding: 4px 0; cursor: pointer;
  }
  #tzMobileNav button svg { display: block; }
  #tzMobileNav button.on { color: var(--blue); }
  body.open #tzMobileNav { display: none; }

  /* ---------- "Mais": todas as outras telas (refeita em 23/10/2026) ---------- */
  #tzMobileMore { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, .45); }
  #tzMobileMore.show { display: block; }
  body.tzmm-open { overflow: hidden; }
  #tzMobileMore .sheet {
    position: absolute; left: 0; right: 0; bottom: 0; max-height: 90vh; overflow-y: auto; overscroll-behavior: contain;
    background: var(--bg); color: var(--ink); border-radius: 20px 20px 0 0;
    padding: 6px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -12px 40px rgba(15, 23, 42, .2);
  }
  #tzMobileMore .grip { width: 38px; height: 4px; border-radius: 4px; background: var(--tz-n300); margin: 4px auto 8px; }
  .tzmm-head { display: flex; align-items: center; gap: 12px; padding: 4px 0 12px; }
  .tzmm-av { flex-shrink: 0; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--tz-primary); color: #fff; font-weight: 600; }
  .tzmm-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .tzmm-who b { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tzmm-who small { color: var(--muted); font-size: 13px; }
  .tzmm-close { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--surface); color: var(--muted); }
  .tzmm-search { position: sticky; top: -6px; z-index: 1; display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; margin: 0 -2px 4px; border: 1px solid var(--tz-outline-control); border-radius: var(--tz-r-sm); background: var(--surface); color: var(--muted); }
  .tzmm-search svg { width: 18px; height: 18px; flex-shrink: 0; }
  .tzmm-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 16px; }
  .tzmm-group:not(:has(h4)) { margin-top: 16px; }
  .tzmm-group h4 { margin: 16px 2px 8px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
  #tzMobileMore .items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #tzMobileMore .items button {
    display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; border: 1px solid var(--tz-outline-control);
    border-radius: var(--tz-r-sm); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; font-weight: 500; text-align: left; cursor: pointer;
  }
  #tzMobileMore .items button[hidden], .tzmm-group[hidden] { display: none; }
  #tzMobileMore .items button svg { flex-shrink: 0; width: 20px; height: 20px; color: var(--tz-primary); }
  #tzMobileMore .items button span { min-width: 0; line-height: 1.25; }
  #tzMobileMore .items button.on { border-color: var(--tz-primary); background: var(--tz-primary-soft); color: var(--tz-primary-ink); }
  #tzMobileMore .items button:active { transform: scale(.98); }
  .tzmm-none { margin: 16px 2px; color: var(--muted); font-size: 14px; }
  .tzmm-chips { display: flex; gap: 6px; margin-bottom: 8px; }
  .tzmm-chips button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 6px; border: 1px solid var(--tz-outline-control); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 500; }
  .tzmm-chips button.on { border-color: var(--tz-primary); background: var(--tz-primary-soft); color: var(--tz-primary-ink); }
  .tzmm-sw { width: 12px; height: 12px; border-radius: 50%; background: #0b6bff; }
  .tzmm-sw.graphite { background: #262e3b; }
  .tzmm-sw.coral { background: #c24162; }
  .tzmm-rows { margin-top: 16px; border: 1px solid var(--tz-outline-container); border-radius: var(--tz-r-md); background: var(--surface); overflow: hidden; }
  .tzmm-rows button { display: flex; align-items: center; gap: 12px; width: 100%; height: 52px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--tz-outline-divider); background: transparent; color: var(--ink); font: inherit; font-size: 15px; text-align: left; }
  .tzmm-rows button:last-child { border-bottom: 0; }
  .tzmm-rows button svg { width: 20px; height: 20px; color: var(--muted); }
  .tzmm-rows button.danger, .tzmm-rows button.danger svg { color: var(--tz-danger); }
  body[data-theme="graphite"] .tzmm-av { color: #0b1b33; }
  body[data-theme="graphite"] #tzMobileMore .items button.on, body[data-theme="graphite"] .tzmm-chips button.on { color: var(--tz-primary); }

  /* ---------- Conteúdo das telas ---------- */
  .content { padding: 12px 12px 20px !important; }
  .heading { flex-direction: row !important; align-items: center !important; margin-bottom: 10px !important; gap: 10px; }
  .heading h2 { font-size: 20px !important; margin: 0 !important; }
  .heading p { display: none; }
  .heading .primary { padding: 9px 12px !important; font-size: 12.5px !important; white-space: nowrap; }

  /* ---------- Conversas ---------- */
  .content .toolbar { display: flex !important; flex-wrap: nowrap !important; gap: 6px !important; margin-bottom: 8px !important; }
  .content .toolbar .search { flex: 1; min-width: 0 !important; }
  .content .toolbar > .filter:not(.tzm-filter-toggle),
  .content .toolbar .tzc-view-button { display: none !important; }
  .tzm-filter-toggle { display: inline-flex !important; align-items: center; gap: 4px; flex-shrink: 0; }
  body.tzm-filters-open .content .toolbar { flex-wrap: wrap !important; }
  body.tzm-filters-open .content .toolbar .search { flex: 1 1 100%; order: -1; }
  body.tzm-filters-open .content .toolbar > .filter:not(.tzm-filter-toggle) { display: inline-flex !important; }
  .content .sla-row { display: none !important; }
  body.tzm-filters-open .content .sla-row { display: flex !important; flex-wrap: wrap; gap: 8px; margin: 0 0 10px !important; }

  /* Atendentes e atalhos: uma linha que desliza para o lado */
  .team-filters {
    flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    padding: 6px 8px !important; margin-bottom: 10px !important;
  }
  .team-filters::-webkit-scrollbar { display: none; }
  .team-filters .team-label { display: none; }
  .team-filters .team-filter { flex: 0 0 auto; white-space: nowrap; font-size: 12px !important; padding: 6px 10px !important; }

  /* Lista: um atendimento por linha, compacto */
  .conversations.list .card { padding: 11px 12px !important; gap: 4px 10px !important; }
  .conversations.list .card .owner { font-size: 11px; }
  .conversations .card .card-top { width: 100%; min-width: 0; }
  .conversations .card .person { flex: 1; min-width: 0; }
  .conversations .card .person .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .conversations .card .preview { overflow-wrap: anywhere; }
  /* Painel: linhas "aguardando há mais tempo" sem cortar a etiqueta de tempo */
  .tzd-row > span:first-child { min-width: 0; overflow: hidden; }
  .tzd-row > span:first-child b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tzd-row .tzd-pill { flex-shrink: 0; }
  /* Grade: dois cards por linha */
  .conversations:not(.list) { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  .conversations:not(.list) .card { min-height: 0 !important; padding: 10px !important; gap: 6px !important; border-radius: 12px; }
  .conversations:not(.list) .card .avatar { width: 28px !important; height: 28px !important; font-size: 11px; }
  .conversations:not(.list) .card .name { font-size: 12.5px; }
  .conversations:not(.list) .card .sub, .conversations:not(.list) .card .time { font-size: 10px !important; }
  .conversations:not(.list) .card .preview { font-size: 12px !important; min-height: 0 !important; -webkit-line-clamp: 2; }
  .conversations:not(.list) .card .owner, .conversations:not(.list) .card .bottom .chips, .conversations:not(.list) .card .sub { display: none; }
  .conversations:not(.list) .card .card-top { align-items: flex-start; }
  .conversations:not(.list) .card .waiting-time, .conversations:not(.list) .card .tzc-chip { font-size: 10px !important; }
  .card:hover, .card.selected { transform: none !important; }

  /* ---------- Conversa aberta em tela cheia ---------- */
  .drawer { top: 0 !important; left: 0; width: 100vw !important; height: 100dvh; box-shadow: none !important; z-index: 50 !important; }
  .backdrop { display: none !important; }
  .drawer-head { padding: 10px 12px !important; gap: 8px; }
  .drawer-head .name { font-size: 15px !important; }
  .drawer-actions { gap: 6px !important; }
  .drawer-toolbar { padding: 6px 12px !important; overflow-x: auto; }
  .drawer-body { padding: 12px !important; }
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) !important; gap: 6px !important; max-width: 100vw; box-sizing: border-box; }
  .composer > * { flex-shrink: 0; }
  .composer input, .composer textarea, .composer #message { flex: 1 1 auto !important; min-width: 0 !important; width: auto !important; }
  .composer .round, .composer .send, .composer button { min-width: 36px; }
  .drawer-head, .drawer-toolbar, .drawer-body, .drawer-tools-panel { max-width: 100vw; box-sizing: border-box; }
  .drawer-head > div:first-child { min-width: 0; }
  .drawer-head .name, #dSub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .composer input, .composer textarea { font-size: 16px !important; } /* evita o zoom automático do iPhone */
  body.open { overflow: hidden; }

  /* ---------- Outras telas: tabelas viram cartões, grades viram uma coluna ---------- */
  .module-grid, .module-columns, .crud-permissions, .tzd-grid, .tzd-kpis { grid-template-columns: 1fr !important; }
  .tzd-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .module-head, .crud-page-action { flex-direction: column; align-items: stretch !important; gap: 10px; }
  .crud-list-head, .contacts-list-head, .search-results-head { display: none !important; }
  .crud-list-row, .team-crud-row {
    display: grid !important; grid-template-columns: 1fr auto !important; gap: 6px 10px !important;
    padding: 12px !important; align-items: center;
  }
  .crud-list-row > * { min-width: 0; }
  /* Larguras mínimas fixas pensadas para computador (650px, 780px, 790px...) */
  .crud-list-row, .team-crud-row, .contact-admin-row, .module-list-item { min-width: 0 !important; max-width: 100%; }
  .contact-admin-row { display: grid !important; grid-template-columns: 1fr auto !important; gap: 6px 10px !important; }
  .contact-admin-row > :first-child { grid-column: 1 / -1; }
  .module-list-item { flex-wrap: wrap; gap: 8px; }
  #moduleView, #moduleView > *, #moduleView section, .security-summary, .module-form { max-width: 100%; min-width: 0; }
  .security-summary { grid-template-columns: 1fr !important; }
  #securityAuditResults, #securitySessionsResults { overflow-x: auto; }
  #moduleView pre, #moduleView code { white-space: pre-wrap; overflow-wrap: anywhere; }
  .search-results-table { display: block !important; overflow-x: auto; min-width: 0 !important; max-width: 100%; }
  .agenda-month-head, .agenda-month-grid { min-width: 0 !important; grid-template-columns: repeat(7, minmax(0, 1fr)) !important; }
  .agenda-month-grid .agenda-event { font-size: 9.5px !important; padding: 2px 3px !important; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .agenda-toolbar { flex-wrap: wrap; gap: 8px; }
  .tzd-list { min-width: 0; }
  .tzd-row { width: 100%; min-width: 0; }
  .crud-list-row .crud-list-main { grid-column: 1 / -1; }
  .crud-list-row .crud-list-actions { justify-self: end; display: flex; flex-wrap: wrap; gap: 6px; }
  .module-table, table { display: block; overflow-x: auto; max-width: 100%; }
  .kanban-column { min-width: 78vw; }
  .module-columns { display: flex !important; overflow-x: auto; gap: 10px; scroll-snap-type: x mandatory; }
  .module-columns > * { scroll-snap-align: start; }
  .agenda-month-grid { font-size: 11px; }

  /* Janelas de cadastro em tela cheia */
  .standard-crud-backdrop { padding: 0 !important; place-items: stretch !important; }
  .standard-crud-dialog { width: 100vw !important; max-width: 100vw !important; height: 100dvh; max-height: 100dvh !important; border-radius: 0 !important; margin: 0 !important; display: flex; flex-direction: column; }
  .standard-crud-form { grid-template-columns: 1fr !important; overflow-y: auto; }
  .standard-crud-form input, .standard-crud-form select, .standard-crud-form textarea { font-size: 16px !important; }

  /* Menus e janelas do TomZap novo */
  .tzm-modal { width: 100% !important; }
  .tzc-menu { max-width: calc(100vw - 16px); }
  .toast { left: 12px !important; right: 12px !important; bottom: 76px !important; }
}

/* No celular a conversa ocupa a tela (z-index 50): janelas que abrem a partir dela ficam acima. */
@media (max-width: 760px) {
  .finish-backdrop, .agenda-composer-backdrop { z-index: 70 !important; }
}

/* Faixa da janela de 24 h no celular: uma linha fina (antes cobria a primeira mensagem). */
@media (max-width: 760px) {
  #customerWindowBannerTomZap { padding: 5px 12px !important; margin: 4px 8px !important; border-radius: 999px !important; font-size: 12px !important; gap: 8px !important; }
  #customerWindowBannerTomZap small { display: none !important; }
  #customerWindowBannerTomZap strong { font-size: 12px !important; }
}
/* Cards em duas colunas: o nome quebra em até 2 linhas em vez de cortar com "…" */
@media (max-width: 760px) {
  .conversations:not(.list) .card .name { white-space: normal !important; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.2; }
}

/* ---------- Telas antigas no celular (23/10/2026) ---------- */
@media (max-width: 760px) {
  /* cabeçalho: título e (i) na mesma linha; "Triagem" sem quebrar */
  .module-head h2, .heading h2 { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
  .heading > div:first-child { min-width: 0; }
  .heading .tzpd-info { display: none; } /* a dica (i) ficava escondida atrás do Triagem */
  .heading .tzia-tri { flex-shrink: 0; white-space: nowrap; margin-right: 0; padding: 0 10px; }

  /* cadastros no molde antigo (Respostas rápidas, Etiquetas, Setores, Grupos...): faixa de ação curta e linhas compactas */
  .crud-page-action { display: flex !important; flex-direction: row !important; flex-wrap: wrap; align-items: center; gap: 8px !important; padding: 12px !important; }
  .crud-page-action > div:first-child { flex: 1 1 100%; }
  .crud-page-action > div:first-child span { display: none; }
  .crud-page-action > button { flex: 1 1 0; width: auto !important; min-width: 0; height: 40px; margin: 0 !important; white-space: nowrap; }
  .crud-list-panel .crud-list-row {
    display: grid !important; grid-template-columns: minmax(0, 1fr) auto !important; gap: 4px 10px !important;
    grid-template-areas: "main main" "meta status" "actions actions"; padding: 12px 14px !important;
  }
  .crud-list-row > .crud-list-main { grid-area: main; min-width: 0; }
  .crud-list-row > .crud-list-meta { grid-area: meta; align-self: center; color: var(--muted); font-size: 13px; }
  .crud-list-row > div:nth-child(3) { grid-area: status; justify-self: end; align-self: center; }
  .crud-list-row > .crud-list-actions { grid-area: actions; display: flex !important; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 4px; padding: 0 !important; }
  .crud-list-actions .crud-edit-button { height: 36px; padding: 0 12px !important; font-size: 13px !important; }
  .crud-list-actions .tzqr-attach .crud-edit-button::before { content: none !important; display: none !important; }

  /* Contatos: botões do topo lado a lado e os contadores numa faixa que desliza */
  .contacts-page .module-head { flex-direction: row !important; flex-wrap: wrap; gap: 8px !important; }
  .contacts-page .module-head > div:first-child { flex: 1 1 100%; }
  .contacts-page .module-head > button { flex: 1 1 0; width: auto !important; min-width: 0; height: 42px; margin: 0 !important; white-space: nowrap; }
  .contacts-page .contacts-stats { gap: 4px 16px !important; padding: 10px 14px !important; }
}

/* ---------- Celular deitado (23/10/2026): telas com pouca altura ----------
   Deitado, o iPhone passa de 760 px de largura e recebe o layout de computador numa altura de ~390 px; o Android menor
   fica no layout de celular com ~360 px. Nos dois, topo, menu e barra de baixo comiam metade da tela. */
@media (orientation: landscape) and (max-height: 500px) {
  .top { height: 48px !important; flex-basis: 48px !important; }
  .top .round, .top .avatar { width: 34px !important; height: 34px !important; }
  .module-head, .heading { margin-bottom: 8px !important; }
  .module-head h2, .heading h2, .md-hello h2, .tzkn-head h2 { font-size: 20px !important; }
  .md-hello p { display: none; }
  .md-box h3 { flex-wrap: wrap; row-gap: 6px; }
  .md-box h3 > a, .md-box h3 > button, .md-box h3 > span { white-space: nowrap; }
  /* menu lateral (layout de computador): só ícones, mais baixos, e rola */
  .tzs:not(.open) .tzs-scroll > .tzs-item, .tzs:not(.open) .tzs-group > .tzs-item { height: 40px !important; }
  .tzs:not(.open) .tzs-rl { display: none !important; }
  .tzs { padding-top: 8px; padding-bottom: 8px; }
  .tzs-brand { height: 32px; }
  /* colunas do Kanban e grade da agenda com altura útil */
  .tzkn-col { max-height: none; }
  .tzv-scroll { max-height: max(220px, calc(100vh - 150px)) !important; }
  /* conversa aberta: cabeçalho numa faixa, barra de ações mais baixa, mais espaço para as mensagens */
  .drawer .drawer-head { padding-top: 6px !important; padding-bottom: 6px !important; }
  .drawer .drawer-head .sub, .drawer .tzbc-chips .tzbc-chip.ghost { display: none !important; }
  .drawer .drawer-head .tzbc-chips { margin-top: 2px; }
  .drawer .drawer-toolbar .drawer-tool { padding-top: 6px !important; padding-bottom: 6px !important; }
  .drawer .composer { padding-top: 6px !important; padding-bottom: 6px !important; }
}
@media (orientation: landscape) and (max-height: 500px) and (min-width: 761px) {
  /* layout de computador (iPhone e Android grandes deitados): mais ícones à direita do topo */
  body.tzm-page-conversations .content > .toolbar { right: 260px; }
}
@media (orientation: landscape) and (max-height: 500px) and (max-width: 760px) {
  /* barra de baixo: ícone ao lado do nome, mais baixa */
  #tzMobileNav { padding-top: 2px; padding-bottom: calc(2px + env(safe-area-inset-bottom)); }
  #tzMobileNav button { display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px; font-size: 13px; }
  #tzMobileNav button svg { width: 20px; height: 20px; }
  /* cartões de conversa: dois por linha (deitado sobra largura) */
  body #conversations:not(.list) { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  /* folha "Mais": mais colunas e quase a tela toda */
  #tzMobileMore .sheet { max-height: 94vh; }
  #tzMobileMore .items { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .tzv-new { bottom: calc(52px + env(safe-area-inset-bottom)); height: 42px; }
}

/* ---------- Conversas com o celular deitado, 2ª rodada (23/10/2026) ----------
   No aparelho de verdade a barra do navegador ainda tira altura (sobram ~320 px) e o cabeçalho de Conversas ficava com
   70% da tela. Agora: "Triagem" e "Novo atendimento" sobem para a barra do topo (o título sai: a aba já diz onde está),
   a página rola inteira (o topo vai embora ao rolar; no layout de computador só a lista rolava, num vão de ~100 px) e
   busca e filtros ficam mais baixos. */
@media (orientation: landscape) and (max-height: 500px) {
  .app, .main { height: auto !important; min-height: 100vh; overflow: visible !important; }
  .main { position: relative; }
  .top { position: static !important; }
  .content { overflow: visible !important; height: auto !important; }
  body.tzm-page-conversations .top > div:first-child, body.tzm-page-conversations .top .realtime-status { display: none !important; }
  body.tzm-page-conversations .top { justify-content: flex-end !important; }
  /* abas, "Minhas + fila" e "Filtros" numa linha que desliza (no iPhone deitado ocupavam duas) */
  .tzl-tabs { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; margin-bottom: 8px !important; max-width: 100%; min-width: 0; box-sizing: border-box; }
  html, body { overflow-x: clip; }
  .tzl-tabs::-webkit-scrollbar { display: none; }
  .tzl-tabs > * { flex: 0 0 auto !important; white-space: nowrap; }
  body.tzm-page-conversations .content > .heading { position: absolute; top: 7px; left: 12px; z-index: 31; margin: 0 !important; gap: 8px; }
  body.tzm-page-conversations .content > .heading > div:first-child { display: none; }
  body.tzm-page-conversations .content > .heading button { height: 34px !important; padding: 0 12px !important; font-size: 13px !important; box-shadow: none !important; }
  body.tzm-page-conversations .content { padding-top: 8px !important; }
  /* 3ª rodada (captura do Tom no Android deitado): os dois botões viram só ícone e a busca também sobe para a barra do
     topo, entre eles e os ícones da direita; embaixo ficam só as abas/filtros e os cartões */
  body.tzm-page-conversations .content > .heading .tzia-tri, body.tzm-page-conversations .content > .heading .primary { width: 38px; padding: 0 !important; font-size: 0 !important; display: inline-grid; place-items: center; }
  body.tzm-page-conversations .content > .heading .tzia-tri::before { content: '✨'; font-size: 16px; }
  body.tzm-page-conversations .content > .heading .primary::before { content: '+'; font-size: 22px; font-weight: 500; line-height: 1; }
  body.tzm-page-conversations .content > .heading .tzia-tri *, body.tzm-page-conversations .content > .heading .primary * { display: none; }
  body.tzm-page-conversations .content > .heading .tzl-grid-btn { display: none; }
  body.tzm-page-conversations .content > .toolbar { position: absolute; top: 6px; left: 108px; right: 160px; z-index: 31; margin: 0 !important; }
  body.tzm-page-conversations .content > .toolbar .search, body.tzm-page-conversations .content > .toolbar .search input, body.tzm-page-conversations .content > .toolbar > button { height: 36px !important; }
  #conversations, .conversations { overflow: visible !important; max-height: none !important; height: auto !important; }
  .content .toolbar { margin-bottom: 6px !important; }
  .content .toolbar .search, .content .toolbar .search input, .content .toolbar > button { height: 36px !important; }
  .team-filters { padding: 4px 6px !important; margin-bottom: 8px !important; }
  .team-filters .team-filter { padding: 4px 10px !important; }
}

/* Formulários em janelas no celular: leitura, rolagem e ações acessíveis (25/10/2026). */
@media (max-width: 760px) {
  /* Contato: folha que cresce conforme o conteúdo, com cabeçalho fixo e botões sempre à mão. */
  .contact-crud-backdrop {
    align-items: end !important;
    justify-items: stretch !important;
    padding: 0 !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
  }
  .contact-crud-dialog {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: none !important;
    max-height: min(90dvh, 760px) !important;
    margin: 0 !important;
    border-radius: 18px 18px 0 0 !important;
    overflow: hidden !important;
  }
  .contact-crud-header { flex: 0 0 auto; min-height: 58px; padding: 12px 16px !important; }
  .contact-crud-close { width: 44px !important; height: 44px !important; flex: 0 0 44px; }
  .contact-crud-form {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 16px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .contact-crud-field.full { grid-column: auto !important; }
  .contact-crud-field { gap: 6px !important; }
  .contact-crud-field label { font-size: 12px !important; }
  .contact-crud-field input { width: 100%; height: 46px !important; font-size: 16px !important; }
  .contact-crud-footer {
    position: sticky;
    bottom: calc(-10px - env(safe-area-inset-bottom, 0px));
    z-index: 1;
    flex-wrap: wrap;
    gap: 8px !important;
    margin: 4px -16px calc(-10px - env(safe-area-inset-bottom, 0px)) !important;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    border-top: 1px solid var(--tz-outline-divider);
    background: var(--surface) !important;
    box-shadow: 0 -8px 18px rgba(15, 23, 42, .06);
  }
  .contact-crud-footer .spacer { display: none !important; }
  .contact-crud-footer button { flex: 1 1 calc(50% - 8px); min-width: 0; min-height: 44px; height: auto !important; padding: 8px 10px !important; font-size: 13px !important; }
  .contact-crud-footer button.danger, .contact-crud-footer button.reactivate { flex-basis: 100%; }

  /* Cadastros maiores: tela inteira, cabeçalho visível e rodapé fixo na área de rolagem. */
  .standard-crud-backdrop { padding: 0 !important; place-items: stretch !important; }
  .standard-crud-dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  .standard-crud-header { flex: 0 0 auto; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px !important; }
  .standard-crud-close { width: 44px !important; height: 44px !important; flex: 0 0 44px; }
  .standard-crud-form {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 16px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .standard-crud-field:not(.standard-crud-footer) { width: 100%; }
  .standard-crud-field.full { grid-column: auto !important; }
  .standard-crud-field { gap: 6px !important; }
  .standard-crud-field label { font-size: 12px !important; }
  .standard-crud-field input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
  .standard-crud-field select { height: 46px !important; min-height: 46px; font-size: 16px !important; }
  .standard-crud-field textarea { min-height: 100px; font-size: 16px !important; }
  .standard-crud-footer {
    position: sticky;
    bottom: calc(-10px - env(safe-area-inset-bottom, 0px));
    z-index: 1;
    flex-wrap: wrap;
    gap: 8px !important;
    width: calc(100% + 32px) !important;
    box-sizing: border-box;
    margin: 4px -16px calc(-10px - env(safe-area-inset-bottom, 0px)) !important;
    margin-top: auto !important;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    background: var(--surface) !important;
    box-shadow: 0 -8px 18px rgba(15, 23, 42, .06);
  }
  .standard-crud-footer .spacer { display: none !important; }
  .standard-crud-footer button { flex: 1 1 calc(50% - 8px); min-width: 0; min-height: 44px; height: auto !important; padding: 8px 10px !important; font-size: 13px !important; }
  .standard-crud-footer button.danger, .standard-crud-footer button.reactivate { flex-basis: 100%; }

  /* Janelas curtas (agenda, tarefas, avisos): folha móvel e botões maiores. */
  .tzf-backdrop { align-items: end !important; padding: 0 !important; }
  .tzf-modal {
    width: 100% !important;
    max-height: 92dvh !important;
    padding: 18px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 18px 18px 0 0 !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .tzf-modal h3 { position: sticky; top: -18px; z-index: 2; padding: 2px 0 12px; background: var(--surface); font-size: 19px; }
  .tzf-form { grid-template-columns: 1fr !important; gap: 12px !important; }
  .tzf-form .wide { grid-column: auto !important; }
  .tzf-form label { gap: 6px !important; font-size: 12px !important; }
  .tzf-form input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
  .tzf-form select, .tzf-form textarea, #tzfReasonOther {
    min-height: 46px;
    font-size: 16px !important;
    box-sizing: border-box;
  }
  .tzf-form textarea { padding-top: 10px; }
  .tzf-modal-actions {
    position: sticky;
    bottom: calc(-10px - env(safe-area-inset-bottom, 0px));
    z-index: 1;
    flex-wrap: wrap;
    margin: 4px -16px calc(-10px - env(safe-area-inset-bottom, 0px)) !important;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--tz-outline-divider);
    background: var(--surface);
    box-shadow: 0 -8px 18px rgba(15, 23, 42, .06);
  }
  .tzf-modal-actions span { display: none; }
  .tzf-modal button { min-height: 44px; padding: 10px 14px; font-size: 14px; }
  .tzf-modal-actions button { flex: 1 1 0; }

  /* Menus de conta e IA seguem o mesmo padrão de folha e ações alcançáveis. */
  .tzm-back { align-items: end !important; padding: 0 !important; }
  .tzm-modal {
    width: 100% !important;
    max-height: 92dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: 18px 18px 0 0 !important;
    padding: 20px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    font-size: 16px;
  }
  .tzm-modal label { font-size: 13px !important; }
  .tzm-modal input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
  .tzm-modal select, .tzm-modal textarea { min-height: 46px; font-size: 16px !important; box-sizing: border-box; }
  .tzm-modal .tzm-actions { position: sticky; bottom: calc(-10px - env(safe-area-inset-bottom, 0px)); z-index: 1; margin: 4px -16px calc(-10px - env(safe-area-inset-bottom, 0px)) !important; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)) !important; border-top: 1px solid var(--tz-outline-divider); background: var(--surface); }
  .tzm-modal .tzm-actions button { flex: 1 1 0; min-height: 44px; height: auto !important; font-size: 14px; }
}
