/* ===========================================================
   CRM Sua Cidade — Mobile App shell (bottom-nav) — PATHFINDER
   Só ativa em telas <=768px. NÃO afeta desktop.
   =========================================================== */
@media (max-width: 768px) {
  /* 1) Esconder navegação antiga (sidebar desktop + abas de topo) */
  html body .sidebar,
  html body .sidebar-toggle,
  html body .pp-topnav { display: none !important; }

  /* 2) Body vira 1 coluna, conteúdo 100% largura (vence #crm-menu-padrao 200px) */
  html body {
    display: block !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
    /* 3) espaço reservado pra bottom-nav */
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  }
  html body > main,
  html body > .page-main,
  html body .page-main {
    width: 100% !important;
    max-width: 100% !important;
    grid-column: 1 / -1 !important;
  }

  /* === MOBINT-SCROLLFIX: destravar rolagem vertical no mobile === */
  html, body {
    height: auto !important;
    min-height: 100vh !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Containers de conteudo do app-shell nao podem prender altura/overflow no mobile */
  html body .main,
  html body > main,
  html body .page-main,
  html body .container,
  html body .dash-wrap,
  html body .kanban-wrap,
  html body .pat-wrap,
  html body .proto-wrap {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  /* 4) Bottom-nav */
  .mob-bottom-nav {
    display: flex !important;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 9999;
    background: #ffffff;
    border-top: 1px solid #ececec;
    box-shadow: 0 -2px 10px rgba(0,0,0,.05);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  .mob-bottom-nav a,
  .mob-bottom-nav button {
    flex: 1 1 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    height: 64px;
    background: none; border: none; cursor: pointer;
    text-decoration: none;
    color: #8a8a8a;
    font-family: inherit;
    font-size: 11px; font-weight: 600; line-height: 1;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-bottom-nav a svg,
  .mob-bottom-nav button svg { width: 22px; height: 22px; display: block; stroke: currentColor; }
  .mob-bottom-nav a.active,
  .mob-bottom-nav button.active { color: #FF3131; }

  /* 5) Sheet do "Mais" */
  .mob-sheet-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(0,0,0,.38);
  }
  .mob-sheet-overlay.open { display: block; }
  .mob-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10001;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 8px 8px calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 24px rgba(0,0,0,.18);
    transform: translateY(0);
  }
  .mob-sheet .mob-sheet-grip {
    width: 40px; height: 4px; border-radius: 99px;
    background: #d9d9d9; margin: 8px auto 12px;
  }
  .mob-sheet a {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 14px; text-decoration: none;
    color: #333; font-size: 15px; font-weight: 600;
    border-radius: 10px;
  }
  .mob-sheet a svg { width: 20px; height: 20px; stroke: currentColor; flex-shrink: 0; }
  .mob-sheet a.active { color: #FF3131; background: rgba(237,164,32,.10); }

  /* FAN-OUT: FAB flutuante e barras fixas ACIMA da bottom-nav (~64px) */
  button[onclick^="abrirAgendaPopup"],
  .fab, .fab-add, .btn-float, .btn-fab, .float-add {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 14px) !important;
    z-index: 9998 !important;
  }
  .prod { bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important; }
  .toast { bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 18px) !important; }

  /* Container de scroll pra tabelas largas (não empurra a página) */
  .mob-tscroll { display: block; width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .mob-tscroll > table { max-width: none; }
}

/* Fora do mobile: nunca mostrar a bottom-nav / sheet */
.mob-bottom-nav { display: none; }
.mob-sheet-overlay { display: none; }


/* ===========================================================
   PADTOPO-UNIFICADO — cabecalho/topo padronizado no mobile (<=768px)
   Distancia do titulo ao topo IGUAL em todas as telas + h1/subtitulo unificados.
   So afeta mobile. Desktop intocado.
   =========================================================== */
@media (max-width: 768px) {
  html body .main,
  html body .page-main,
  html body .kanban-page {
    padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  }
  html body .header,
  html body .kanban-head,
  html body .head,
  html body .paineis-top {
    padding-top: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 14px !important;
    align-items: flex-start !important;
  }
  html body .cl-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
    margin-bottom: 0 !important;
  }
  html body .header h1,
  html body .kanban-head h1,
  html body .head h1,
  html body .paineis-top h1,
  html body .cl-header h1,
  html body .page-h1,
  html body .main > h1 {
    font-size: 23px !important;
    font-weight: 700 !important;
    line-height: 1.2 !important;
    letter-spacing: -.3px !important;
    color: var(--wine, #1b232e) !important;
    margin: 0 !important;
    font-family: 'Inter', sans-serif !important;
  }
  html body .header .sub,
  html body .kanban-head .sub,
  html body .head .sub,
  html body .paineis-top .sub,
  html body .cl-header .sub,
  html body .page-sub,
  html body .main > .sub,
  html body .main > p.sub {
    font-size: 13px !important;
    font-weight: 400 !important;
    line-height: 1.35 !important;
    color: var(--text-soft, #6B5F68) !important;
    margin: 3px 0 0 !important;
  }

  /* ====== CONTATOS (pacientes): tabela vira CARDS empilhados ====== */
  html body main.page-main .tab-card {
    border: none !important; background: transparent !important;
    padding: 0 !important; overflow: visible !important; box-shadow: none !important;
  }
  html body main.page-main .tab-card table,
  html body main.page-main .tab-card tbody,
  html body main.page-main .tab-card tr,
  html body main.page-main .tab-card td {
    display: block !important; width: auto !important;
  }
  html body main.page-main .tab-card thead {
    position: absolute !important; left: -9999px !important; top: -9999px !important;
  }
  html body main.page-main .tab-card tr {
    background: #fff !important;
    border: 1px solid var(--border, #ececec) !important;
    border-radius: 12px !important;
    padding: 14px 14px 12px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 1px 4px rgba(0,0,0,.05) !important;
    position: relative !important;
  }
  html body main.page-main .tab-card td {
    padding: 0 !important; border: none !important; max-width: none !important;
    text-align: left !important; font-size: 13.5px !important;
    color: var(--text-soft, #6B5F68) !important;
  }
  html body main.page-main .tab-card td:nth-child(1) {
    font-size: 16px !important; font-weight: 700 !important;
    color: var(--wine, #1b232e) !important;
    margin-bottom: 8px !important; padding-right: 96px !important;
  }
  html body main.page-main .tab-card td:nth-child(3) {
    position: absolute !important; top: 13px !important; right: 13px !important;
    margin: 0 !important;
  }
  html body main.page-main .tab-card td:nth-child(3) span {
    display: inline-block !important;
    padding: 3px 10px !important; border-radius: 99px !important;
    background: rgba(0,0,0,.05) !important; font-size: 11px !important;
    max-width: 150px !important; overflow: hidden !important;
    text-overflow: ellipsis !important; white-space: nowrap !important;
  }
  html body main.page-main .tab-card td:nth-child(2),
  html body main.page-main .tab-card td:nth-child(4),
  html body main.page-main .tab-card td:nth-child(5) { margin-top: 5px !important; }
  html body main.page-main .tab-card td:nth-child(2)::before { content: 'Curso: '; font-weight: 600; color: var(--wine, #1b232e); }
  html body main.page-main .tab-card td:nth-child(4)::before { content: 'Profissão: '; font-weight: 600; color: var(--wine, #1b232e); }
  html body main.page-main .tab-card td:nth-child(5)::before { content: 'Telefone: '; font-weight: 600; color: var(--wine, #1b232e); }
  html body main.page-main .tab-card td:nth-child(6) {
    text-align: left !important; margin-top: 12px !important;
  }
  html body main.page-main .tab-card td:nth-child(6) button {
    width: 100% !important; padding: 9px !important; font-size: 13px !important;
  }
  html body main.page-main .tab-card td.empty-row {
    font-size: 14px !important; font-weight: 400 !important;
    color: var(--text-soft, #6B5F68) !important; padding: 18px 4px !important;
    text-align: center !important;
  }
}

/* PADTOPO-UNIFICADO fix: kanban-page tem regra inline mais especifica (html body main.kanban-page) */
@media (max-width: 768px) {
  html body main.kanban-page { padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important; }
}
