/* ============================================================
   VHSEG — Estilos Mobile-First
   Otimizado para smartphones (≤ 768px)
   ============================================================ */

/* ── Variáveis mobile ──────────────────────────────────────── */
:root {
  --bottom-nav-height: 60px;
}

/* ============================================================
   LAYOUT GERAL
   ============================================================ */
@media (max-width: 768px) {

  /* Espaço para a bottom nav fixa */
  .page-content {
    padding: 12px 12px calc(var(--bottom-nav-height) + 16px) 12px !important;
  }

  /* App container ocupa 100% */
  .app-container {
    flex-direction: column;
  }

  /* Sidebar: escondida por padrão, desliza da esquerda */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100dvh !important;
    z-index: 200 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    width: 280px !important;
    box-shadow: 4px 0 20px rgba(0,0,0,0.25);
  }

  .sidebar.open {
    transform: translateX(0) !important;
  }

  /* Main content ocupa tudo */
  .main-content {
    margin-left: 0 !important;
    width: 100%;
  }

  /* Topbar compacta */
  .topbar {
    padding: 0 12px !important;
    height: 56px;
    min-height: 56px;
  }

  .topbar-title {
    font-size: 16px !important;
  }

  .topbar-subtitle {
    font-size: 11px !important;
  }

  .topbar-date {
    display: none; /* Ocultar data no mobile para economizar espaço */
  }

  /* Overlay da sidebar */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.show {
    display: block;
  }
}

/* ============================================================
   KPI GRID — 2 colunas no mobile
   ============================================================ */
@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .kpi-card {
    padding: 10px 10px !important;
    min-width: 0; /* evita overflow fora do grid */
    overflow: hidden;
  }

  .kpi-info {
    min-width: 0;
    overflow: hidden;
  }

  .kpi-value {
    font-size: 16px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* Valores monetários menores para não cortar */
  .kpi-value[data-monetary="true"],
  .kpi-card .kpi-value {
    font-size: 14px !important;
  }

  .kpi-label {
    font-size: 10px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-icon {
    width: 32px !important;
    height: 32px !important;
    font-size: 14px !important;
    flex-shrink: 0;
  }
}

/* ============================================================
   CARDS
   ============================================================ */
@media (max-width: 768px) {
  .card {
    border-radius: 10px !important;
    margin-bottom: 12px !important;
  }

  .card-header {
    padding: 12px 14px !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card-title {
    font-size: 13px !important;
  }

  .card-body {
    padding: 12px !important;
  }

  .mb-6 {
    margin-bottom: 12px !important;
  }
}

/* ============================================================
   TABELAS — scroll horizontal
   ============================================================ */
@media (max-width: 768px) {
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 10px 10px;
  }

  .data-table {
    min-width: 600px; /* força scroll horizontal em vez de comprimir */
    font-size: 12px !important;
  }

  .data-table th,
  .data-table td {
    padding: 10px 10px !important;
    white-space: nowrap;
  }

  /* Esconder colunas menos importantes em mobile */
  .data-table .col-hide-mobile {
    display: none;
  }
}

/* ============================================================
   TOOLBAR — empilhada no mobile
   ============================================================ */
@media (max-width: 768px) {
  .toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 10px 0 !important;
  }

  .toolbar-left {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar-right {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .toolbar-right .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }

  .search-box {
    width: 100%;
  }

  .search-box input {
    width: 100%;
  }

  /* Grupo de botões import/export: scroll horizontal */
  .btn-group-imp {
    border-right: none !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 4px !important;
  }

  .btn-group-imp .btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* ============================================================
   GRÁFICOS — altura reduzida no mobile
   ============================================================ */
@media (max-width: 768px) {
  /* Todos os wrappers de canvas */
  [id^="wrap-chart"],
  .card-body [style*="height:300px"],
  .card-body [style*="height:280px"],
  .card-body [style*="height:260px"] {
    height: 220px !important;
  }

  /* Legenda dos gráficos: em baixo em vez de à direita */
  canvas {
    max-height: 220px;
  }
}

/* ============================================================
   MODAIS — tela cheia no mobile
   ============================================================ */
@media (max-width: 768px) {
  .modal-overlay {
    align-items: flex-end !important; /* modal sobe de baixo */
    padding: 0 !important;
  }

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    overflow-y: auto;
  }

  .modal-header {
    padding: 16px 16px 12px !important;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
    border-bottom: 1px solid #e5e7eb;
  }

  .modal-body {
    padding: 16px !important;
  }

  .modal-footer {
    padding: 12px 16px !important;
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    z-index: 1;
  }

  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   GRID-2 — 1 coluna no mobile
   ============================================================ */
@media (max-width: 768px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
}

/* ============================================================
   TABS — scroll horizontal no mobile
   ============================================================ */
@media (max-width: 768px) {
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    gap: 0 !important;
    padding-bottom: 2px;
  }

  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 12px !important;
    padding: 8px 12px !important;
  }
}

/* ============================================================
   FILTRO DO DASHBOARD — empilhado no mobile
   ============================================================ */
@media (max-width: 768px) {
  #dash-filtro-bar {
    gap: 8px !important;
    padding: 12px !important;
  }

  #dash-filtro-bar select {
    width: 100% !important;
  }

  #dash-filtro-bar > div:first-child {
    width: 100%;
  }

  #dash-periodo-label {
    width: 100%;
    text-align: center;
  }
}

/* ============================================================
   GANTT — scroll horizontal forçado
   ============================================================ */
@media (max-width: 768px) {
  #gantt-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #gantt-container table {
    min-width: 700px;
  }
}

/* ============================================================
   ORÇAMENTOS — adaptações
   ============================================================ */
@media (max-width: 768px) {
  .orc-header {
    flex-direction: column;
    gap: 6px;
  }
}

/* ============================================================
   BOTTOM NAVIGATION BAR (mobile)
   Navegação principal fixada na parte inferior da tela
   ============================================================ */
.bottom-nav {
  display: none; /* oculta no desktop */
}

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    z-index: 150;
    align-items: stretch;
    justify-content: space-around;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    border: none;
    background: none;
    color: #9ca3af;
    font-size: 10px;
    font-weight: 500;
    font-family: inherit;
    padding: 4px 2px;
    transition: color 0.15s ease;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }

  .bottom-nav-item i {
    font-size: 20px;
    transition: transform 0.15s ease;
  }

  .bottom-nav-item.active {
    color: var(--primary);
  }

  .bottom-nav-item.active i {
    transform: translateY(-2px);
  }

  /* Indicador ativo */
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
  }

  /* Item "mais" — abre menu extra */
  .bottom-nav-more {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 8px);
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    padding: 12px 0 16px;
    z-index: 151;
    display: none;
    animation: slideUpMenu 0.22s ease;
  }

  .bottom-nav-more.open {
    display: block;
  }

  @keyframes slideUpMenu {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  .bottom-nav-more-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    border: none;
    background: none;
    width: 100%;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-more-item:active {
    background: #f3f4f6;
  }

  .bottom-nav-more-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    color: var(--primary);
  }

  .bottom-nav-more-item span {
    flex: 1;
    text-align: left;
  }

  .bottom-nav-more-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 149;
    background: rgba(0,0,0,0.3);
  }

  .bottom-nav-more-backdrop.open {
    display: block;
  }

  /* Handle bar do menu "mais" */
  .bottom-nav-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0 auto 12px;
  }
}

/* ============================================================
   BADGES — menores no mobile
   ============================================================ */
@media (max-width: 768px) {
  .badge {
    font-size: 10px !important;
    padding: 2px 6px !important;
  }
}

/* ============================================================
   BOTÕES — altura de toque mínima 44px (Apple HIG)
   ============================================================ */
@media (max-width: 768px) {
  .btn {
    min-height: 40px;
    font-size: 13px !important;
  }

  .btn-sm {
    min-height: 34px !important;
  }

  /* Botão de nova ação ocupa largura total no mobile */
  .toolbar-right .btn-primary {
    flex: 1;
  }
}

/* ============================================================
   FORMULÁRIOS — inputs maiores para toque
   ============================================================ */
@media (max-width: 768px) {
  .form-control {
    font-size: 16px !important; /* evita zoom automático no iOS */
    min-height: 42px;
    padding: 10px 12px !important;
  }

  select.form-control {
    background-size: 16px;
  }

  textarea.form-control {
    min-height: 80px;
  }

  .form-label {
    font-size: 13px !important;
  }
}

/* ============================================================
   TABELA RESUMO FINANCEIRO — compacta no mobile
   ============================================================ */
@media (max-width: 768px) {
  #dash-fin-resumo-table {
    font-size: 12px !important;
  }

  #dash-fin-resumo-table th,
  #dash-fin-resumo-table td {
    padding: 7px 10px !important;
  }
}

/* ============================================================
   KPI GRID DO PLANO DE AÇÃO — 5 colunas → 3+2 no mobile
   ============================================================ */
@media (max-width: 768px) {
  #pa-kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  #pa-kpi-grid .kpi-card:nth-child(4),
  #pa-kpi-grid .kpi-card:nth-child(5) {
    grid-column: span 1;
  }
}

/* ============================================================
   USUÁRIOS — adaptações mobile
   ============================================================ */
@media (max-width: 768px) {
  #page-usuarios .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ============================================================
   SCROLL SUAVE EM TODOS OS CONTÊINERES
   ============================================================ */
@media (max-width: 768px) {
  .page-content,
  .table-container,
  .modal-body {
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================================
   PRINT — não afeta mobile
   ============================================================ */
@media (max-width: 768px) {
  .sidebar-footer {
    padding-bottom: 80px; /* espaço acima da bottom nav */
  }
}

/* ============================================================
   TOAST — posição no mobile
   ============================================================ */
@media (max-width: 768px) {
  #toast-container {
    bottom: calc(var(--bottom-nav-height) + 12px) !important;
    top: auto !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
  }

  .toast {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================================
   IMPORTAÇÃO — modal adaptado
   ============================================================ */
@media (max-width: 768px) {
  .imp-instrucoes {
    gap: 8px;
  }

  .imp-instrucao-item {
    padding: 10px 12px;
    font-size: 12px;
  }

  .imp-resumo {
    flex-direction: column;
  }

  .imp-resumo-item {
    min-width: 0;
  }
}

/* ============================================================
   LOGIN — já está bom, pequenos ajustes
   ============================================================ */
@media (max-width: 400px) {
  .login-card {
    margin: 12px !important;
    padding: 24px 18px !important;
  }
}
