/* ============================================================
   Flux CRM — Camada responsiva (celular / tablet)
   Carregado DEPOIS de styles.css. Só atua em telas estreitas:
   o visual desktop (> 900px) permanece idêntico.
   ============================================================ */

/* backdrop da gaveta (só existe no DOM quando o menu está aberto) */
.nav-backdrop { display: none; }

/* ------------------------------------------------------------
   ≤ 1080px — tablet paisagem
   ------------------------------------------------------------ */
@media screen and (max-width: 1080px) {
  .page { padding: 22px 20px 56px; }
}

/* ------------------------------------------------------------
   ≤ 900px — sidebar vira gaveta (off-canvas)
   ------------------------------------------------------------ */
@media screen and (max-width: 900px) {
  .sidebar,
  .sidebar.collapsed {
    position: fixed; left: 0; top: 0; bottom: 0;
    height: 100vh; height: 100dvh;
    width: min(280px, 84vw); flex-basis: auto;
    transform: translateX(-102%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    z-index: 120;
    box-shadow: none;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  /* se estava recolhida no desktop, no celular mostra completa */
  .sidebar.collapsed .nav-label { display: inline; }
  .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 10px 12px; }
  .sidebar.collapsed .nav-user .meta { display: block; }

  .nav-item { padding: 12px 12px; }            /* alvo de toque maior */

  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 110;
    background: rgba(13,22,42,.46); backdrop-filter: blur(2px);
    animation: fade .16s ease;
  }

  .main { width: 100%; }
  .topbar { padding: 0 12px; gap: 6px; }
}

/* ------------------------------------------------------------
   ≤ 720px — celular
   ------------------------------------------------------------ */
@media screen and (max-width: 720px) {
  :root { --topbar-h: 56px; }

  .page { padding: 16px 12px 48px; }
  .page-head { gap: 12px; margin-bottom: 16px; align-items: stretch; }
  .page-head > * { min-width: 0; }
  .page-title { font-size: 21px; }
  .page-sub { font-size: 13px; }
  .crumb { margin-bottom: 4px; }

  /* ---- grids inline das páginas → 1 coluna ---- */
  main [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  main [style*="grid-column"],
  main [class*="col-span-"] { grid-column: 1 / -1 !important; }

  /* linhas de itens do estoque: 2 colunas, descrição em largura total */
  main [style*="2fr 80px 70px"] { grid-template-columns: 1fr 1fr !important; }
  main [style*="2fr 80px 70px"] > :first-child,
  main [style*="2fr 80px 70px"] > :last-child { grid-column: 1 / -1 !important; }

  /* ---- cards de indicadores ---- */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .ic { width: 34px; height: 34px; margin-bottom: 10px; }
  .stat .val { font-size: 20px; overflow-wrap: anywhere; }
  .totals { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .total-cell .v { font-size: 15px; }

  .card-pad { padding: 14px; }
  .card-head { padding: 13px 14px; flex-wrap: wrap; }

  /* ---- toolbar / busca ---- */
  .toolbar { gap: 8px; }
  .toolbar .grow:empty { display: none; }
  .search-inline,
  main .search-inline[style] {
    min-width: 0 !important; max-width: none !important;
    flex: 1 1 100%; height: 42px;
  }
  .page-head .btn { flex: 1 1 auto; }

  /* dropdown do catálogo (O.S / venda) cabe na tela */
  main .row > .card[style*="position: absolute"] {
    width: auto !important; left: 0 !important; right: 0 !important;
  }

  /* ---- tabelas: rolagem horizontal com o dedo ---- */
  .table-wrap,
  main :not(.table-wrap):has(> table) {
    overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%;
  }
  table.tbl { font-size: 13px; }
  table.tbl thead th { padding: 11px 12px; }
  table.tbl tbody td { padding: 11px 12px; }
  main td[style*="max-width"] { min-width: 160px; }

  /* ---- abas e controles segmentados roláveis ---- */
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: 0 0 auto; padding: 11px 12px; }
  .seg { max-width: 100%; overflow-x: auto; }
  .seg button { flex: 0 0 auto; }

  /* ---- paginação ---- */
  .pager { justify-content: center; padding: 12px; }
  .pages { flex-wrap: wrap; justify-content: center; }

  /* ---- modais em tela cheia ---- */
  .overlay { padding: 0; align-items: stretch; }
  .modal, .modal.wide {
    max-width: none; max-height: none; height: 100%;
    border-radius: 0;
  }
  .modal-head { padding: 14px 16px; gap: 10px; }
  .modal-head h2 { font-size: 17px; }
  .modal-body { padding: 16px; flex: 1; }
  .modal-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-foot .grow { display: none; }

  .section-bar { padding: 10px 12px; font-size: 12px; }

  /* ---- toast ---- */
  .toast-wrap { width: calc(100% - 24px); bottom: calc(16px + env(safe-area-inset-bottom)); }
  .toast { width: 100%; }

  /* ---- alvos de toque ---- */
  .act { width: 36px; height: 36px; }
  .btn-sm { height: 38px; }
}

/* evita zoom automático do iOS ao focar campos */
@media screen and (max-width: 720px) and (pointer: coarse) {
  input, select, textarea, .inp,
  .field input, .field select, .field textarea { font-size: 16px; }
}

/* ------------------------------------------------------------
   ≤ 400px — celulares pequenos
   ------------------------------------------------------------ */
@media screen and (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 19px; }
}
