/* ============================================
   MOBILE RESPONSIVE - Rural Cafe System
   Versao: 1.0.0 - 2025-12-05
   ============================================ */

/* ============================================
   VARIAVEIS CSS PARA MOBILE
   ============================================ */
:root {
    --mobile-padding: 12px;
    --mobile-gap: 10px;
    --mobile-font-size: 14px;
    --mobile-header-height: 56px;
}

/* ============================================
   DESKTOP - Esconder elementos mobile
   ============================================ */
.mobile-menu-btn {
    display: none !important;
}

.sidebar-overlay {
    display: none;
}

/* ============================================
   TABLET (max-width: 1024px)
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }

    .content {
        margin-left: 220px;
    }

    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 10px;
    }
}

/* ============================================
   MOBILE LANDSCAPE (max-width: 900px)
   ============================================ */
@media (max-width: 900px) {
    /* Sidebar colapsavel */
    .sidebar {
        position: fixed !important;
        left: -280px !important;
        top: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 1000 !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.2) !important;
        background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%) !important;
        overflow-y: auto !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    .content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 60px !important;
    }

    /* Botao menu hamburger - FORCADO VISIVEL */
    .mobile-menu-btn {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: fixed !important;
        top: 10px !important;
        left: 10px !important;
        z-index: 1001 !important;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: white !important;
        border: none !important;
        padding: 12px 14px !important;
        border-radius: 10px !important;
        font-size: 22px !important;
        cursor: pointer !important;
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4) !important;
        min-width: 48px !important;
        min-height: 48px !important;
    }

    .mobile-menu-btn:active {
        transform: scale(0.95) !important;
    }

    /* Overlay quando sidebar aberta */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block !important;
    }

    /* Header ajustado */
    .header {
        padding-left: 70px !important;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
    }

    .header h1 {
        font-size: 16px !important;
    }

    /* User info compacto */
    .user-info {
        flex-direction: column !important;
        gap: 5px !important;
        align-items: flex-end !important;
    }

    .user-info .btn-logout {
        padding: 6px 12px !important;
        font-size: 12px !important;
    }
}

/* ============================================
   MOBILE PORTRAIT (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Tipografia menor */
    body {
        font-size: var(--mobile-font-size);
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.1rem; }

    /* Header compacto */
    .header {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    /* Tabs em scroll horizontal */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        white-space: nowrap;
        padding-bottom: 5px;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 12px;
        flex-shrink: 0;
    }

    /* Forms responsivos */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .form-group {
        margin-bottom: 12px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Evita zoom no iOS */
        padding: 12px;
    }

    /* Dashboard stats */
    .dashboard-stats,
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-card h3 {
        font-size: 0.75rem;
    }

    .stat-card .value {
        font-size: 1.2rem;
    }

    /* Tabelas responsivas */
    .table-container,
    .data-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }

    table {
        min-width: 600px;
        font-size: 12px;
    }

    table th,
    table td {
        padding: 8px 6px;
        white-space: nowrap;
    }

    /* Botoes */
    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }

    .btn-group {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Modais mobile-friendly */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        padding: 15px;
        flex-shrink: 0;
    }

    .modal-body {
        flex: 1;
        overflow-y: auto;
        padding: 15px;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer,
    .form-actions {
        padding: 15px;
        flex-shrink: 0;
        flex-direction: column;
        gap: 10px;
    }

    .form-actions button {
        width: 100%;
        padding: 14px;
    }

    /* Cards de contratos */
    .contract-card {
        padding: 12px;
    }

    /* Filtros */
    .filters-row {
        flex-direction: column;
        gap: 10px;
    }

    .filters-row input,
    .filters-row select {
        width: 100%;
    }

    /* Paginacao */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }

    .pagination button {
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* ============================================
   MOBILE PEQUENO (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    /* Login responsivo */
    .login-box {
        padding: 25px 20px;
        margin: 15px;
        max-width: calc(100% - 30px);
    }

    .login-box h1 {
        font-size: 1.5rem;
    }

    .login-box h2 {
        font-size: 1rem;
    }

    /* Stats em coluna unica */
    .dashboard-stats,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Tabs ainda menores */
    .tab-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Tabela minima */
    table {
        font-size: 11px;
    }

    table th,
    table td {
        padding: 6px 4px;
    }

    /* Acoes em dropdown no mobile */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .action-buttons .btn {
        padding: 6px 8px;
        font-size: 11px;
    }

    /* JARVIS chat responsivo */
    #jarvisContainer {
        width: 100% !important;
        height: 60vh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        border-radius: 20px 20px 0 0;
    }
}

/* ============================================
   UTILIDADES MOBILE
   ============================================ */

/* Esconder em mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Mostrar apenas em mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }

    .show-mobile-flex {
        display: flex !important;
    }
}

/* Texto truncado */
.text-truncate-mobile {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .text-truncate-mobile {
        max-width: 60px;
    }
}

/* Touch friendly */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px; /* Apple HIG recomenda 44px */
        min-width: 44px;
    }

    /* Links em tabelas */
    table a {
        display: inline-block;
        padding: 4px 0;
    }
}

/* ============================================
   ORIENTACAO LANDSCAPE EM MOBILE
   ============================================ */
@media (max-width: 900px) and (orientation: landscape) {
    .modal-content {
        height: 100vh;
        max-height: 100vh;
    }

    .modal-body {
        max-height: calc(100vh - 120px);
    }
}

/* ============================================
   AJUSTES ESPECIFICOS DO SISTEMA
   ============================================ */

/* Modal de Novo Contrato - Mobile */
@media (max-width: 768px) {
    #contractModal .modal-content {
        padding: 0;
    }

    #contractModal .form-section {
        padding: 15px;
        margin: 10px 0;
    }

    #contractModal .form-section h3 {
        font-size: 14px;
    }

    /* Especificacoes de qualidade em coluna */
    #qualitySpecsBlock .form-row {
        grid-template-columns: 1fr !important;
    }
}

/* Aba de Contratos - Mobile */
@media (max-width: 768px) {
    #contractsTable {
        min-width: 900px;
    }

    .contracts-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .contracts-header .btn-group {
        width: 100%;
    }

    .contracts-header .btn {
        flex: 1;
    }
}

/* Aba Financeiro Cliente - Mobile */
@media (max-width: 768px) {
    .financeiro-resumo {
        grid-template-columns: 1fr;
    }

    .extrato-container {
        padding: 10px;
    }
}

/* Aba Divergencias - Mobile */
@media (max-width: 768px) {
    .divergencia-card {
        padding: 12px;
    }

    .divergencia-card .card-header {
        flex-direction: column;
        gap: 8px;
    }
}

/* Aba Espelhos de Corretagem - Mobile */
@media (max-width: 768px) {
    .espelho-preview {
        padding: 15px;
        font-size: 12px;
    }
}

/* ============================================
   PRINT - Esconder elementos mobile
   ============================================ */
@media print {
    .mobile-menu-btn,
    .sidebar-overlay,
    #jarvisContainer {
        display: none !important;
    }
}
