/**
 * Mobile Optimization Styles
 * Otimizações para dispositivos móveis
 * Autor: Diego Bernardes Silva
 * Data: 17/10/2025
 */

/* ===================================
   VARIÁVEIS GLOBAIS MOBILE
   =================================== */
:root {
    --mobile-padding: 0.75rem;
    --mobile-font-size: 0.9rem;
    --touch-target-size: 44px; /* Tamanho mínimo recomendado para touch */
}

/* ===================================
   MELHORIAS GERAIS MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Padding reduzido em containers */
    .container, .container-fluid {
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }
    
    /* Títulos menores */
    h1 {
        font-size: 1.75rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    h3 {
        font-size: 1.25rem !important;
    }
    
    /* Texto base menor */
    body {
        font-size: var(--mobile-font-size);
    }
    
    /* Cards com menos padding */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
}

/* ===================================
   FORMULÁRIOS MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Inputs maiores para touch */
    .form-control,
    .form-select,
    textarea {
        font-size: 16px !important; /* Previne zoom no iOS */
        min-height: var(--touch-target-size);
        padding: 0.75rem;
    }
    
    /* Labels mais visíveis */
    .form-label {
        font-weight: 600;
        margin-bottom: 0.5rem;
    }
    
    /* Botões maiores para touch */
    .btn {
        min-height: var(--touch-target-size);
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }
    
    /* Botões em linha viram full-width */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-group-mobile .btn {
        width: 100%;
    }
    
    /* Formulário ocupa toda largura */
    .form-row {
        flex-direction: column;
    }
    
    .form-row > * {
        width: 100% !important;
        margin-bottom: 1rem;
    }
}

/* ===================================
   TABELAS MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Container com scroll horizontal */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scroll no iOS */
    }
    
    /* Tabela compacta */
    .table {
        font-size: 0.85rem;
    }
    
    .table td, .table th {
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }
    
    /* Ocultar colunas menos importantes */
    .table .hide-mobile {
        display: none !important;
    }
    
    /* Tabela em cards (alternativa) */
    .table-card {
        display: block;
    }
    
    .table-card thead {
        display: none;
    }
    
    .table-card tbody,
    .table-card tr {
        display: block;
        margin-bottom: 1rem;
    }
    
    .table-card tr {
        border: 1px solid var(--bs-gray-700);
        border-radius: 8px;
        padding: 1rem;
    }
    
    .table-card td {
        display: block;
        text-align: right;
        padding: 0.5rem 0;
        border: none;
    }
    
    .table-card td:before {
        content: attr(data-label);
        float: left;
        font-weight: bold;
        color: var(--bs-secondary);
    }
}

/* ===================================
   NAVEGAÇÃO MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Navbar mais compacta */
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    .navbar-toggler {
        padding: 0.5rem;
        font-size: 1.25rem;
    }
    
    /* Menu collapse ocupa tela toda */
    .navbar-collapse {
        background: var(--bs-dark);
        padding: 1rem;
        margin: 0 -1rem;
        border-radius: 0 0 8px 8px;
    }
    
    /* Links do menu maiores */
    .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 1rem;
        min-height: var(--touch-target-size);
        display: flex;
        align-items: center;
    }
    
    /* Dropdown menu */
    .dropdown-menu {
        border: none;
        background: var(--bs-gray-800);
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        min-height: var(--touch-target-size);
    }
}

/* ===================================
   CANVAS DE ASSINATURA MOBILE
   =================================== */
@media (max-width: 768px) {
    .signature-pad-container {
        width: 100%;
        margin: 0;
    }
    
    .signature-canvas {
        width: 100% !important;
        height: 250px !important; /* Altura maior no mobile */
        max-width: 100%;
        touch-action: none; /* Previne scroll durante assinatura */
        border: 2px solid var(--bs-primary);
        border-radius: 8px;
    }
    
    /* Botões de controle do canvas */
    .signature-controls {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 1rem;
    }
    
    .signature-controls .btn {
        width: 100%;
    }
}

/* ===================================
   MODAIS MOBILE
   =================================== */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 12px;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* ===================================
   FILTROS E BUSCA MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Container de filtros */
    .filter-container {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .filter-row {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .filter-row > * {
        width: 100% !important;
    }
    
    /* Botões de filtro empilhados */
    .filter-buttons {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .filter-buttons .btn {
        width: 100%;
    }
    
    /* Busca full-width */
    .search-input {
        width: 100%;
    }
}

/* ===================================
   CARDS E BADGES MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Badges maiores */
    .badge {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    /* Cards empilhados */
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }
}

/* ===================================
   NOTIFICAÇÕES MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Lista de notificações */
    .notification-item {
        padding: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .notification-item .notification-title {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .notification-item .notification-message {
        font-size: 0.85rem;
    }
    
    /* Botão de marcar como lida maior */
    .notification-item .btn {
        min-height: var(--touch-target-size);
    }
}

/* ===================================
   PAGINAÇÃO MOBILE
   =================================== */
@media (max-width: 768px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-item {
        margin: 0.125rem;
    }
    
    .pagination .page-link {
        min-width: var(--touch-target-size);
        min-height: var(--touch-target-size);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
    }
    
    /* Ocultar alguns números em telas muito pequenas */
    @media (max-width: 576px) {
        .pagination .page-item:not(.active):not(.disabled):not(:first-child):not(:last-child):nth-child(n+4):nth-last-child(n+4) {
            display: none;
        }
    }
}

/* ===================================
   AÇÕES RÁPIDAS MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Botões de ação empilhados */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Dropdown de ações */
    .dropdown-toggle {
        width: 100%;
        min-height: var(--touch-target-size);
    }
}

/* ===================================
   IMAGENS E MÍDIA MOBILE
   =================================== */
@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Logo menor */
    .logo {
        max-width: 150px;
    }
    
    /* Assinatura visualizada */
    .signature-image {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
    }
}

/* ===================================
   ALERTAS E MENSAGENS MOBILE
   =================================== */
@media (max-width: 768px) {
    .alert {
        padding: 0.75rem;
        margin-bottom: 1rem;
        font-size: 0.9rem;
    }
    
    .alert .btn-close {
        padding: 0.5rem;
    }
}

/* ===================================
   UTILITÁRIOS MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Margem e padding responsivos */
    .mt-mobile-0 { margin-top: 0 !important; }
    .mb-mobile-1 { margin-bottom: 0.5rem !important; }
    .p-mobile-2 { padding: 1rem !important; }
    
    /* Texto centralizado */
    .text-mobile-center {
        text-align: center !important;
    }
    
    /* Ocultar em mobile */
    .hide-on-mobile {
        display: none !important;
    }
    
    /* Mostrar apenas em mobile */
    .show-on-mobile {
        display: block !important;
    }
    
    /* Flex direction column */
    .flex-mobile-column {
        flex-direction: column !important;
    }
    
    /* Width 100% */
    .w-mobile-100 {
        width: 100% !important;
    }
}

/* ===================================
   ESPECÍFICO: EXTRA SMALL (< 576px)
   =================================== */
@media (max-width: 576px) {
    /* Padding ainda menor */
    .container, .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Títulos ainda menores */
    h1 {
        font-size: 1.5rem !important;
    }
    
    h2 {
        font-size: 1.25rem !important;
    }
    
    /* Botões compactos */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    /* Cards sem margem lateral */
    .card {
        border-radius: 8px;
    }
}

/* ===================================
   LANDSCAPE MOBILE (480px - 768px)
   =================================== */
@media (min-width: 480px) and (max-width: 768px) and (orientation: landscape) {
    /* Aproveitar largura em landscape */
    .modal-dialog {
        max-width: 90%;
    }
    
    /* Canvas de assinatura mais largo */
    .signature-canvas {
        height: 200px !important;
    }
}

/* ===================================
   ACESSIBILIDADE TOUCH
   =================================== */
@media (pointer: coarse) {
    /* Aumentar área de toque */
    a, button, .btn, .nav-link, .dropdown-item {
        min-height: var(--touch-target-size);
        display: inline-flex;
        align-items: center;
    }
    
    /* Remover hover effects em touch devices */
    .btn:hover,
    .nav-link:hover {
        transform: none;
    }
    
    /* Focus visible maior */
    :focus-visible {
        outline: 3px solid var(--bs-primary);
        outline-offset: 2px;
    }
}

/* ===================================
   PERFORMANCE MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Reduzir animações para performance */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Desabilitar transforms pesados */
    .disable-transform-mobile {
        transform: none !important;
    }
}

/* ===================================
   STICKY ELEMENTS MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Navbar sticky otimizada */
    .navbar.fixed-top {
        position: sticky;
        top: 0;
        z-index: 1030;
    }
    
    /* Footer sticky */
    .footer-mobile-sticky {
        position: sticky;
        bottom: 0;
        background: var(--bs-dark);
        padding: 1rem;
        border-top: 1px solid var(--bs-gray-700);
    }
}

/* ===================================
   GRID MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Forçar col-12 em mobile */
    .force-mobile-full {
        width: 100% !important;
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Grid 2 colunas em mobile */
    .grid-mobile-2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

/* ===================================
   SCROLL OTIMIZADO
   =================================== */
@media (max-width: 768px) {
    /* Scroll suave */
    html {
        scroll-behavior: smooth;
    }
    
    /* Scroll customizado */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: var(--bs-gray-600);
        border-radius: 3px;
    }
    
    ::-webkit-scrollbar-track {
        background: var(--bs-gray-900);
    }
}

/* ===================================
   FAB (Floating Action Button) MOBILE
   =================================== */
@media (max-width: 768px) {
    .fab-mobile {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        z-index: 1000;
        font-size: 1.5rem;
    }
    
    .fab-mobile:active {
        transform: scale(0.95);
    }
}

/* ===================================
   LOADING STATES MOBILE
   =================================== */
@media (max-width: 768px) {
    .loading-mobile {
        text-align: center;
        padding: 2rem;
    }
    
    .loading-mobile .spinner-border {
        width: 3rem;
        height: 3rem;
    }
}

