/* ════════════════════════════════════════════════════════════
   GRUPO MRX — mobile.css  v31
   Responsividade completa: tablet, mobile, PWA (Android/iOS)
   ════════════════════════════════════════════════════════════ */

/* ── BASE GLOBAL MOBILE ──────────────────────────────────────────────────── */
* {
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
  /* iOS Safari: impede scroll horizontal em toda a página */
  overflow-x: hidden;
  max-width: 100%;
}

body {
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip; /* clip não cria scroll container, mantendo scroll da janela funcional */
  max-width: 100%;
}

/* Cards e grids nunca saem da tela */
.kpi-card,
.chart-card,
.insight-card,
.prod-card,
.equipe-card,
.reativ-card,
.alert-card,
.card {
  max-width: 100%;
  min-width: 0;
}

/* Texto dentro de flex items nunca força overflow */
.ind-kpi-card > div:last-child,
.reativ-card-info,
.equipe-card-info {
  min-width: 0;
  overflow: hidden;
}

/* Momentum scroll em containers que fazem overflow */
.table-wrap,
.mrxia-chat,
.sidebar-nav,
.modal,
.ficha-modal {
  -webkit-overflow-scrolling: touch;
}

/* ── TABLET (≤ 1024px) ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {

  .mini-sidebar { display: none; }

  .topbar,
  .main { margin-left: 0; }

  .hamburger-btn { display: flex; }

  /* Nos celulares menores .main chega a ter só 8px de padding — some com o
     board do Kanban colado na borda física da tela. Arrastar um card que
     começa a ~8px da borda cai dentro da faixa que iOS/Android reservam pro
     gesto nativo de "voltar" (swipe da borda), que tem prioridade sobre
     touch-action:none da página — o navegador interpretava o arraste como
     "voltar" e saía do CRM. 16px de respiro extra tira o board dessa faixa. */
  .kanban-board { padding-left: 16px; padding-right: 16px; }

  /* Sidebar cobre a tela inteira — acima de tudo */
  .sidebar {
    top: 0 !important;
    height: 100dvh !important;
    height: 100vh !important;
    z-index: 9999 !important;
    overflow: hidden;
  }

  .sidebar-overlay {
    top: 0 !important;
    z-index: 9998 !important;
  }

  /* Rebaixa topbar para trás do sidebar quando ele está aberto */
  body.sidebar-open .topbar {
    z-index: 1 !important;
  }

  /* min-height:0 é obrigatório para flex child scrollável — sem isso o nav
     não encolhe e os itens vazam para fora do sidebar */
  .sidebar-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Footer respeita barra de navegação do sistema (Android/iOS) */
  .sidebar-footer {
    flex-shrink: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    height: 56px;
    padding: 0 18px;
    gap: 10px;
  }

  .logo-text { font-size: 0.95rem; }

  .page-title {
    font-size: 0.75rem;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 22px;
  }

  .kpi-card { padding: 16px; }
  .kpi-card-value { font-size: 1.8rem; }

  .charts-grid-2 { grid-template-columns: 1fr 1fr; gap: 16px; }
  .charts-grid-3 { grid-template-columns: 1fr 1fr; gap: 16px; }

  .insight-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }

  .main { padding: 22px 20px 90px; }

  .filter-chip { font-size: 0.71rem; padding: 4px 10px; }
  .modal { width: clamp(320px, 92vw, 560px); }
}

/* ── TOPBAR: esconde nome do usuário em telas menores ────────────────── */
@media (max-width: 600px) {
  .topbar-user-name { display: none; }
  .topbar-user-static { padding: 5px 7px; gap: 0; }
  .topbar-right { gap: 8px; flex-shrink: 0; }
  /* Sidebar permanece full-height em mobile também */
}

/* ── SMALL TABLET (≤ 768px) ────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Topbar ── */
  .topbar {
    height: 54px;
    padding: 0 14px;
  }

  .sidebar-header {
    height: 54px;
    padding: 0 44px 0 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .sidebar-brand-label { font-size: 0.6rem; margin-bottom: 2px; }
  .sidebar-brand-name  { font-size: 0.9rem; line-height: 1.15; }

  .sidebar-close { top: 50%; transform: translateY(-50%); }
  .sidebar-close:active { transform: translateY(-50%) scale(0.96); }

  .topbar-divider { display: none; }
  .page-title     { display: none; }

  /* ── Produção: 1 coluna em todos os celulares/tablets verticais ── */
  .prod-cards-grid { grid-template-columns: 1fr; gap: 14px; }

  /* ── KPI ── */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }

  .kpi-card { padding: 14px; }
  .kpi-card-label { font-size: 0.65rem; }
  .kpi-card-value { font-size: 1.6rem; }
  .kpi-card-sub   { font-size: 0.7rem; }

  /* ── Charts: 1 col ── */
  .charts-grid-2,
  .charts-grid-3 {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .chart-card { padding: 16px; }

  .insight-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .insight-card { padding: 16px; }

  /* ── Main ── */
  .main { padding: 14px 14px 90px; }

  /* ── Page header ── */
  .page-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
  }

  .page-header h2 { font-size: 1.2rem; }
  .page-header p  { font-size: 0.78rem; }

  /* ── Table toolbar: grid 2-col — filtros / busca / select+export ── */
  .table-toolbar {
    display: grid;
    grid-template-areas:
      "filters filters"
      "search  search"
      "select  export";
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
  }

  .table-filters        { grid-area: filters; }
  .origem-filter-select { grid-area: select;  width: 100%; font-size: 0.78rem; }
  .search-box           { grid-area: search;  width: 100%; }
  .search-box input     { width: 100%; }
  .export-btns          { grid-area: export;  display: flex; gap: 5px; align-items: center; flex-shrink: 0; }
  .export-btn           { white-space: nowrap; font-size: 0.76rem; padding: 8px 10px; }

  /* Chips: scroll horizontal em vez de quebrar linha */
  .table-filters {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px;
    padding-bottom: 2px;
  }
  .table-filters::-webkit-scrollbar { display: none; }

  .filter-chip {
    font-size: 0.68rem;
    padding: 4px 8px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .add-lead-btn {
    width: 100%;
    justify-content: center;
    padding: 9px 16px;
    font-size: 0.82rem;
  }

  /* ── Table ── */
  .leads-table thead th,
  .leads-table tbody td {
    padding: 9px 10px;
    font-size: 0.78rem;
  }

  /* ── Table footer ── */
  .table-footer {
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.72rem;
  }

  /* ── Modal ── */
  .modal {
    width: 100%;
    max-width: 480px;
    padding: 22px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-group.full { grid-column: 1; }
}


/* ══════════════════════════════════════════════════════════════════════════
   SAFE AREA — iOS PWA (notch + home indicator)
   ══════════════════════════════════════════════════════════════════════════ */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }

  /* O sidebar sempre cobre a tela inteira a partir do topo (top:0, regra
     !important logo acima) — nunca começa "abaixo da topbar", pra concordar
     com openSidebar()/closeSidebar() (app.js), que sempre forçam top:0 em
     qualquer tamanho de tela. Em vez de deslocar o painel inteiro pra fugir
     do notch (o que conflitava com essa regra e causava corte/salto visual
     dependendo do zoom), o próprio painel ganha um respiro no topo — o
     header (altura fixa) e o footer continuam do mesmo jeito, só o miolo
     rolável (.sidebar-nav, flex + overflow-y) absorve o espaço extra.
     Simétrico ao que .sidebar-footer já faz com o safe-area de baixo. */
  .sidebar {
    padding-top: env(safe-area-inset-top);
  }
}

/* ── MOBILE (≤ 480px) ──────────────────────────────────────────────────── */
@media (max-width: 480px) {

  /* ── Topbar ── */
  .topbar {
    height: 52px;
    padding: 0 12px;
    gap: 8px;
  }

  .logo-img {
    width: 30px;
    height: 30px;
    object-fit: cover;
    object-position: 50% 22%;
    border-radius: 50%;
  }

  .logo-text    { font-size: 0.88rem; }
  .theme-label  { display: none; }

  .theme-toggle { padding: 2px 2px 2px 6px; }

  /* ── KPI: 2 cols ── */
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
  }

  .kpi-card {
    padding: 12px 10px;
    border-radius: 8px;
  }

  .kpi-accent { height: 0; margin-right: 4px; }

  .kpi-card-label {
    font-size: 0.6rem;
    letter-spacing: 0.6px;
    margin-bottom: 6px;
  }

  .kpi-card-value { font-size: 1.45rem; }
  .kpi-card-sub   { font-size: 0.62rem; margin-top: 4px; }

  /* ── Charts ── */
  .charts-grid-2,
  .charts-grid-3 {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }

  .chart-card { padding: 14px; }

  .chart-card-title {
    font-size: 0.68rem;
    margin-bottom: 12px;
  }

  /* ── Insight grid: 2 cols ── */
  .insight-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .insight-card {
    padding: 13px 11px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 84px;
  }

  .insight-card-label {
    font-size: 0.57rem;
    letter-spacing: 0.7px;
    margin-bottom: 6px;
    line-height: 1.3;
  }

  .insight-card-big {
    font-size: 1.45rem;
    line-height: 1.1;
    word-break: break-word;
  }

  .insight-card-desc {
    font-size: 0.6rem;
    margin-top: 5px;
    line-height: 1.3;
  }

  /* ── Main ── */
  .main { padding: 10px 10px 90px; }

  /* ── Page header ── */
  .page-header {
    margin-bottom: 12px;
    padding-bottom: 10px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .page-header h2 { font-size: 1.05rem; }
  .page-header p  { font-size: 0.73rem; }

  /* ── Filter chips: scroll horizontal ── */
  .table-filters {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px;
    padding-bottom: 2px;
  }

  .table-filters::-webkit-scrollbar { display: none; }

  .filter-chip {
    font-size: 0.63rem;
    padding: 4px 9px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Table + toolbar: edge-to-edge (só leads e faturamento) ── */
  #page-leads .table-toolbar,
  #page-leads .table-wrap,
  #page-faturamento .table-wrap {
    border-radius: 0;
    margin: 0 -10px;
    width: calc(100% + 20px);
  }

  /* Toolbar edge-to-edge: compensa padding do grid */
  #page-leads .table-toolbar {
    padding: 10px;
  }

  .leads-table thead th,
  .leads-table tbody td {
    padding: 8px 9px;
    font-size: 0.74rem;
  }

  .leads-table thead th {
    font-size: 0.6rem;
    letter-spacing: 0.4px;
  }

  /* Oculta colunas menos importantes na tabela de leads */
  #page-leads .leads-table thead th:nth-child(3),
  #page-leads .leads-table tbody td:nth-child(3),
  #page-leads .leads-table thead th:nth-child(4),
  #page-leads .leads-table tbody td:nth-child(4),
  #page-leads .leads-table thead th:nth-child(6),
  #page-leads .leads-table tbody td:nth-child(6),
  #page-leads .leads-table thead th:nth-child(7),
  #page-leads .leads-table tbody td:nth-child(7) {
    display: none;
  }

  /* Oculta colunas secundárias na tabela de faturamento */
  #page-faturamento .leads-table thead th:nth-child(5),
  #page-faturamento .leads-table tbody td:nth-child(5),
  #page-faturamento .leads-table thead th:nth-child(6),
  #page-faturamento .leads-table tbody td:nth-child(6),
  #page-faturamento .leads-table thead th:nth-child(10),
  #page-faturamento .leads-table tbody td:nth-child(10) {
    display: none;
  }

  /* Oculta Taxa e Valor Gerado na tabela de indicações (já sem Ativos e Último Contato a partir de 700px) */
  .ind-table thead th:nth-child(5),
  .ind-table tbody td:nth-child(5),
  .ind-table thead th:nth-child(6),
  .ind-table tbody td:nth-child(6) {
    display: none;
  }

  /* Oculta Responsável na tabela LGPD */
  .lgpd-table thead th:nth-child(5),
  .lgpd-table tbody td:nth-child(5) {
    display: none;
  }

  .action-btn {
    padding: 4px 7px;
    font-size: 0.68rem;
  }

  .pill {
    font-size: 0.6rem;
    padding: 2px 6px;
  }

  /* ── Paginação compacta ── */
  .pagination {
    gap: 3px;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 4px 0;
    scrollbar-width: none;
  }

  .pagination::-webkit-scrollbar { display: none; }

  .page-btn,
  .page-arrow {
    padding: 5px 8px;
    font-size: 0.7rem;
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .page-ellipsis { padding: 5px 4px; font-size: 0.7rem; }

  /* ── Modal: bottom sheet ── */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    padding: 8px 16px 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    animation: slideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  }

  @keyframes slideUp {
    from { transform: translateY(100%); opacity: 0.6; }
    to   { transform: translateY(0);    opacity: 1;   }
  }

  /* Handle do bottom sheet */
  .modal::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 6px auto 16px;
  }

  .modal h3 {
    font-size: 1rem;
    margin-bottom: 14px;
    padding-bottom: 12px;
  }

  .form-input,
  .form-select {
    padding: 10px 12px;
    font-size: 16px; /* evita zoom iOS */
  }

  .form-label { font-size: 0.64rem; }

  .modal-footer {
    gap: 8px;
    margin-top: 14px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .btn-cancel,
  .btn-save {
    flex: 1;
    text-align: center;
    padding: 11px;
    font-size: 0.84rem;
    border-radius: 9px;
  }

  /* ── Produção: seletor e anel menores (1-col já definido em ≤768px) ── */
  .prod-mes-select { min-width: unset; width: 100%; }
  .prod-card-label-row { flex-wrap: wrap; gap: 4px; }
  .prod-meta-edit-btn  { font-size: 0.65rem; padding: 2px 7px; }
  /* Empilha anel + info verticalmente — info usa largura total, sem risco de corte */
  .prod-meta-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .prod-ring-wrap { width: 64px; height: 64px; }
  .prod-ring-pct  { font-size: 0.82rem; }
  .prod-meta-info { width: 100%; min-width: 0; }
  .prod-meta-info-value { font-size: 1.1rem; }
  .prod-meta-info-label,
  .prod-meta-info-goal  { font-size: 0.65rem; }

  /* ── Indicações KPI: ícone e fonte menores para caber em 2 cols ── */
  .ind-kpi-grid { gap: 10px; }
  .ind-kpi-card { padding: 12px 10px; gap: 10px; }
  .ind-kpi-icon { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
  .ind-kpi-icon svg { width: 16px; height: 16px; }
  .ind-kpi-val  { font-size: 1.1rem; overflow-wrap: break-word; }
  .ind-kpi-label { font-size: 0.62rem; }

  /* ── Funil compacto ── */
  .funnel-step { gap: 8px; margin-bottom: 8px; }
  .funnel-outer { height: 36px; }
  .funnel-inner {
    font-size: 0.7rem;
    padding-left: 8px;
    min-width: 55px;
  }
  .funnel-count  { font-size: 0.92rem; }
  .funnel-pct    { font-size: 0.62rem; }
  .funnel-meta   { min-width: 46px; }

  /* ── Barras ── */
  .bar-label { font-size: 0.7rem; min-width: 86px; }
  .bar-val   { font-size: 0.66rem; min-width: 22px; }

  /* ── Toast ── */
  .toast {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    right: 10px;
    transform: translateY(80px);
    white-space: normal;
    text-align: center;
    width: auto;
  }

  .toast.show { transform: translateY(0); }

  /* ── Kanban: colunas menores em telas muito pequenas ── */
  .kanban-col { flex: 0 0 155px; }

  /* ── Leads header: toggle + botão ficam na mesma linha mas quebram se necessário ── */
  #page-leads .page-header > div:last-child {
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
  }
  #page-leads .add-lead-btn {
    flex: 1;
    min-width: 130px;
    justify-content: center;
  }
  #page-leads .leads-view-toggle {
    flex: 0 0 auto;
  }
}

/* ── TINY MOBILE (≤ 360px) ─────────────────────────────────────────────── */
@media (max-width: 360px) {

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .kpi-card-value { font-size: 1.3rem; }
  .logo-text      { display: none; }

  .filter-chip {
    font-size: 0.6rem;
    padding: 4px 6px;
  }

  .insight-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .insight-card {
    padding: 10px 8px;
    min-height: 74px;
  }

  .insight-card-label { font-size: 0.54rem; margin-bottom: 5px; }
  .insight-card-big   { font-size: 1.2rem; }
  .insight-card-desc  { font-size: 0.57rem; margin-top: 4px; }

  .modal { padding: 6px 12px 16px; }
  .modal h3 { font-size: 0.95rem; }
  .topbar   { padding: 0 8px; }
  .main     { padding: 8px 8px 90px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   TOUCH — tap targets ≥ 44px, sem efeitos hover
   ══════════════════════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {

  .form-input,
  .form-select {
    min-height: 44px;
    font-size: 16px;
  }

  .login-field input {
    min-height: 44px;
    font-size: 16px;
  }

  .filter-chip {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .btn-cancel,
  .btn-save,
  .add-lead-btn,
  .export-btn,
  .login-btn {
    min-height: 44px;
  }

  .page-btn,
  .page-arrow {
    min-height: 36px;
    min-width: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .pago-check,
  .expirada-check {
    width: 32px;
    height: 32px;
  }

  .action-btn {
    min-height: 36px;
    min-width: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Remove hover, adiciona active */
  .kpi-card:hover {
    transform: none;
    border-color: var(--border);
    box-shadow: var(--shadow);
  }

  .kpi-card:active {
    transform: scale(0.97);
    border-color: var(--royal-mid);
  }

  .mini-nav-btn:hover { background: transparent; }

  /* Scrollbar invisível */
  ::-webkit-scrollbar { width: 0; height: 0; }
}

/* ══════════════════════════════════════════════════════════════════════════
   FATURAMENTO MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  .fat-filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .fat-filter-chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px;
  }

  .fat-filter-chips::-webkit-scrollbar { display: none; }

  .fat-chip {
    font-size: 0.71rem;
    padding: 7px 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .fat-month-select {
    width: 100%;
    padding: 9px 10px;
    font-size: 0.82rem;
  }

  .fat-visibility-btn { padding: 5px; }

  /* Fat total compacto */
  .fat-total-row { padding: 10px 12px; gap: 8px; }
  .fat-total-label { font-size: 0.7rem; }
  .fat-total-val   { font-size: 1rem; }
}

@media (max-width: 480px) {
  #page-faturamento .page-header {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   FICHA MODAL MOBILE + KANBAN + LEADS HEADER (≤ 600px)
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  .ficha-modal {
    width: 100% !important;
    border-radius: 16px 16px 0 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .ficha-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .ficha-avatar { width: 40px; height: 40px; font-size: 0.88rem; }
  .ficha-name   { font-size: 0.95rem; }
  .ficha-tab    { padding: 7px 10px; font-size: 0.72rem; }
  .kanban-col   { flex: 0 0 175px; }
  .view-btn     { padding: 5px 8px; font-size: 0.72rem; }

  /* section-header: empilha como page-header (regra que estava em style.css) */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .page-header .btn,
  .section-header .btn {
    align-self: stretch;
    justify-content: center;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   ALERTAS / AGENDA MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .alert-grid { grid-template-columns: 1fr; }
  .alert-card { padding: 12px 14px; }

  .alert-category-header {
    padding: 10px 14px;
    font-size: 0.78rem;
  }

  .alert-cat-count {
    font-size: 0.68rem;
    padding: 2px 8px;
  }

  /* Calendário da agenda: mais compacto */
  .agenda-page-nav { gap: 6px; margin-bottom: 14px; }
  .agenda-page-month-label { font-size: 0.85rem; }

  .agenda-page-grid {
    gap: 3px;
    padding: 10px;
  }

  .agenda-page-cell {
    min-height: 38px;
    padding: 4px 3px 3px;
    border-radius: 6px;
  }

  .agenda-page-day-num {
    font-size: 0.68rem;
    margin-bottom: 2px;
  }

  .agenda-page-dots {
    gap: 2px;
  }

  .agenda-page-dot {
    width: 5px;
    height: 5px;
  }

  .agenda-page-day-panel {
    padding: 12px 14px;
    margin-top: 10px;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   AI INSIGHT CARD MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  .ai-insight-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .refresh-insight-btn {
    width: 100%;
    justify-content: center;
  }

  .ai-insight-body {
    font-size: 0.82rem;
    line-height: 1.65;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   FOLLOW-UP PANEL MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Remove o padding-bottom excessivo que era para a bottom nav */
  .followup-inner { padding-bottom: 32px; }
}

@media (max-width: 480px) {
  .followup-inner { padding: 12px 12px 24px; }

  /* Empilha tipo + textarea no formulário de histórico */
  .reativ-hist-form-row { flex-direction: column; gap: 8px; }
  .reativ-hist-tipo-sel { width: 100%; }

  .followup-header { gap: 8px; padding-bottom: 14px; }
  .followup-back-btn { padding: 6px 10px; font-size: 0.78rem; }
  .followup-reativar-btn { padding: 8px 12px; font-size: 0.78rem; }
  #followupLeadName { font-size: 0.95rem; }
}

/* ══════════════════════════════════════════════════════════════════════════
   MRX IA MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .mrxia-chat { max-height: calc(100vh - 400px); max-height: calc(100dvh - 400px); }
  .mrxia-history-drawer { width: 300px; }
}

@media (max-width: 768px) {

  .mrxia-quick-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 6px;
    scrollbar-width: none;
  }

  .mrxia-quick-bar::-webkit-scrollbar { display: none; }

  .mrxia-quick {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.72rem;
    padding: 5px 12px;
  }

  .mrxia-chat {
    max-height: calc(100vh - 340px);
    max-height: calc(100dvh - 340px);
    min-height: 200px;
  }

  .mrxia-bubble { max-width: 90%; font-size: 0.84rem; }

  .mrxia-history-drawer { width: 100%; right: -100%; }
  .mrxia-input { font-size: 16px; }
  .mrxia-send-btn { width: 44px; height: 44px; }
}

@media (max-width: 480px) {

  #page-mrxia .page-header {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
  }

  #page-mrxia .page-header > div:first-child { flex: 1; min-width: 0; }
  #page-mrxia .page-header h2 { font-size: 1rem; }

  #page-mrxia .page-header > div:last-child {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0;
  }

  #mrxiaHistoryBtn,
  #mrxiaClearBtn {
    font-size: 0.7rem;
    padding: 5px 8px;
    white-space: nowrap;
  }

  .mrxia-chat {
    max-height: calc(100vh - 330px);
    max-height: calc(100dvh - 330px);
    min-height: 180px;
  }

  .mrxia-msg    { gap: 6px; }
  .mrxia-avatar { width: 28px; height: 28px; margin-left: 4px; }

  .mrxia-bubble {
    max-width: 93%;
    padding: 10px 12px;
    font-size: 0.82rem;
  }

  .mrxia-input-bar { gap: 6px; padding-top: 8px; }

  .mrxia-input {
    font-size: 16px;
    padding: 10px 12px;
    border-radius: 10px;
  }

  .mrxia-send-btn { width: 42px; height: 42px; border-radius: 10px; }

  .mrxia-welcome { padding: 22px 12px; }
  .mrxia-welcome h3 { font-size: 1rem; }
  .mrxia-welcome p  { font-size: 0.8rem; }

  .mrxia-history-item-title { font-size: 0.79rem; }
  .mrxia-history-item-meta  { font-size: 0.68rem; }
}

/* ══════════════════════════════════════════════════════════════════════════
   PAGE TITLE — esconde em telas médias
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) { .page-title { display: none; } }

/* ══════════════════════════════════════════════════════════════════════════
   KPI VALUE — menor em tablet
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) and (min-width: 641px) {
  .kpi-card-value { font-size: 1.5rem; }
}

/* ══════════════════════════════════════════════════════════════════════════
   TOUCH — MRX IA tap targets
   ══════════════════════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  .mrxia-quick    { min-height: 36px; display: inline-flex; align-items: center; }
  .mrxia-send-btn { min-height: 44px; min-width: 44px; }
  .mrxia-input    { min-height: 44px; font-size: 16px; }
  .fat-chip       { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; }
  .mrxia-history-item { min-height: 52px; }
  #mrxiaHistoryBtn,
  #mrxiaClearBtn  { min-height: 36px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   PWA — display: standalone (instalado na tela inicial)
   ══════════════════════════════════════════════════════════════════════════ */
@media (display-mode: standalone) {

  /* Topbar ocupa safe area do status bar no iOS/Android */
  .topbar {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(56px + env(safe-area-inset-top, 0px));
    background: var(--bg2);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }

  /* Conteúdo respeita home indicator no iOS + espaço pro termômetro fixo */
  .main {
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   ORÇAMENTOS MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Select de lead: largura total */
  #orcLeadSelect { max-width: 100% !important; width: 100%; }

  /* Painel de dados: botão Bradesco full-width quando quebra de linha */
  #orcAbrirBradescoBtn { width: 100%; justify-content: center; }
  #orcLeadPanel > div:first-child > div:last-child { margin-left: 0 !important; width: 100%; flex: 0 0 100%; }

  /* Botões do formulário empilhados */
  #orcFormCard > div:last-child { flex-direction: column; }
  #orcCancelBtn, #orcSaveBtn { width: 100%; justify-content: center; text-align: center; }

  /* Scroll-margin ajustado ao topbar de mobile */
  #orcFormCard { scroll-margin-top: 60px; }
}

@media (max-width: 480px) {
  #orcFormCard { scroll-margin-top: 52px; }

  /* Oculta colunas secundárias na tabela de orçamentos */
  #page-orcamentos .leads-table thead th:nth-child(3),
  #page-orcamentos .leads-table tbody td:nth-child(3),
  #page-orcamentos .leads-table thead th:nth-child(5),
  #page-orcamentos .leads-table tbody td:nth-child(5),
  #page-orcamentos .leads-table thead th:nth-child(7),
  #page-orcamentos .leads-table tbody td:nth-child(7) {
    display: none;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   BACKUPS MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Oculta Tipo e Tamanho — mantém Data, Registros e Ações */
  #page-backups .leads-table thead th:nth-child(2),
  #page-backups .leads-table tbody td:nth-child(2),
  #page-backups .leads-table thead th:nth-child(4),
  #page-backups .leads-table tbody td:nth-child(4) {
    display: none;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   FICHA ETAPA STEPS MOBILE — compactar em tela muito pequena
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 360px) {
  .ficha-etapa-steps { gap: 4px; }
  .ficha-etapa-step  { padding: 6px 6px 5px; min-width: 70px; }
  .ficha-etapa-step-label { font-size: 0.6rem; }
  .ficha-etapa-step-pct   { display: none; }
}

/* ══════════════════════════════════════════════════════════════════════════
   BARRA DE LABEL — min-width menor em ultra-mobile
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 360px) {
  .bar-label { min-width: 72px; font-size: 0.65rem; }
}

/* ══════════════════════════════════════════════════════════════════════════
   TOAST — nunca maior que viewport (previne transbordamento)
   ══════════════════════════════════════════════════════════════════════════ */
.toast {
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
}

/* ══════════════════════════════════════════════════════════════════════════
   PROD-META-POPOVER — touch-friendly no mobile
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .prod-meta-popover {
    width: calc(100vw - 32px);
    max-width: 320px;
    left: 50% !important;
    transform: translateX(-50%);
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   TABELA DE LEADS — min-width reduzido quando colunas ocultas
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Com 4 cols ocultas a tabela só precisa de ~340px */
  #page-leads      .leads-table { min-width: 340px; }
  #page-faturamento .leads-table { min-width: 400px; }
  #page-orcamentos .leads-table { min-width: 360px; }
  #page-backups    .leads-table { min-width: 280px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   ORC-DADO-CARDS — 2 por linha em mobile médio
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .orc-dado-card { flex: 1 1 calc(50% - 8px); min-width: 0; }
}
@media (max-width: 360px) {
  .orc-dado-card { flex: 1 1 100%; }
}

/* ══════════════════════════════════════════════════════════════════════════
   SINISTROS MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .sin-kpi-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }
  .sin-kpi-card { padding: 10px 8px; gap: 8px; }
  .sin-kpi-icon { width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0; }
  .sin-kpi-icon svg { width: 14px; height: 14px; }
  .sin-kpi-val  { font-size: 1.25rem; }
  .sin-kpi-label { font-size: 0.58rem; }

  /* Painel lateral: tela cheia abaixo de 640px */
  .sin-panel { width: 100vw; border-radius: 0; }
  .sin-panel-header { padding: 14px 16px 12px; }
  .sin-chat { padding: 12px 14px; }
  .sin-chat-input-bar { padding: 10px 14px; gap: 6px; }
  .sin-chat-input { font-size: 16px; }
}

@media (max-width: 480px) {
  .sin-kpi-grid { grid-template-columns: repeat(2, 1fr); }

  /* Filtros sinistros: coluna única */
  #page-sinistros .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .sin-filters {
    width: 100%;
    flex-direction: column;
    gap: 6px;
  }
  .sin-filters select { width: 100%; font-size: 0.82rem; }
}

/* ══════════════════════════════════════════════════════════════════════════
   CANCELADOS MOBILE
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Header da aba: empilha título e botão */
  .impl-header-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .btn-cancel-reg { width: 100%; justify-content: center; }

  /* Cards de cancelamento: padding compacto e empilhamento */
  .can-item { padding: 12px 14px; gap: 10px; }
  .can-item-avatar { width: 32px; height: 32px; font-size: 0.7rem; }
  .can-item-top { flex-wrap: wrap; }
  .can-item-right { width: 100%; flex-direction: row; align-items: center; justify-content: space-between; margin-top: 4px; }
}

@media (max-width: 480px) {
  #page-cancelados .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   ETAPA MINI BAR — evita transbordamento em telas muito estreitas
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
  .etapa-mini-btn {
    min-width: 0;
    width: 100%;
  }
  .etapa-mini-label { font-size: 0.63rem; }
  .etapa-mini-pct   { font-size: 0.61rem; padding: 1px 4px; }
  .etapa-dot        { width: 6px; height: 6px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   EXPORTAÇÃO GERAL — empilha botões em mobile estreito
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .expgeral-actions {
    flex-direction: column;
    gap: 8px;
  }
  .expgeral-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   ALERTAS DE VENCIMENTO (IMPLANTADOS) — mobile
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .venc-alerts-section { padding: 12px 13px; }

  .venc-chip {
    flex-wrap: wrap;
    gap: 8px;
    padding: 9px 11px;
  }

  .venc-chip-info { flex: 1 1 100%; }

  .venc-chip-days { flex: 1; }

  .venc-chip-wa {
    flex: 1;
    justify-content: center;
  }

  /* Mini-calendar day label: menor em telas muito estreitas */
  .impl-mc-day { font-size: 0.55rem; }

  /* Badge de vencimento no card: oculta "📅 " prefixo em telas pequenas */
  .impl-venc-badge { font-size: 0.65rem; padding: 1px 6px; }

  /* Impl cards: header compacto */
  .impl-card-header { padding: 11px 12px 10px; gap: 10px; }
  .impl-avatar { width: 34px; height: 34px; font-size: 0.72rem; }
}

@media (max-width: 360px) {
  .venc-chip-wa { font-size: 0.65rem; padding: 4px 8px; }
  .impl-card-meta { gap: 5px; }
}

/* ── FICHA TIMELINE — mobile ─────────────────────────────── */
@media (max-width: 600px) {
  .ficha-timeline-form-actions { flex-wrap: wrap; gap: 6px; }
  .ficha-timeline-tipo { width: 100%; }
  .ficha-timeline-save-btn { flex: 1; }
  .ficha-timeline-cancel-btn { flex: 1; margin-left: 0; }
  .ftl-meta { font-size: 0.68rem; }
  .ftl-title { font-size: 0.75rem; }
  .ftl-desc  { font-size: 0.76rem; }
  .ftl-item  { gap: 9px; }
  .ftl-content { padding-bottom: 14px; }
}
@media (max-width: 360px) {
  .ficha-timeline-add-btn { font-size: 0.68rem; padding: 3px 8px; }
  .ftl-dot { width: 10px; height: 10px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   LGPD TABLE — min-width para scroll horizontal
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  #page-lgpd .leads-table { min-width: 360px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   BAR-LABEL — truncar com ellipsis em telas ultra-estreitas
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 360px) {
  .bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80px;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   CHART-CARD-TITLE — padding-right para não sobrepor botão fullscreen
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .chart-card-title { padding-right: 32px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   SISTEMA ACESSO (admin) — responsivo em mobile
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .sistema-user-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .sistema-user-card > div:last-child {
    align-self: stretch;
    display: flex;
    gap: 6px;
  }
  .sistema-user-card > div:last-child .btn {
    flex: 1;
    justify-content: center;
    text-align: center;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   NOVO VENDEDOR MODAL — bottom sheet em mobile
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  #novoVendedorOverlay { align-items: flex-end; padding: 0; }
  #novoVendedorOverlay .modal {
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 100%;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  }
}
