/* ============================================
   RESPONSIVIDADE MOBILE-FIRST
   Centraliza Argo - Sistema de Gestão
   ============================================ */

/* Breakpoints:
   - Mobile: até 640px (iPhone, Android pequenos)
   - Tablet: 641px - 1024px (iPad, tablets)
   - Desktop: acima de 1024px
*/

/* ============================================
   BASE MOBILE-FIRST
   ============================================ */

/* Garantir viewport correto */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-size: 14px;
    line-height: 1.5;
}

/* Containers fluidos */
.container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

/* ============================================
   TIPOGRAFIA RESPONSIVA
   ============================================ */

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.9rem; }

@media (min-width: 641px) {
    h1 { font-size: 2rem; }
    h2 { font-size: 1.75rem; }
    h3 { font-size: 1.5rem; }
    h4 { font-size: 1.25rem; }
    h5 { font-size: 1.1rem; }
    h6 { font-size: 1rem; }
}

@media (min-width: 1025px) {
    h1 { font-size: 2.25rem; }
    h2 { font-size: 2rem; }
    h3 { font-size: 1.75rem; }
    h4 { font-size: 1.5rem; }
    h5 { font-size: 1.25rem; }
    h6 { font-size: 1.1rem; }
}

/* ============================================
   CARDS E GRIDS
   ============================================ */

/* Cards empilhados em mobile */
.card {
    margin-bottom: 1rem;
    border-radius: 0.5rem;
}

/* Grids de cards - 1 coluna no mobile */
.row.g-3,
.row.g-2,
.row.g-4 {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
}

.row.g-3 > *,
.row.g-2 > *,
.row.g-4 > * {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* Cards em grid - mobile: 1 coluna */
.col-lg-3,
.col-lg-4,
.col-lg-6,
.col-md-4,
.col-md-6 {
    width: 100%;
    margin-bottom: 1rem;
}

@media (min-width: 641px) {
    /* Tablet: 2 colunas */
    .col-md-6 {
        width: 50%;
    }
    .col-md-4 {
        width: 50%;
    }
}

@media (min-width: 1025px) {
    /* Desktop: layout original */
    .col-lg-3 {
        width: 25%;
    }
    .col-lg-4 {
        width: 33.333333%;
    }
    .col-lg-6 {
        width: 50%;
    }
    .col-md-4 {
        width: 33.333333%;
    }
    .col-md-6 {
        width: 50%;
    }
}

/* Padding interno dos cards no mobile */
.card-body {
    padding: 1rem;
}

@media (min-width: 641px) {
    .card-body {
        padding: 1.25rem;
    }
}

/* ============================================
   TABELAS RESPONSIVAS
   ============================================ */

/* Container para scroll horizontal em mobile */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

/* Tabelas - ocultar colunas secundárias no mobile */
@media (max-width: 640px) {
    /* Colunas que podem ser ocultadas em mobile - aplicado globalmente */
    .d-none-mobile,
    th.d-none-mobile,
    td.d-none-mobile,
    .table .d-none-mobile,
    .table th.d-none-mobile,
    .table td.d-none-mobile {
        display: none !important;
    }
    
    /* Tabelas menores */
    .table {
        font-size: 0.85rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.4rem;
        white-space: nowrap;
    }
    
    /* Badges menores em tabelas */
    .table .badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.4rem;
    }
    
    /* Formulários em tabelas - empilhar */
    .invoices-filters .row > div,
    .rebates-filters .row > div,
    .pedidos-filters .row > div,
    .retiradas-filters .row > div,
    .controle-retiradas-filters .row > div,
    .promotion-filters .row > div,
    .performance-filters .row > div,
    .alinhar-filtros-retiradas .row > div {
        width: 100% !important;
        margin-bottom: 0.75rem;
    }
    
    /* Ações de formulários empilhadas */
    .filtros-retiradas-actions,
    .rebates-actions,
    .pedidos-actions {
        flex-direction: column;
    }
    
    .filtros-retiradas-actions .btn,
    .rebates-actions .btn,
    .pedidos-actions .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* Layout tipo card para tabelas em mobile */
@media (max-width: 640px) {
    .table-mobile-card {
        display: block;
    }
    
    .table-mobile-card thead {
        display: none;
    }
    
    .table-mobile-card tbody,
    .table-mobile-card tr,
    .table-mobile-card td {
        display: block;
        width: 100%;
    }
    
    .table-mobile-card tr {
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        padding: 0.75rem;
        background: #fff;
    }
    
    .table-mobile-card td {
        border: none;
        padding: 0.5rem 0;
        text-align: left !important;
    }
    
    .table-mobile-card td:before {
        content: attr(data-label) ": ";
        font-weight: bold;
        display: inline-block;
        min-width: 100px;
    }
}

/* ============================================
   FORMULÁRIOS E INPUTS
   ============================================ */

/* Inputs ocupam largura total no mobile */
@media (max-width: 640px) {
    .form-control,
    .form-select,
    .form-check-input {
        width: 100%;
        font-size: 16px; /* Evita zoom no iOS */
    }
    
    /* Botões de formulário empilhados */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        border-radius: 0.375rem !important;
    }
    
    .btn-group .btn:last-child {
        margin-bottom: 0;
    }
}

/* Labels e inputs empilhados */
@media (max-width: 640px) {
    .row.g-2 > .col-md-6,
    .row.g-2 > .col-md-4,
    .row.g-2 > .col-md-3,
    .row.g-3 > .col-md-6,
    .row.g-3 > .col-md-4 {
        width: 100%;
        margin-bottom: 0.75rem;
    }
}

/* Botões com área de toque adequada (mínimo 44px) */
.btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    touch-action: manipulation;
}

.btn-sm {
    min-height: 38px;
    padding: 0.375rem 0.75rem;
    font-size: 0.85rem;
}

.btn-lg {
    min-height: 48px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Espaçamento entre botões no mobile */
@media (max-width: 640px) {
    .btn + .btn {
        margin-left: 0;
        margin-top: 0.5rem;
    }
    
    .d-flex.gap-2 {
        flex-direction: column;
    }
    
    .d-flex.gap-2 > * {
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   FILTROS E BARRA DE BUSCA
   ============================================ */

/* Filtros empilhados em mobile */
@media (max-width: 640px) {
    .filter-row,
    .filters-container {
        flex-direction: column;
    }
    
    .filter-row > *,
    .filters-container > * {
        width: 100%;
        margin-bottom: 0.75rem;
    }
    
    /* Botões de filtro marketplace */
    .marketplace-filter-group {
        flex-direction: column !important;
    }
    
    .marketplace-filter-group .btn {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
        margin-left: 0 !important;
        border-radius: 0.375rem !important;
        flex: none !important;
    }
    
    /* Card de filtros do dashboard */
    .card-body .row.align-items-center {
        flex-direction: column;
    }
    
    .card-body .row.align-items-center > div {
        width: 100% !important;
        margin-bottom: 0.75rem;
        text-align: center !important;
    }
    
    .card-body .row.align-items-center > div:last-child {
        margin-bottom: 0;
    }
}

/* Barra de busca */
@media (max-width: 640px) {
    .search-bar,
    .input-group {
        flex-direction: column;
    }
    
    .input-group > * {
        width: 100%;
        margin-bottom: 0.5rem;
        border-radius: 0.375rem !important;
    }
    
    .input-group > .btn {
        margin-top: 0.5rem;
    }
}

/* ============================================
   NAVEGAÇÃO E MENUS
   ============================================ */

/* Navbar já tem ajustes no topnav.blade.php, apenas garantir */
@media (max-width: 991.98px) {
    .navbar-collapse {
        max-height: calc(100vh - 64px);
        overflow-y: auto;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }
}

/* Sidebar - já colapsa automaticamente no Bootstrap */
@media (max-width: 1199.98px) {
    .sidenav {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidenav.show {
        transform: translateX(0);
    }
}

/* ============================================
   MODAIS
   ============================================ */

@media (max-width: 640px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }
}

/* ============================================
   PAGINAÇÃO
   ============================================ */

@media (max-width: 640px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-item {
        margin: 0.25rem;
    }
    
    .pagination .page-link {
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        text-align: center;
    }
}

/* ============================================
   BADGES E ALERTAS
   ============================================ */

@media (max-width: 640px) {
    .badge {
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }
    
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    .alert-dismissible .btn-close {
        padding: 0.75rem 1rem;
    }
}

/* ============================================
   ESPAÇAMENTOS E PADDINGS
   ============================================ */

@media (max-width: 640px) {
    .py-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .py-3 {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
    
    .py-2 {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    .mb-4 {
        margin-bottom: 1rem !important;
    }
    
    .mb-3 {
        margin-bottom: 0.75rem !important;
    }
    
    .mt-4 {
        margin-top: 1rem !important;
    }
    
    .mt-3 {
        margin-top: 0.75rem !important;
    }
}

/* ============================================
   UTILITÁRIOS ESPECÍFICOS
   ============================================ */

/* Ocultar elementos não essenciais no mobile */
@media (max-width: 640px) {
    .d-none-mobile {
        display: none !important;
    }
    
    .d-block-mobile {
        display: block !important;
    }
    
    .text-center-mobile {
        text-align: center !important;
    }
}

/* Mostrar apenas em mobile */
@media (min-width: 641px) {
    .d-block-mobile-only {
        display: none !important;
    }
}

/* Ocultar em mobile */
@media (max-width: 640px) {
    .d-none-mobile-only {
        display: none !important;
    }
}

/* ============================================
   GRÁFICOS E CHARTS
   ============================================ */

@media (max-width: 640px) {
    canvas {
        max-width: 100%;
        height: auto !important;
    }
    
    .chart-container {
        position: relative;
        width: 100%;
        height: 250px !important;
    }
}

@media (min-width: 641px) {
    .chart-container {
        height: 300px !important;
    }
}

@media (min-width: 1025px) {
    .chart-container {
        height: 400px !important;
    }
}

/* ============================================
   DROPDOWNS E MENUS
   ============================================ */

@media (max-width: 640px) {
    .dropdown-menu {
        max-width: calc(100vw - 2rem);
        left: 1rem !important;
        right: 1rem !important;
        width: auto !important;
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* ============================================
   CARDS DE MÉTRICAS (DASHBOARD)
   ============================================ */

@media (max-width: 640px) {
    .card-stats,
    .metric-card {
        margin-bottom: 1rem;
    }
    
    .card-stats .card-body,
    .metric-card .card-body {
        padding: 1rem;
    }
    
    .card-stats .icon {
        font-size: 2rem;
    }
}

/* ============================================
   TABELAS DE RANKING E LISTAGENS
   ============================================ */

@media (max-width: 640px) {
    /* Simplificar tabelas de ranking */
    .table-ranking th:nth-child(n+4),
    .table-ranking td:nth-child(n+4) {
        display: none;
    }
    
    /* Tabelas de top vendas */
    .top-vendas-table {
        font-size: 0.85rem;
    }
}

/* ============================================
   AJUSTES ESPECÍFICOS POR COMPONENTE
   ============================================ */

/* Cards de pedidos */
@media (max-width: 640px) {
    .order-card,
    .pedido-card {
        margin-bottom: 1rem;
    }
    
    .order-card .card-body,
    .pedido-card .card-body {
        padding: 0.75rem;
    }
}

/* Filtros de período */
@media (max-width: 640px) {
    .period-filter,
    .date-filter {
        width: 100%;
        margin-bottom: 0.75rem;
    }
}

/* Botões de ação em tabelas */
@media (max-width: 640px) {
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .action-buttons .btn {
        width: 100%;
    }
}

/* ============================================
   SCROLL SUAVE E PERFORMANCE
   ============================================ */

* {
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   IMPRESSÃO
   ============================================ */

@media print {
    .navbar,
    .sidenav,
    .btn,
    .pagination,
    .filter-row {
        display: none !important;
    }
    
    .card {
        border: 1px solid #000;
        page-break-inside: avoid;
    }
}

