/* ==========================================================================
   Portal Radeane — camada MOBILE (aditiva)
   Só age em telas <= 900px. No computador nada muda.
   Carregado DEPOIS do app.css, por isso os overrides usam !important
   onde precisam vencer regras existentes/inline.
   ========================================================================== */

/* Elementos que só existem no celular ficam escondidos no desktop */
.menu-toggle, .nav-close, .nav-backdrop, .bottom-nav, .kmove { display: none; }

@media (max-width: 900px) {

  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }

  /* ---------- Estrutura: sidebar vira gaveta ---------- */
  .page { display: block !important; }
  .page-wrapper { margin-left: 0 !important; width: 100% !important; max-width: 100% !important; min-width: 0 !important; }

  .sidebar {
    position: fixed !important; top: 0; left: 0; bottom: 0;
    width: 290px !important; max-width: 86vw;
    height: 100vh !important; height: 100dvh !important;
    display: flex !important; flex-direction: column; align-items: stretch;
    box-sizing: border-box; overflow: hidden; gap: 0;
    padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
    visibility: hidden;
    transform: translateX(-105%); transition: transform .22s ease;
    z-index: 1200; box-shadow: none;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidebar .sidebar-logo { padding: 6px 46px 20px 8px; flex-shrink: 0; }
  .sidebar .sidebar-logo small { display: block; }
  .sidebar .nav-scroll { display: block; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; flex: 1; }
  .sidebar .nav-group-label { display: block; margin: 18px 10px 8px; }
  .sidebar .nav-item, .sidebar .nav-subitem { min-height: 48px; box-sizing: border-box; display: flex; align-items: center; white-space: normal; font-size: 14px; }
  .sidebar .nav-item { border-bottom: 0; border-left: 3px solid transparent; }
  .sidebar .nav-item.active { border-left-color: #C81430; }
  .sidebar .sidebar-bottom { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid #2a2a2e; flex-shrink: 0; }
  .sidebar .sidebar-user .who { display: block; }
  .sidebar .logout-link { min-width: 44px; min-height: 44px; box-sizing: border-box; }
  .nav-close { display: flex; position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid #3a3a3e; border-radius: 12px; background: #242428; color: #fff; font-size: 28px; cursor: pointer; }
  .nav-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

  .nav-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(15,15,20,.5);
    opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 1100;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  /* ---------- Cabeçalho ---------- */
  .page-header { position: sticky; top: 0; z-index: 1000; padding-top: env(safe-area-inset-top, 0px); }
  .page-header-inner { gap: 10px; padding-left: 12px !important; padding-right: 12px !important; }
  .page-header-inner > div:first-child { min-width: 0; flex: 1; }
  .page-crumb { display: none !important; }
  .page-title { font-size: 17px !important; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
    width: 44px; height: 44px; border-radius: 12px; border: 1px solid #e4e4e7;
    background: #fff; color: #1c1d21; cursor: pointer; margin-right: 2px;
  }
  .menu-toggle svg { width: 22px; height: 22px; }
  .page-header-inner { display: flex !important; align-items: center; }
  .page-header-inner > .menu-toggle + div { flex: 1; }

  /* Sino: dropdown ocupa a largura da tela */
  .notif-dropdown { position: fixed !important; left: 8px !important; right: 8px !important; top: calc(60px + env(safe-area-inset-top, 0px)) !important; width: auto !important; max-height: 70vh !important; }
  .notif-bell-btn { width: 44px !important; height: 44px !important; }

  /* ---------- Conteúdo ---------- */
  .page-body { padding: 12px 0 !important; }
  .page-body > div,
  .page-body > [style*="padding-left"] { padding-left: 12px !important; padding-right: 12px !important; max-width: 100% !important; box-sizing: border-box; }
  .card { border-radius: 14px; }
  .card-header { flex-wrap: wrap; gap: 6px; }
  .card-body { padding: 14px; }
  .d-flex.justify-between { flex-wrap: wrap; gap: 8px; }

  /* Grades viram coluna única */
  .row-2, .row-3 { display: grid !important; grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
  .kpi-grid { display: grid !important; grid-template-columns: repeat(2, minmax(0,1fr)) !important; gap: 10px !important; }
  .kpi-card { padding: 12px !important; min-width: 0; }
  .kpi-value { font-size: 24px !important; }
  .kpi-label { font-size: 11px !important; }
  .kpi-icon { display: none !important; }
  .chart-wrap { height: 210px !important; padding: 8px 10px !important; }

  /* ---------- Botões e formulários (alvo de toque >= 44px) ---------- */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 40px; padding-left: 14px; padding-right: 14px; }
  input:not([type=checkbox]):not([type=radio]), select, textarea {
    font-size: 16px !important;   /* evita o zoom automático do iPhone */
    min-height: 44px; max-width: 100%; box-sizing: border-box;
  }
  .field { min-width: 0 !important; width: 100%; }
  form.d-flex { flex-direction: column; align-items: stretch !important; }
  form.d-flex > .field { min-width: 0 !important; }

  /* ---------- Modais viram "bottom sheet" ---------- */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal, .modal.modal-lg {
    width: 100% !important; max-width: 100% !important; margin: 0 !important;
    max-height: 92vh; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    border-radius: 18px 18px 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal-footer { position: sticky; bottom: 0; background: #fff; gap: 8px; }
  .modal-footer .btn { flex: 1; }

  /* ---------- Kanban: colunas deslizam, uma por vez ---------- */
  .kanban-wrap {
    display: flex !important; gap: 10px !important; overflow-x: auto !important;
    scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
    padding: 0 0 14px !important; margin: 0 -12px; padding-left: 12px !important; padding-right: 12px !important;
    scroll-padding-left: 12px;
  }
  .kanban-col { flex: 0 0 84vw !important; width: 84vw !important; max-width: 340px; min-width: 0 !important; scroll-snap-align: start; }
  .kanban-col-body { max-height: none !important; }
  .kcard { -webkit-user-drag: none; }
  .kanban-empty { font-size: 12px; }

  /* Controle "Mover para..." (o arrastar com o dedo é ruim em tela pequena) */
  .kmove { display: block; margin: -4px 0 10px; }
  .kmove select {
    width: 100%; min-height: 40px; border: 1px dashed #d4d4d8; border-radius: 10px;
    background: #fafafa; color: #52525b; font-size: 14px !important; padding: 0 10px;
  }

  /* ---------- Tabelas ---------- */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table:not(.tbl-cards) { min-width: 560px; }

  /* Lista de leads / matriculados / lixeira => cartões */
  .tbl-cards, .tbl-cards tbody { display: block; width: 100%; }
  .tbl-cards thead { display: none; }
  .tbl-cards tr {
    display: block; margin: 10px 12px; padding: 12px 14px;
    border: 1px solid #ececef; border-radius: 14px; background: #fff;
    box-shadow: 0 1px 2px rgba(20,20,30,.04);
  }
  .tbl-cards td {
    display: flex !important; justify-content: space-between; align-items: center; gap: 12px;
    padding: 5px 0 !important; border: 0 !important; text-align: right; font-size: 13px; white-space: normal !important;
  }
  .tbl-cards td::before { content: attr(data-label); flex: 0 0 auto; color: #8b8d94; font-size: 12px; font-weight: 600; text-align: left; }
  .tbl-cards td:first-child { font-size: 16px; font-weight: 700; justify-content: flex-start; padding-bottom: 8px !important; }
  .tbl-cards td:first-child::before { display: none; }
  .tbl-cards td:empty { display: none !important; }

  /* Ligar / WhatsApp com um toque */
  .tel-actions { display: inline-flex; gap: 6px; align-items: center; }
  .tel-actions a.tel-num { color: inherit; font-weight: 600; text-decoration: none; }
  .tel-actions a.tel-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 40px; border-radius: 10px; font-size: 18px; text-decoration: none;
    border: 1px solid #e4e4e7; background: #fff;
  }
  .tel-actions a.tel-btn.wa { background: #e8f8ee; border-color: #bfe9cd; }

  /* ---------- Ficha do lead ---------- */
  .detail-top { flex-wrap: wrap; gap: 10px; }
  .funnel-track { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; padding-bottom: 6px; }
  .funnel-step { flex: 0 0 auto !important; white-space: nowrap; min-height: 40px; display: inline-flex; align-items: center; }
  .dtabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; }
  .dtab-btn { flex: 0 0 auto; white-space: nowrap; min-height: 44px; }
  .task-item, .note-item { min-width: 0; }
  .task-title, .note-item { overflow-wrap: anywhere; }

  /* ---------- Precisa de atenção ---------- */
  .attn-row { padding: 12px 14px; min-height: 56px; }

  /* Configurações e telas com largura máxima fixa */
  [style*="max-width:820px"], [style*="max-width:760px"], [style*="max-width:720px"],
  [style*="max-width:640px"], [style*="max-width:560px"] { max-width: 100% !important; }
  .settings-row, .catalog-item { flex-wrap: wrap; gap: 8px; }
  .catalog-actions { flex-wrap: wrap; }

  /* ---------- Barra inferior (estilo app) ---------- */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    background: #fff; border-top: 1px solid #e4e4e7;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 18px rgba(20,20,30,.06);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; min-height: 60px; padding: 6px 2px; border: 0; background: none; cursor: pointer;
    color: #6b6d73; font: inherit; font-size: 11px; font-weight: 600; text-decoration: none;
  }
  .bottom-nav svg { width: 22px; height: 22px; }
  .bottom-nav .active { color: #C81430; }
  .bottom-nav .bn-badge {
    position: absolute; top: 4px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px;
    background: #C81430; color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
  }
  /* quando um modal está aberto, a barra inferior não atrapalha */
  body.modal-aberto .bottom-nav { display: none; }

  /* ---------- Login ---------- */
  .login-page { display: block !important; min-height: 100vh; min-height: 100dvh; }
  .login-brand-panel { display: none !important; }
  .login-form-panel { width: 100% !important; max-width: 100% !important; min-height: 100vh; min-height: 100dvh; padding: 24px 20px !important; display: flex; align-items: center; justify-content: center; box-sizing: border-box; }
  .login-form { width: 100%; max-width: 420px; }
  .login-form-logo { max-height: 64px; width: auto; }
}

/* Telas bem pequenas */
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
  .kanban-col { flex-basis: 90vw !important; width: 90vw !important; }
}
