/*
 * ============================================
 * CONTAÍ - ESTILOS MOBILE UNIFICADOS
 * ============================================
 *
 * Este arquivo combina layout, componentes e correções
 * para uma experiência móvel coesa e otimizada.
 *
 * Versão: 1.2
 * ============================================
 */

/* ===== MEDIA QUERY PRINCIPAL (Até 767px) ===== */
@media (max-width: 767px) {

    /* ===== VARIÁVEIS E BASE ===== */
    :root {
        --mobile-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
        --mobile-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
        --mobile-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
        --mobile-transition: all 0.2s ease-in-out;
        --mobile-transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        --mobile-header-height: 60px;
        --mobile-touch-target: 44px;
        --mobile-touch-target-sm: 36px;
        --mobile-z-sidebar: 2000;
        --mobile-z-overlay: 1999;
        --mobile-z-header: 1000;
        --mobile-z-dropdown: 1001;
        --mobile-z-fab: 900;
        --mobile-z-modal: 3000;
        --mobile-z-toast: 4000;
    }

    * {
        -webkit-tap-highlight-color: transparent;
    }

    html {
        -webkit-text-size-adjust: 100%;
    }

    body {
        overflow-x: hidden;
        -webkit-font-smoothing: antialiased;
    }

    body.sidebar-open {
        overflow: hidden;
    }


    /* ===== LAYOUT PRINCIPAL ===== */
    .app-container {
        display: block;
        position: relative;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        transition: transform 0.3s ease;
    }

    /* ===== SIDEBAR ===== */
    .sidebar {
        width: 280px;
        max-width: calc(100vw - 60px);
        position: fixed;
        height: 100vh;
        left: 0;
        top: 0;
        z-index: var(--mobile-z-sidebar);
        transform: translateX(-100%);
        transition: var(--mobile-transition-slow);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--mobile-shadow-lg);
    }

    .sidebar-header {
        padding: 16px 20px;
    }
    
    .logo svg {
        max-width: 140px;
        height: 32px;
    }
    
    .sidebar-nav {
        padding: 16px 0;
    }
    
    .nav-item {
        padding: 12px 20px;
        font-size: 14px;
        min-height: var(--mobile-touch-target);
    }
    
    .nav-item:active {
        transform: scale(0.98);
        background-color: var(--gray-100);
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: var(--mobile-z-overlay);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    /* ===== HEADER ===== */
    .header {
        height: var(--mobile-header-height);
        min-height: var(--mobile-header-height);
        padding: 0 16px;
        z-index: var(--mobile-z-header);
    }

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        font-size: 18px;
        color: var(--gray-600);
        background-color: var(--gray-50);
        border: 1px solid var(--gray-200);
        border-radius: 8px;
    }
    
    .menu-toggle:active {
        transform: scale(0.95);
        background: var(--gray-200);
    }

    .page-title {
        font-size: 20px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .page-subtitle {
        display: none; /* Simplifica o header */
    }

    .user-info {
        display: none;
    }

    .user-avatar {
        width: 36px;
        height: 36px;
    }

    .user-dropdown {
        position: fixed;
        top: calc(var(--mobile-header-height) + 5px);
        right: 10px;
        left: 10px;
        width: auto;
        z-index: var(--mobile-z-dropdown);
    }

    /* ===== PAGE CONTENT ===== */
    .page-content {
        padding: 20px 16px;
    }

    .page-header {
        flex-direction: column;
        gap: 16px;
        margin-bottom: 24px;
        align-items: flex-start;
    }

    .page-header h1 {
        font-size: 24px;
    }

    .page-header p {
        font-size: 14px;
        color: var(--gray-500);
    }

    .page-header .btn {
        width: 100%;
    }

    /* ===== GRIDS ===== */
    .stats-grid, .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    @media (min-width: 480px) {
        .stats-grid, .grid-2 {
            grid-template-columns: repeat(2, 1fr) !important;
        }
    }

    /* ===== CARDS ===== */
    .card {
        margin-bottom: 20px;
        border-radius: 12px;
    }

    .card-header {
        padding: 16px 20px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .card-title {
        font-size: 16px;
        width: 100%;
    }

    .card-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .card-content {
        padding: 20px;
    }

    .stat-card {
        padding: 20px;
        text-align: center;
    }

    .stat-header {
        justify-content: center;
        gap: 8px;
    }

    .stat-title {
        font-size: 13px;
    }

    .stat-value {
        font-size: 28px;
    }

    /* ===== BOTÕES ===== */
    .btn {
        padding: 12px 20px;
        font-size: 14px;
        min-height: var(--mobile-touch-target);
        border-radius: 8px;
    }
    
    .btn:active {
        transform: scale(0.98);
    }

    .btn-sm {
        padding: 8px 16px;
        font-size: 12px;
        min-height: var(--mobile-touch-target-sm);
    }
    
    /* Botões em cards viram full-width */
    .card-content .btn:not(.btn-sm):not(.btn-outline),
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 8px;
    }
    .card-content .btn:last-child,
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }


    /* ===== FORMULÁRIOS ===== */
    .form-group {
        margin-bottom: 16px;
    }

    .form-label {
        font-size: 13px;
        margin-bottom: 6px;
    }

    .form-control, select, textarea {
        width: 100%;
        padding: 12px 14px;
        font-size: 16px; /* Previne zoom no iOS */
        min-height: var(--mobile-touch-target);
        border-radius: 8px;
    }
    
    select.form-control {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
        background-position: right 12px center;
        background-repeat: no-repeat;
        background-size: 16px;
        padding-right: 40px;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* ===== TABELAS ===== */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
    }

    .table {
        min-width: 600px;
    }

    .table th, .table td {
        padding: 12px 10px;
        font-size: 13px;
        white-space: nowrap;
    }

    .table th {
        font-size: 11px;
        background-color: var(--gray-50);
        position: sticky;
        top: 0;
        z-index: 2;
    }
    
    /* Coluna primária fixa para melhor navegação */
    .table th:first-child,
    .table td:first-child {
        position: sticky;
        left: 0;
        background-color: var(--white);
        z-index: 1;
        box-shadow: 2px 0 5px rgba(0,0,0,0.04);
    }
    .table tr:hover td:first-child {
      background-color: var(--gray-50);
    }
    .table th:first-child {
        z-index: 3;
        background-color: var(--gray-50);
    }

    /* ===== PÁGINA DE LOGIN ===== */
    .login-container {
        padding: 16px;
    }

    .login-card {
        padding: 24px;
        width: 100%;
    }

    .login-header {
        margin-bottom: 24px;
    }

    .login-logo svg {
        height: 50px;
    }

    .login-subtitle {
        font-size: 14px;
    }
    
    /* ===== MODAIS ===== */
    .modal-footer {
        padding: 16px 20px;
        background-color: var(--gray-50);
        border-top: 1px solid var(--gray-200);
        display: flex;
        flex-direction: column-reverse; /* Botão primário fica por último/embaixo */
        gap: 12px;
    }

    /* ===== CORREÇÃO PARA PÁGINA DE PERFIL (Profile Page Fix) v2 ===== */
    /* Aplica flexbox a todas as linhas de informação no card de perfil para melhor alinhamento. */
    /* Esta abordagem é mais compatível que a anterior. */
    .page-content .card-content > div {
        display: flex;
        align-items: center;
        flex-wrap: wrap; /* Permite que o texto quebre a linha se não houver espaço */
        gap: 8px; /* Espaço entre ícone/badge e texto */
    }

    /* Garante que ícones e badges não sejam comprimidos */
    .page-content .card-content > div > .fas,
    .page-content .card-content > div > .far,
    .page-content .card-content > div > .badge {
        flex-shrink: 0;
    }
}
