/* =====================================================================
   Camada mobile "app" (v2) — só entra abaixo de 1024px e só com o cookie
   crm_mobile_v2 (ativa por ?mobile_v2=1, desativa por ?mobile_v2=0).
   Não altera nada no desktop. Reaproveita a identidade do sistema:
   --primary-color do white label, Inter, wz-* e o mesmo tab bar/menu.
   ===================================================================== */

/* Transição entre páginas (navegação normal) — navegadores que suportam
   cross-document view transitions (Chrome/Android 126+, Safari 18.2+). */
@view-transition {
  navigation: auto;
}
@keyframes mv2-vt-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes mv2-vt-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (max-width: 1023px) {
  ::view-transition-old(root) { animation: 140ms ease-out both mv2-vt-out; }
  ::view-transition-new(root) { animation: 220ms cubic-bezier(.2, .8, .2, 1) both mv2-vt-in; }
}

@media (max-width: 1023px) {
  :root {
    --mv2-nav-h: 64px;
    --mv2-safe-b: env(safe-area-inset-bottom, 0px);
    --mv2-radius: 14px;
    --mv2-ease: cubic-bezier(.32, .72, 0, 1);
  }

  /* ---------- Toque ---------- */
  html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
  }
  body {
    touch-action: manipulation;
  }
  .content {
    padding: 12px;
    padding-bottom: calc(var(--mv2-nav-h) + 16px + var(--mv2-safe-b));
    overscroll-behavior: contain;
    scrollbar-width: none;
    animation: mv2-page-in .18s ease-out both;
  }
  .content::-webkit-scrollbar,
  .chat-list::-webkit-scrollbar,
  #kanban-board::-webkit-scrollbar {
    display: none;
  }
  @keyframes mv2-page-in { from { opacity: 0; } to { opacity: 1; } }

  /* Feedback de pressão (no lugar do hover, que não existe no toque) */
  .wz-btn, .btn, .mobile-nav-item, .mob-sheet__item,
  .wz-card a[href], .chat-item, .kanban-card, .contact-card,
  .content a.rounded-2xl[href], .content a.rounded-xl[href] {
    transition: transform .12s var(--mv2-ease), background-color .15s, border-color .15s, opacity .15s;
  }
  .wz-btn:active, .btn:active, .mob-sheet__item:active,
  .wz-card a[href]:active, .content a.rounded-2xl[href]:active, .content a.rounded-xl[href]:active {
    transform: scale(.97);
  }
  .chat-item:active, .kanban-card:active {
    transform: scale(.985);
  }
  .wz-btn:hover, .btn:hover { transform: none; }

  /* ---------- Botões e campos: alvo mínimo de 44px ---------- */
  .wz-btn { min-height: 44px; border-radius: 12px; padding-left: 1rem; padding-right: 1rem; }
  .wz-btn-sm { min-height: 38px; border-radius: 10px; }
  .wz-btn-icon { width: 44px; padding: 0; }
  .wz-btn-sm.wz-btn-icon { width: 38px; }
  .btn { min-height: 42px; border-radius: 12px; }
  .content button.h-9, .content a.h-9 { height: 42px; min-width: 42px; }
  .content button.w-9 { width: 42px; }

  /* Fonte de 16px evita o zoom automático do iOS ao focar */
  .content input:where(:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file])),
  .content select, .content textarea,
  .wz-input, .wz-select, .wz-textarea {
    font-size: 16px !important;
  }
  .wz-input, .wz-select { min-height: 46px; border-radius: 12px; }
  .wz-textarea { border-radius: 12px; }
  .content :where(input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number], input[type=url], input[type=password], input[type=date], select) {
    min-height: 46px;
  }
  .content :where(input, select, textarea):focus-visible {
    outline: 2px solid color-mix(in srgb, var(--primary-color, #22c55e) 55%, transparent);
    outline-offset: 1px;
  }

  /* ---------- Cards ---------- */
  .wz-card { border-radius: 16px; }
  .wz-card-body { padding: 16px; }
  .wz-stat { border-radius: 14px; }

  /* ---------- Cabeçalho das páginas (page_header.php e cópias) ----------
     O topbar usa -mx-6/-mt-6 (24px) e o conteúdo mobile tem 12px de padding:
     ele vazava 12px pra fora e cortava título e botões. Agora casa com o
     padding, fica fixo no topo e as ações rolam na horizontal. */
  .content div.-mx-6.-mt-6 {
    margin: -12px -12px 12px !important;
    height: 56px;
    padding: 0 12px 0 16px;
    position: sticky;
    top: -12px;
    z-index: 35;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    backdrop-filter: blur(16px) saturate(160%);
    gap: 10px;
  }
  .dark .content div.-mx-6.-mt-6,
  html.dark .content div.-mx-6.-mt-6 {
    background: rgba(10, 10, 10, .88);
  }
  .content div.-mx-6.-mt-6 > h1 {
    font-size: 17px !important;
    letter-spacing: -.01em;
    min-width: 0;
  }
  .content div.-mx-6.-mt-6 > div.flex {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    max-width: 70%;
    padding: 4px 0;
    justify-content: flex-start;
  }
  .content div.-mx-6.-mt-6 > div.flex::-webkit-scrollbar { display: none; }
  .content div.-mx-6.-mt-6 > div.flex > * { flex-shrink: 0; }

  /* ---------- Tab bar (barra inferior) ---------- */
  .mobile-nav {
    height: calc(var(--mv2-nav-h) + var(--mv2-safe-b));
    padding: 6px 4px 0;
    padding-bottom: var(--mv2-safe-b);
    align-items: flex-start;
    justify-content: space-around;
    background: rgba(255, 255, 255, .95);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid rgba(15, 23, 42, .08);
    box-shadow: 0 -6px 24px rgba(15, 23, 42, .06);
    z-index: 60;
  }
  .dark .mobile-nav, html.dark .mobile-nav {
    background: rgba(12, 12, 14, .94);
    border-top-color: rgba(255, 255, 255, .08);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .35);
  }
  .mobile-nav-item {
    position: relative;
    flex: 1 1 0;
    max-width: 96px;
    height: 54px;
    padding: 4px 0 0;
    gap: 4px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0;
    color: #64748b;
    -webkit-user-select: none;
    user-select: none;
    transition: color .18s, transform .12s var(--mv2-ease);
  }
  .mobile-nav-item:active {
    transform: scale(.92);
    opacity: 1;
  }
  .mobile-nav-item svg,
  .mobile-nav-item .mobile-nav-avatar {
    width: 24px;
    height: 24px;
    position: relative;
    z-index: 1;
    stroke-width: 1.9;
    transition: transform .22s var(--mv2-ease), color .18s;
  }
  /* Pílula atrás do ícone ativo (substitui a linha fina do topo) */
  .mobile-nav-item.active::before {
    content: '';
    position: absolute;
    top: 1px;
    left: 50%;
    height: 32px;
    width: 58px;
    transform: translateX(-50%);
    border-radius: 999px;
    background: rgba(15, 23, 42, .06);
    background: color-mix(in srgb, var(--primary-color, #22c55e) 16%, transparent);
    animation: mv2-pill .28s var(--mv2-ease) both;
  }
  @keyframes mv2-pill {
    from { transform: translateX(-50%) scaleX(.55); opacity: .4; }
    to { transform: translateX(-50%) scaleX(1); opacity: 1; }
  }
  .mobile-nav-item.active svg {
    transform: translateY(-1px);
    stroke-width: 2.2;
  }
  .mobile-nav-item.active .mobile-nav-avatar {
    border-color: var(--primary-color, #22c55e);
    box-shadow: 0 0 0 2px #fff;
  }
  .mobile-nav-item.active {
    color: color-mix(in srgb, var(--primary-color, #22c55e) 78%, #0f172a);
  }
  .dark .mobile-nav-item.active, html.dark .mobile-nav-item.active {
    color: color-mix(in srgb, var(--primary-color, #22c55e) 85%, #fff);
  }
  .mobile-nav-item span {
    line-height: 1;
    z-index: 1;
  }

  /* Botão flutuante do suporte e dicas: acima da barra, sem tampar a aba "Eu" */
  #scw-root {
    bottom: calc(var(--mv2-nav-h) + 14px + var(--mv2-safe-b)) !important;
    right: 14px !important;
  }
  #scw-root > button, #scw-root .scw-launcher, #scw-root .scw-fab {
    width: 52px !important;
    height: 52px !important;
  }
  #wf-inbox-tip { display: none !important; }

  /* Toasts do rodapé nunca atrás da barra */
  #toast-container.fixed.top-4 { top: 12px; right: 12px; left: 12px; }

  /* ---------- Menu inferior (bottom-sheet) ---------- */
  .mob-sheet { display: block; pointer-events: none; }
  .mob-sheet__overlay {
    opacity: 0;
    transition: opacity .22s ease;
    background: rgba(15, 23, 42, .45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
  .mob-sheet__panel {
    transform: translateY(105%);
    transition: transform .34s var(--mv2-ease);
    animation: none;
    border-radius: 24px 24px 0 0;
    border-top: 0;
    padding: 10px 16px 0;
    padding-bottom: calc(14px + var(--mv2-safe-b));
    max-height: 86dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, .22);
    will-change: transform;
  }
  .mob-sheet.is-open { pointer-events: auto; }
  .mob-sheet.is-open .mob-sheet__overlay { opacity: 1; }
  .mob-sheet.is-open .mob-sheet__panel { transform: translateY(0); }
  .mob-sheet__panel.is-dragging { transition: none; }
  .mob-sheet__handle {
    width: 44px;
    height: 5px;
    background: rgba(100, 116, 139, .35);
    margin: 0 auto 14px;
  }
  .mob-sheet__title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.01em;
    margin: 0 4px 12px;
  }
  .mob-sheet__item {
    min-height: 52px;
    border-radius: var(--mv2-radius);
    padding: 12px 14px;
    font-weight: 500;
    background: var(--bg, #fff);
  }
  .mob-sheet__item:hover { background: var(--bg, #fff); }
  .mob-sheet__item:active { background: var(--muted, #f1f5f9); }
  .mob-sheet__item-label i, .mob-sheet__item-label svg { width: 20px; height: 20px; }

  /* Acessos rápidos: grade de atalhos com ícone colorido (cara de app) */
  #mobile-quick-menu-modal .mob-sheet__panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    align-content: start;
  }
  #mobile-quick-menu-modal .mob-sheet__handle,
  #mobile-quick-menu-modal .mob-sheet__title,
  #mobile-quick-menu-modal .mob-sheet__item[style] {
    grid-column: 1 / -1;
  }
  #mobile-quick-menu-modal .mob-sheet__title { margin-bottom: 4px; }
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) {
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 12px 6px 10px;
    min-height: 92px;
    border-color: transparent;
    background: var(--muted, #f5f7fa);
    text-align: center;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text, #1e293b);
  }
  #mobile-quick-menu-modal .mob-sheet__item:not([style]):active {
    background: color-mix(in srgb, var(--primary-color, #22c55e) 14%, var(--muted, #f5f7fa));
  }
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) > i:last-child,
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) > svg:last-child {
    display: none; /* seta */
  }
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) .mob-sheet__item-label {
    flex-direction: column;
    gap: 8px;
  }
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) .mob-sheet__item-label i,
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) .mob-sheet__item-label svg {
    width: 44px;
    height: 44px;
    padding: 11px;
    border-radius: 14px;
    background: #fff;
    color: var(--primary-color, #22c55e);
    color: color-mix(in srgb, var(--primary-color, #22c55e) 80%, #0f172a);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
  }
  .dark #mobile-quick-menu-modal .mob-sheet__item:not([style]) .mob-sheet__item-label svg,
  html.dark #mobile-quick-menu-modal .mob-sheet__item:not([style]) .mob-sheet__item-label svg {
    background: rgba(255, 255, 255, .06);
    color: color-mix(in srgb, var(--primary-color, #22c55e) 85%, #fff);
  }
  #mobile-quick-menu-modal .mob-sheet__item[style] {
    margin: 0;
    background: var(--bg, #fff);
  }

  /* ---------- Modais viram folhas de baixo ---------- */
  .wz-modal { padding: 0; align-items: flex-end; }
  .wz-modal-panel {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    animation: mv2-sheet-up .32s var(--mv2-ease) both;
  }
  .wz-modal-body { padding: 14px 16px; }
  .wz-modal-header, .wz-modal-footer { padding: 12px 16px; }
  .wz-modal-footer { padding-bottom: calc(12px + var(--mv2-safe-b)); }
  .wz-modal-footer .wz-btn { flex: 1 1 0; }
  #wz-confirm-modal { align-items: flex-end !important; padding: 0 !important; }
  #wz-confirm-modal > div {
    width: 100%;
    max-width: 100% !important;
    border-radius: 22px 22px 0 0 !important;
    padding-bottom: calc(16px + var(--mv2-safe-b));
    animation: mv2-sheet-up .32s var(--mv2-ease) both;
  }
  @keyframes mv2-sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

  /* ---------- Inbox ---------- */
  .chat-item { border-radius: 14px; }
  .chat-item.active, .chat-item.is-active {
    background: color-mix(in srgb, var(--primary-color, #22c55e) 8%, transparent);
  }

  /* ---------- Kanban: colunas "paginadas" com snap ---------- */
  .kanban-page #kanban-board {
    scroll-snap-type: x mandatory;
    scroll-padding-left: 12px;
    padding: 10px;
    border-radius: 16px;
  }
  .kanban-page .kanban-col {
    scroll-snap-align: start;
    width: min(86vw, 360px);
    min-width: min(86vw, 360px);
    border-radius: 14px;
  }
  .kanban-page .kb-head-title { font-size: 20px; }


  /* Inbox: fileira de ações do topo rola na horizontal (não estoura em 360px) */
  .content div.mb-2\.5.flex.items-center.gap-1\.5 {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 8px;
    padding: 2px 2px 4px;
  }
  .content div.mb-2\.5.flex.items-center.gap-1\.5::-webkit-scrollbar { display: none; }
  .content div.mb-2\.5.flex.items-center.gap-1\.5 > * { flex-shrink: 0; }

  /* Configurações/Apps: cards sem altura mínima de desktop (sobrava um vazio enorme) */
  .content [class*="min-h-[152"], .content [class*="min-h-[160"], .content [class*="min-h-[140"] {
    min-height: 0 !important;
  }

  /* Kanban: cabeçalho da página quebra em duas linhas em vez de cortar a estrela/filtro */
  .kanban-page div.justify-between:has(> div.gap-4 > .kb-head) {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .kanban-page div.gap-4:has(> .kb-head) { gap: 10px; min-width: 0; max-width: 100%; }
  .kanban-page .kb-head { min-width: 0; }
  .kanban-page .kb-head > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

  /* ---------- Contatos ---------- */
  .contacts-surface { border-radius: 16px; }
}

/* Telas muito estreitas */
@media (max-width: 360px) {
  .mobile-nav-item { font-size: 10px; }
  .mobile-nav-item svg, .mobile-nav-item .mobile-nav-avatar { width: 22px; height: 22px; }
  #mobile-quick-menu-modal .mob-sheet__item:not([style]) { min-height: 84px; font-size: 12px; }
}

/* Respeita quem desligou animações no aparelho */
@media (prefers-reduced-motion: reduce) {
  .content, .mob-sheet__panel, .wz-modal-panel, #wz-confirm-modal > div,
  .mobile-nav-item.active::before { animation: none !important; transition: none !important; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}

/* ===================== Rodada 2 (06/09/2026) ===================== */
@media (max-width: 1023px) {
  /* ---------- Cabeçalho da conversa em UMA linha ---------- */
  .chat-header {
    padding: 6px 8px 6px 4px !important;
    min-height: 56px;
    gap: 6px !important;
  }
  .chat-header .inbox-hdr-main {
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
  }
  .chat-header .inbox-hdr-identity { flex: 1 1 55%; min-width: 0; width: auto; }
  .chat-header .inbox-hdr-identity .title { font-size: 14px; line-height: 1.2; }
  .chat-header .inbox-hdr-identity .subtitle { line-height: 1.1; }
  .chat-header .inbox-hdr-identity .subtitle * { font-size: 11px; }
  .chat-header .inbox-header-tags {
    flex: 0 1 auto !important;
    min-width: 0;
    width: auto !important;
    max-width: 42% !important;
  }
  .chat-header .inbox-header-tags > button {
    padding: 4px 8px;
    gap: 4px;
    box-shadow: none;
  }
  .chat-header .inbox-header-tags > button > div:first-child { max-width: 100%; }
  .chat-header > div:first-child > span[class*="rounded-full"],
  .chat-header > div:first-child > div[class*="h-10"] {
    width: 36px !important;
    height: 36px !important;
  }
  .chat-header button[class*="h-10"] { height: 38px; width: 38px; }

  /* ---------- Deslizar nos cards do Inbox ---------- */
  [data-conversation-id][role="button"] { touch-action: pan-y; }
  .mv2-swipe-row {
    transition: transform .22s var(--mv2-ease);
    will-change: transform;
    position: relative;
    z-index: 2;
  }
  .mv2-swipe-row.mv2-swiping { transition: none; }
  .mv2-swipe-hint {
    position: fixed;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 4px;
    border: 0;
    border-radius: 14px;
    font: 600 11px/1 Inter, system-ui, sans-serif;
    color: #fff;
    background: #dc2626;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .16);
    pointer-events: none;
    opacity: 0;
    transform: scale(.92);
    transition: opacity .12s, transform .16s var(--mv2-ease), background-color .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .mv2-swipe-hint.is-visible { transform: scale(1); }
  .mv2-swipe-hint.is-armed { transform: scale(1.04); }
  .mv2-swipe-hint.is-open { pointer-events: auto; transform: scale(1); }
  .mv2-swipe-hint.is-open:active { transform: scale(.96); filter: brightness(.92); }
  .mv2-swipe-hint.mv2-left { background: #dc2626; }
  .mv2-swipe-hint.mv2-right { background: #2563eb; }
  .mv2-swipe-hint .mv2-swipe-ico { display: flex; }
  .mv2-swipe-hint .mv2-swipe-lbl { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mv2-swipe-hint svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
}

/* ===================== Rodada 4 (06/09/2026): topo da lista do Inbox ===================== */
@media (max-width: 1023px) {
  .mv2-inbox-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
  .mv2-seg { flex: 1 1 auto; min-width: 0; margin: 0; }
  .mv2-seg > button { padding: 7px 8px; font-size: 12px; white-space: nowrap; }
  .mv2-more { position: relative; flex-shrink: 0; }
  .mv2-more-menu {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 70; width: 236px; padding: 6px;
    border-radius: 16px; border: 1px solid var(--border, #e2e8f0); background: var(--bg, #fff);
    box-shadow: 0 18px 40px rgba(15, 23, 42, .18); animation: mv2-sheet-up .18s var(--mv2-ease) both;
  }
  .mv2-more-item {
    display: flex; width: 100%; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 12px;
    font: 500 14px/1.2 Inter, system-ui, sans-serif; color: var(--text, #334155); text-align: left;
    background: transparent; border: 0; text-decoration: none;
  }
  .mv2-more-item:active { background: var(--muted, #f1f5f9); }
  .mv2-more-item > svg { width: 18px; height: 18px; flex-shrink: 0; color: #64748b; }
  .mv2-more-item > span { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mv2-more-item .mv2-more-badge { flex: 0 0 auto; border-radius: 999px; background: #0f172a; color: #fff; font-size: 10px; font-weight: 600; padding: 2px 6px; }
  .dark .mv2-more-item .mv2-more-badge, html.dark .mv2-more-item .mv2-more-badge { background: #e4e4e7; color: #0f172a; }
  .mv2-search-row { display: flex; align-items: center; gap: 8px; }
  .mv2-search-input { flex: 1 1 auto; min-width: 0; }
  .mv2-filter-btn { flex-shrink: 0; height: 46px; min-height: 46px; border-radius: 999px; padding: 0 12px; gap: 6px; }
  .inbox-conversation-list .mv2-tabs { padding: 3px; gap: 3px; border-radius: 12px; margin-bottom: 0; }
  .inbox-conversation-list .mv2-tab { min-height: 34px; flex-direction: row; gap: 6px; padding: 5px 6px; border-radius: 9px; }
  .inbox-conversation-list .mv2-tab > span:first-child { font-size: 12px; }
  .inbox-conversation-list .mv2-tab-count { min-width: 20px; padding: 1px 6px; font-size: 10px; }
  .inbox-conversation-list .mv2-seg > button { padding: 7px 8px; font-size: 12px; }
  .inbox-conversation-list .mv2-filter-btn { height: 46px; min-height: 46px; border-radius: 999px; padding: 0 12px; gap: 6px; }
}

/* ===================== 06/09/2026 (noite): cards do Inbox sem os botõezinhos ===================== */
@media (max-width: 1023px) {
  /* Encerrar (⊗) e "marcar como não lida" saem da vista no celular: viraram o gesto de deslizar.
     Ficam no DOM porque o mobile-app.js aciona esses mesmos botões ao tocar no botão revelado. */
  .inbox-conversation-list [data-conversation-id][role="button"] button:has(> svg[class*="circle-x"]),
  .inbox-conversation-list [data-conversation-id][role="button"] button:has(> svg[class*="x-circle"]),
  .inbox-conversation-list [data-conversation-id][role="button"] button:has(> svg[class*="mail-open"]) {
    display: none !important;
  }
}
