/* =========================================================
   OZPro ERP — Mobile-First Base CSS (v1.0)
   Arquitetura Mobile-First: Base para celular, 
   aprimoramentos progressivos via min-width para tablet/desktop.
   ========================================================= */

/* ─── 1. Reset Universal & Viewport Seguro ─── */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  overflow-x: hidden;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
}

img, video, iframe, embed, object, canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ─── 2. Alvos de Toque & Interatividade Touch ─── */
button, .btn, .btn-icon, .header-action, .mobile-menu-btn,
.menu-item, .stat-card, .kanban-card, .categoria-card,
.report-card, .motoboy-card, .delivery-card, .pagination-btn,
.tab-btn, .action-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ─── 3. Layout Base: Mobile (< 1025px) ─── */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

/* Sidebar no mobile: gaveta lateral oculta com transição fluida */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 280px;
  max-width: 82vw;
  height: 100dvh;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1100;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar.mobile-open {
  transform: translateX(0) !important;
  box-shadow: 10px 0 32px rgba(0, 0, 0, 0.45);
}

/* Overlay escurecido do menu mobile */
.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 1050;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mobile-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Conteúdo principal ocupa 100% da tela no mobile */
.main-content {
  margin-left: 0 !important;
  width: 100% !important;
  min-width: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header responsivo no mobile com suporte a safe-area */
.header {
  position: sticky;
  top: 0;
  z-index: 500;
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-left h2 {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
  margin: 0;
}

.header-breadcrumb,
.header-search {
  display: none;
}

.mobile-menu-btn {
  display: inline-flex;
  width: 40px;
  height: 40px;
  min-width: 40px;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
  background: transparent;
}

/* Área de conteúdo da página com safe-area no rodapé */
.page-content {
  padding: 12px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-x: clip;
  min-height: calc(100dvh - 56px);
  flex: 1 1 auto;
}

/* ─── 4. Formulários & Inputs: 16px previne zoom no iOS Safari ─── */
@media (max-width: 768px) {
  input, select, textarea,
  .form-control, .form-input, .form-select {
    font-size: 16px !important;
    min-height: 44px;
  }
}

.btn {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon {
  width: 42px;
  height: 42px;
  min-height: 42px;
  min-width: 42px;
}

/* ─── 5. Grids e Cards: 1 Coluna em Mobile ─── */
.card {
  border-radius: 12px;
  margin-bottom: 12px;
}

.stat-grid, .form-grid, .form-row, .config-grid, .report-grid,
.delivery-grid, .motoboy-grid, .caixa-grid, .two-col-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.stat-card {
  padding: 14px;
}

.stat-card .stat-value {
  font-size: 18px;
}

/* ─── 6. Tabelas Responsivas com Scroll Suave ─── */
.table-container {
  overflow-x: auto;
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.data-table {
  min-width: 520px;
  width: 100%;
  font-size: 12px;
}

.data-table th, .data-table td {
  padding: 10px 12px;
  white-space: nowrap;
}

/* ─── 7. Modais como Bottom Sheet no Celular ─── */
@media (max-width: 768px) {
  .modal-overlay {
    align-items: flex-end !important;
    justify-content: center !important;
    padding: 0 !important;
  }

  .modal {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90dvh !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    transform: none !important;
    display: flex;
    flex-direction: column;
  }

  .modal-body {
    padding: 16px !important;
    overflow-y: auto !important;
    max-height: 62dvh !important;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
  }

  .modal-footer {
    padding: 12px 16px !important;
    display: flex;
    gap: 8px;
  }

  .modal-footer .btn {
    flex: 1 1 0;
    min-height: 46px;
  }
}

/* ─── 8. Kanban com Scroll Horizontal por Snapping ─── */
.kanban-board {
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 12px;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.kanban-col {
  min-width: 270px;
  max-width: 300px;
  flex-shrink: 0;
  scroll-snap-align: start;
}

/* ─── 9. Utilitários Mobile-First ─── */
.hide-mobile {
  display: none !important;
}

.stack-mobile {
  flex-direction: column !important;
  align-items: stretch !important;
}

.stack-mobile > * {
  width: 100% !important;
}

.text-truncate-mobile {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   Aprimoramento Progressivo: Tablet (min-width: 769px)
   ========================================================= */
@media (min-width: 769px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .two-col-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal-overlay {
    align-items: center !important;
    justify-content: center !important;
  }

  .modal {
    position: relative !important;
    width: 90% !important;
    max-width: 600px !important;
    max-height: 85vh !important;
    border-radius: 16px !important;
    margin: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
  }

  .modal-body {
    max-height: none !important;
  }

  .hide-mobile {
    display: inherit !important;
  }
}

/* =========================================================
   Aprimoramento Progressivo: Desktop (min-width: 1025px)
   ========================================================= */
@media (min-width: 1025px) {
  /* Sidebar fixa clássica de desktop */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    max-width: none;
    height: 100vh;
    transform: translateX(0) !important;
    overflow-y: auto;
    z-index: 100;
  }

  .sidebar.collapsed {
    width: 78px !important;
  }

  .main-content {
    margin-left: 260px !important;
    width: calc(100% - 260px) !important;
  }

  .sidebar.collapsed ~ .main-content {
    margin-left: 78px !important;
    width: calc(100% - 78px) !important;
  }

  .mobile-menu-btn {
    display: none !important;
  }

  .mobile-overlay {
    display: none !important;
  }

  .header-breadcrumb,
  .header-search {
    display: block;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .config-grid, .report-grid, .delivery-grid, .motoboy-grid, .caixa-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }

  .two-col-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-content {
    padding: 24px;
  }
}
