/* ============================================================================
   CRM Sirius — responsive.css
   Dono ÚNICO da responsividade do CRM. Carrega DEPOIS de style.css e
   sirius-ui.css, então vence a cascata sem precisar editar os arquivos grandes.

   Padrão Sirius de breakpoints (replicar nos outros sistemas):
     phone   : ≤ 640px   → navegação por barra inferior (tipo app)
     tablet  : 641–1024px → sidebar vira trilho de ícones
     desktop : 1025–1599  → layout padrão
     tv/wide : ≥ 1600px   → conteúdo com respiro, tipografia maior

   Regra de ouro: alvo de toque mínimo 44px, nada de conteúdo escondido
   atrás de barra fixa, safe-area do iPhone respeitada.
   ============================================================================ */

/* ── Default: elementos de nav mobile escondidos (media query de phone liga).
   Fica ANTES das media queries pra que o display:flex/block delas vença por
   ordem de fonte (mesma especificidade). ── */
#mtabbar { display: none; }
#mtab-more { display: none; }

/* ── 0. Base tátil (vale em qualquer tamanho) ───────────────────────────── */
* { -webkit-tap-highlight-color: transparent; }
@media (pointer: coarse) {
  /* alvos de toque confortáveis em telas de dedo */
  .sb-item, .mtab, .tb-btn, .btn-primary, .btn-ghost, .btn-sm,
  .panel-close, .cdp-close, .panel-back, .act-filter-btn, .cfg-tab { min-height: 40px; }
  input, select, textarea { font-size: 16px; } /* evita zoom automático do iOS ao focar */
}

/* ============================================================================
   1. TV / MONITOR GRANDE  ( ≥ 1600px )
   Aproveita a tela sem esticar tudo: colunas do board maiores, listas com
   largura de leitura confortável, base tipográfica um degrau acima.
   ============================================================================ */
@media (min-width: 1600px) {
  body { font-size: 15px; }
  .kanban-col { width: 320px; min-width: 320px; }
  #board-container { padding: 26px 32px; }
  .view-header, #main-toolbar, .contacts-toolbar { padding-left: 32px; padding-right: 32px; }
  /* seções de config/relatórios não viram uma faixa infinita */
  #dashboard-body, #reports-body, #settings-body, #automations-list { max-width: 1500px; }
}
@media (min-width: 2000px) {
  body { font-size: 16px; }
  #app { max-width: 2400px; margin: 0 auto; } /* em TV 4K não espalha de ponta a ponta */
}

/* ============================================================================
   2. TABLET / iPad  ( 641 – 1024px )
   Mantém a sidebar como trilho de ícones (a regra de 860px do sirius-ui já
   começa isso; aqui estendemos até 1024 e refinamos os alvos de toque).
   ============================================================================ */
@media (min-width: 641px) and (max-width: 1024px) {
  #sidebar { width: 60px !important; }
  #sidebar .sb-label, #sidebar .sb-ws-btn, #sidebar .sb-user-email,
  #sidebar .sb-toggle, #sidebar .sb-sec { display: none !important; }
  #sidebar .sb-logo { font-size: 0; gap: 0; }
  #sidebar .sb-item, #sidebar .sb-refresh, #sidebar .sb-logout { justify-content: center; padding: 12px 0; }
  #sidebar .sb-item { min-height: 44px; }

  /* painel de detalhe do deal não toma a tela toda no tablet */
  #side-panel { width: min(520px, 82vw); }

  /* painel de detalhe do contato como overlay deslizante (não empurra a tabela) */
  .contact-detail-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 84vw) !important;
    z-index: 62; box-shadow: -12px 0 40px rgba(0,0,0,.4); transform: translateX(100%); transition: transform .2s; }
  .contact-detail-panel.open { transform: translateX(0); }

  /* board: colunas um pouco mais estreitas pra caber mais no viewport */
  .kanban-col { width: 260px; min-width: 260px; }
}

/* ============================================================================
   3. PHONE  ( ≤ 640px )  — experiência tipo app
   ============================================================================ */
@media (max-width: 640px) {

  /* 3.1 — Sidebar sai; barra inferior entra ------------------------------- */
  #sidebar { display: none !important; }
  #mtabbar { display: flex; }

  /* conteúdo ocupa tudo e deixa espaço pra barra inferior */
  #main-content { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

  /* headers e toolbars mais compactos e roláveis quando lotam */
  .view-header { padding: 12px 16px; }
  .view-title { font-size: 17px; }
  #main-toolbar { padding: 10px 14px; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .contacts-toolbar { flex-wrap: wrap; padding: 12px 14px; gap: 8px; }

  /* 3.2 — Board: uma etapa por vez, deslizando com snap ------------------- */
  #board-container { padding: 12px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
  #board { gap: 12px; min-height: 0; }
  .kanban-col {
    width: calc(100vw - 24px); min-width: calc(100vw - 24px);
    scroll-snap-align: center;
    max-height: calc(100dvh - 168px);
  }

  /* 3.2b — Cards do deal: alvos de toque grandes (dedo não pega 2 botões) - */
  .deal-card { padding: 14px 14px 12px; }
  .dc-title { font-size: 15.5px; white-space: normal; }
  .dc-sub { font-size: 12px; }
  .dc-val { font-size: 16px; }
  .dc-val.none { font-size: 13px; }
  .deal-actions { gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--sd-hair); justify-content: space-between; }
  .da-btn { padding: 11px; border-radius: 11px; flex: 1; }
  .da-btn svg { width: 20px; height: 20px; }
  .da-btn:active { background: rgba(255,255,255,.14); }
  /* checkbox de seleção do card maior e sempre visível no mobile */
  .deal-card-check { width: 22px; height: 22px; opacity: 1 !important; top: 12px; right: 12px; }

  /* 3.3 — Contatos: tabela vira lista de cards tocáveis ------------------- */
  .contacts-table-wrap { overflow-x: visible; }
  .contacts-table-wrap table { min-width: 0; width: 100%; }
  .contacts-table-wrap thead { display: none; }               /* sem cabeçalho de colunas */
  .contacts-table-wrap tbody,
  .contacts-table-wrap tr,
  .contacts-table-wrap td { display: block; width: 100%; }
  .contacts-table-wrap tr {
    position: relative;
    border: 1px solid var(--border); border-radius: 14px;
    padding: 12px 44px 12px 14px; margin-bottom: 10px;
    background: var(--surface);
  }
  .contacts-table-wrap tbody td { border-bottom: none; padding: 0; white-space: normal; }
  /* esconde colunas de baixo valor no celular (check, empresa, origem, responsável, últ.atividade, criado) */
  .contacts-table-wrap td.td-check,
  .contacts-table-wrap td:nth-child(4),
  .contacts-table-wrap td:nth-child(6),
  .contacts-table-wrap td:nth-child(7),
  .contacts-table-wrap td:nth-child(8),
  .contacts-table-wrap td.ct-date { display: none; }
  /* nome em destaque, whatsapp e tags abaixo */
  .contacts-table-wrap td.td-contact-name { margin-bottom: 6px; }
  .contacts-table-wrap td.td-contact-name .ct-nm { font-size: 15px; font-weight: 600; }
  .contacts-table-wrap td.ct-mono { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
  .contacts-table-wrap td.contact-tags { display: flex; flex-wrap: wrap; gap: 4px; }
  /* botão conversar como ícone flutuante no canto do card */
  .contacts-table-wrap td.td-chat { position: absolute; top: 10px; right: 10px; width: auto; }
  .contacts-table-wrap td.td-chat .ct-chat-btn { width: 40px; height: 40px; }
  #contacts-count { padding: 0 4px; }

  /* 3.4 — Painel do deal em tela cheia ------------------------------------ */
  #side-panel { width: 100vw; z-index: 80; }
  .panel-header { padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top, 0px)); }

  /* conv-mode (inbox) no phone: painel cobre a tela inteira (sidebar não existe) */
  #app.conv-mode #side-panel { left: 0 !important; }

  /* 3.5 — Painel de detalhe do contato em tela cheia ---------------------- */
  .contact-detail-panel {
    position: fixed; inset: 0; width: 100vw !important; z-index: 80;
    transform: translateX(100%); transition: transform .22s ease; border-left: none;
  }
  .contact-detail-panel.open { transform: translateX(0); width: 100vw !important; }
  .cdp-header { padding-top: calc(16px + env(safe-area-inset-top, 0px)); }

  /* sidebar direita do chat (notas/tarefas) também em tela cheia */
  .chat-sidebar { position: fixed; inset: 0; width: 100vw; z-index: 82; }

  /* 3.6 — Modais viram bottom-sheet -------------------------------------- */
  #modal-overlay { align-items: flex-end; }
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92dvh;
    padding: 22px 18px calc(20px + env(safe-area-inset-bottom, 0px));
    animation: sheet-up .22s ease;
  }
  .modal-wide { max-width: 100% !important; }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

  /* 3.7 — FAB acima da barra inferior ------------------------------------ */
  .fab { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); right: 18px; }

  /* agenda empilha e usa altura dinâmica do viewport mobile */
  .agenda-layout { grid-template-columns: 1fr; height: auto; padding: 0 14px 20px; }
  .agenda-timeline { height: auto; }

  /* toast sobe pra não brigar com a barra inferior */
  #toast { bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important; }
}

/* ── 3.8 — telas muito estreitas (≤ 380px): aperta os rótulos da barra ── */
@media (max-width: 380px) {
  .mtab { font-size: 9px; }
  .mtab svg { width: 21px; height: 21px; }
}

/* ============================================================================
   4. Barra de navegação inferior (mobile tab bar)  +  sheet "Mais"
   Escondida por padrão; a media query de phone acima liga o display.
   ============================================================================ */
#mtabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  height: calc(72px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgba(0,0,0,.4);
}
.mtab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 11.5px; font-weight: 600; font-family: inherit;
  padding: 8px 0 6px; position: relative; transition: color .15s;
}
.mtab svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.mtab.active { color: var(--cyan, var(--accent)); }
.mtab.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 40px; height: 4px; border-radius: 0 0 4px 4px;
  background: var(--grad-primary, var(--accent));
  box-shadow: 0 0 12px rgba(0,246,245,.6);
}
/* ícone da aba ativa ganha um leve realce */
.mtab.active svg { filter: drop-shadow(0 0 8px rgba(0,246,245,.45)); }
/* bolinha de notíficação (ex: conversas não lidas) */
.mtab-badge {
  position: absolute; top: 4px; right: calc(50% - 20px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
}
.mtab-badge.show { display: flex; }

/* Sheet "Mais" — folha de baixo com o resto das telas + workspace/sair */
#mtab-more { position: fixed; inset: 0; z-index: 85; }
#mtab-more.open { display: block; }
.mtab-more-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.mtab-more-sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 8px 14px calc(18px + env(safe-area-inset-bottom, 0px));
  max-height: 82dvh; overflow-y: auto;
  animation: sheet-up .22s ease;
}
.mtab-more-grab { width: 40px; height: 4px; border-radius: 3px; background: var(--border);
  margin: 6px auto 12px; }
.mtab-more-head { display: flex; align-items: center; gap: 10px; padding: 0 4px 12px;
  border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.mtab-more-ws { flex: 1; min-width: 0; }
.mtab-more-ws-name { font-size: 14px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mtab-more-ws-sub { font-size: 11px; color: var(--muted); }
.mtab-more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mtab-more-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  background: var(--bg-2, var(--bg)); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 6px; color: var(--text); font-size: 11.5px; font-weight: 500; cursor: pointer;
  min-height: 78px; text-align: center; transition: border-color .15s, background .15s;
}
.mtab-more-item:hover { border-color: var(--accent); }
.mtab-more-item.active { border-color: var(--cyan, var(--accent)); background: rgba(0,246,245,.08); color: var(--cyan, var(--accent)); }
.mtab-more-item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.mtab-more-actions { display: flex; gap: 8px; margin-top: 12px; }
.mtab-more-actions button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-2, var(--bg)); color: var(--text); font-size: 13px; font-weight: 600; font-family: inherit;
}
.mtab-more-actions button svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.mtab-more-actions .mtab-more-logout:hover { color: #ff6b6b; border-color: rgba(255,107,107,.35); }
