/* ============================================================
   Adaptação para celular e tablet
   Carregado depois de style.css — aqui só existem regras de
   tela pequena/média. O desktop continua exatamente como antes.
   ============================================================ */

/* ---------- base ---------- */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 89;
  background: rgba(10, 15, 28, .45);
  opacity: 0; pointer-events: none; transition: opacity .2s;
  display: none;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }

@media (max-width: 980px) {
  .drawer-scrim { display: block; }
  body.menu-aberto { overflow: hidden; }
}

/* ---------- tablets e celulares: base comum ---------- */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  .page-title { font-size: 17px; }
  .page-sub { font-size: 11.5px; }
  .topbar .btn-group { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .topbar .btn-group::-webkit-scrollbar { height: 0; }
  .empresa-switch:not([hidden]) { display: block !important; order: 4; width: 100%; }
  .empresa-switch select { width: 100%; }

  .container { padding: 16px 14px 72px; }
  .card-pad { padding: 16px; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; }
  .card-head h3 { font-size: 14.5px; }
  .section-head { flex-wrap: wrap; padding: 14px 16px; }
  .section-head .btn-group { width: 100%; flex-wrap: wrap; }
  .section-head .btn-group .btn { flex: 1 1 auto; justify-content: center; }

  .grid-2, .grid-2-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
  .module-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .module-card { padding: 16px; }

  /* toque: alvos maiores */
  .sidebar { height: 100vh; height: 100dvh; }
  .btn { min-height: 40px; }
  .btn-mini { min-height: 36px; }
  .icon-btn { width: 40px; height: 40px; min-width: 40px; }
  .nav-item { padding: 12px; font-size: 15px; }
  .chip { padding: 8px 14px; font-size: 13px; }

  /* inputs: 16px evita zoom automático no iOS */
  input, select, textarea { font-size: 16px !important; }
  .form-grid, .form-grid.fg3 { grid-template-columns: 1fr; }
  .input-row { flex-wrap: wrap; }
  .searchbox input { width: 100%; }
  .toolbar .searchbox { width: 100%; margin-right: 0; }
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }
  .report-filters .field { width: 100%; min-width: 0; }
  .field-label-row { flex-wrap: wrap; }

  /* tabelas: compactas e com rolagem horizontal */
  .table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .table { font-size: 12.5px; }
  .table th, .table td { padding: 10px; }
  .table th { font-size: 10.5px; }
  .table .num { white-space: nowrap; }
  .table .avatar { width: 30px; height: 30px; font-size: 11px; }

  /* linhas de lista (compras, contas, obras) */
  .detail-item { padding: 11px 16px; gap: 10px; }
  .card-head + .detail-item { padding-left: 16px; padding-right: 16px; }
  .list-actions { gap: 10px; }
  .list-actions .icon-btn { width: 40px; height: 40px; }

  /* modais em tela cheia */
  .overlay { padding: 0; align-items: stretch; }
  .modal,
  .modal.sm, .modal.md, .modal.lg, .modal.xl {
    max-width: 100% !important; width: 100%;
    max-height: 100vh; max-height: 100dvh;
    height: auto; border-radius: 0;
  }
  .modal.obra-view {
    max-width: 100% !important; max-height: 100vh; max-height: 100dvh; border-radius: 0;
  }
  .modal-head { padding: 14px 16px; }
  .modal-head h3 { font-size: 15px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }

  .dropzone { padding: 18px; }
  .dropzone strong { font-size: 13px; }

  .toasts { left: 12px; right: 12px; top: auto; bottom: 12px; max-width: none; }

  /* editores de itens e parcelas */
  .editor-row { grid-template-columns: 1fr 1fr !important; row-gap: 8px; }
  .editor-row.head { display: none; }
  .parcela-editor .editor-row { grid-template-columns: 1fr 1fr !important; }
  .editor-row > *:last-child { justify-self: end; }

  /* obras / compras / contas em telas estreitas */
  .cp-hero { grid-template-columns: 1fr !important; gap: 16px; padding: 18px; }
  .cp-facts, .ct-facts { grid-template-columns: 1fr; }
  .cp-hero-total { font-size: 26px; }
  .obra-kpis { grid-template-columns: 1fr 1fr; }
  .obra-hero-kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .obra-grid { grid-template-columns: 1fr; }
  .ger-row { flex-wrap: wrap; }
  .ger-actions { margin-left: auto; }
}

/* ---------- celulares ---------- */
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .module-grid { grid-template-columns: 1fr; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 20px; }
  .kpi-icon { width: 34px; height: 34px; }
  .module-count { font-size: 20px; }
  .obra-kpis, .obra-hero-kpis { grid-template-columns: 1fr; }
  .cp-facts, .ct-facts { grid-template-columns: 1fr 1fr; }
  .page-title { font-size: 16px; }
  .container { padding: 14px 10px 80px; }
  .modal-foot .btn { min-width: 46%; }
}

/* ---------- celulares pequenos ---------- */
@media (max-width: 400px) {
  .container { padding: 12px 8px 80px; }
  .topbar { padding: 10px 12px; }
  .card-pad, .modal-body { padding: 13px; }
  .btn { padding: 9px 12px; font-size: 13px; }
  .cp-facts, .ct-facts { grid-template-columns: 1fr; }
  .editor-row { grid-template-columns: 1fr !important; }
}

/* ---------- telas horizontais baixas (celular deitado) ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .modal { max-height: 96vh; }
  .sidebar { height: 100dvh; }
}

/* ---------- login ---------- */
@media (max-width: 900px) {
  .login-root { padding: 16px; overflow-y: auto; }
  .login-card { padding: 30px 22px 24px; border-radius: 18px; }
  .login-ico { width: 62px; height: 62px; margin-bottom: 14px; }
  .login-title { font-size: 20px; }
  .login-form { margin-top: 22px; gap: 12px; }
  .login-btn { min-height: 48px; }
}
@media (max-height: 560px) {
  .login-root { align-items: start; }
}

/* ---------- impressão ---------- */
@media print {
  .sidebar, .topbar, .toasts, .drawer-scrim, .btn, .icon-btn { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .container { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
