/**
 * Mobile Fixes - Arbitrivm
 * Correções de responsividade para dispositivos móveis
 */

/* ==============================================
   VIEWPORT E TOUCH
   ============================================== */

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
}

body {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    -webkit-touch-callout: none;
}

/* ==============================================
   SIDEBAR MOBILE
   ============================================== */

@media (max-width: 768px) {
    /* Sidebar oculta por padrão em mobile */
    .sidebar-custom {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        width: 280px;
        transition: left 0.3s ease;
        z-index: 1050;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-custom.show {
        left: 0;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    /* Overlay quando sidebar aberta */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        animation: fadeIn 0.3s ease;
    }

    /* Main wrapper ocupa tela toda */
    .main-wrapper {
        margin-left: 0 !important;
        width: 100%;
    }

    /* Navbar mobile */
    .navbar-custom {
        position: sticky;
        top: 0;
        z-index: 1030;
        padding: 0.5rem 1rem;
    }

    /* Botão hamburguer mais visível */
    #sidebar-toggle {
        font-size: 1.75rem;
        padding: 0.5rem;
        margin-right: 0.5rem;
    }
}

/* ==============================================
   CARDS E CONTAINERS
   ============================================== */

@media (max-width: 768px) {
    /* Cards em mobile */
    .card {
        margin-bottom: 1rem;
        border-radius: 0.75rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    /* Stat cards em mobile */
    .stat-card {
        margin-bottom: 1rem;
    }

    .stat-card .card-body {
        padding: 1.25rem;
    }

    /* Container principal */
    .container-fluid {
        padding: 1rem;
    }

    /* Row adjustments */
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

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

@media (max-width: 768px) {
    /* Tabelas responsivas com scroll horizontal */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
    }

    table {
        font-size: 0.875rem;
    }

    table th,
    table td {
        padding: 0.5rem;
        white-space: nowrap;
    }

    /* Alternativa: transformar tabela em cards */
    .table-mobile-cards {
        display: block;
        width: 100%;
    }

    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody,
    .table-mobile-cards tr,
    .table-mobile-cards td {
        display: block;
        width: 100%;
    }

    .table-mobile-cards tr {
        margin-bottom: 1rem;
        border: 1px solid var(--gray-200);
        border-radius: 0.5rem;
        padding: 1rem;
        background: white;
    }

    .table-mobile-cards td {
        text-align: right;
        padding: 0.5rem 0;
        border: none;
        position: relative;
        padding-left: 50%;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        text-align: left;
        font-weight: 600;
        color: var(--primary);
    }
}

/* ==============================================
   FORMULÁRIOS
   ============================================== */

@media (max-width: 768px) {
    /* Inputs maiores para touch */
    .form-control,
    .form-select,
    .btn {
        font-size: 1rem;
        padding: 0.625rem 0.875rem;
        min-height: 44px; /* Apple recomenda mínimo 44px */
    }

    /* Labels mais espaçados */
    .form-label {
        margin-bottom: 0.5rem;
        font-weight: 500;
    }

    /* Form groups */
    .mb-3 {
        margin-bottom: 1.25rem !important;
    }

    /* Botões full-width em mobile */
    .btn-mobile-full {
        width: 100%;
        margin-bottom: 0.75rem;
    }

    /* File inputs mais visíveis */
    .form-control[type="file"] {
        padding: 0.75rem;
        border: 2px dashed var(--gray-300);
        background: var(--gray-50);
    }
}

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

@media (max-width: 768px) {
    /* Modal ocupa mais espaço */
    .modal-dialog {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }

    .modal-fullscreen-sm-down {
        width: 100%;
        height: 100%;
        margin: 0;
        max-width: 100%;
    }

    .modal-fullscreen-sm-down .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    /* Modal header */
    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0;
    }
}

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

@media (max-width: 768px) {
    /* Badges mais legíveis */
    .badge {
        padding: 0.375rem 0.625rem;
        font-size: 0.875rem;
    }

    /* Alertas */
    .alert {
        padding: 1rem;
        font-size: 0.9375rem;
    }

    .alert .btn-close {
        padding: 0.75rem;
    }
}

/* ==============================================
   DROPDOWN E MENUS
   ============================================== */

@media (max-width: 768px) {
    /* Dropdown mais largo */
    .dropdown-menu {
        min-width: 250px;
        max-width: calc(100vw - 2rem);
    }

    .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }

    /* Avatar no header */
    .avatar-circle {
        width: 32px;
        height: 32px;
        font-size: 0.875rem;
    }

    /* Ocultar textos longos em mobile */
    .d-none-mobile {
        display: none !important;
    }
}

/* ==============================================
   TIMELINE
   ============================================== */

@media (max-width: 768px) {
    .timeline-custom {
        padding-left: 1.5rem;
    }

    .timeline-item::before {
        left: -1.5rem;
        width: 12px;
        height: 12px;
    }

    .timeline-item::after {
        left: -1.125rem;
    }

    .timeline-content {
        padding: 0.75rem;
    }
}

/* ==============================================
   TIPOGRAFIA MOBILE
   ============================================== */

@media (max-width: 768px) {
    /* Headings menores */
    h1, .h1 {
        font-size: 1.75rem;
    }

    h2, .h2 {
        font-size: 1.5rem;
    }

    h3, .h3 {
        font-size: 1.25rem;
    }

    h4, .h4 {
        font-size: 1.125rem;
    }

    h5, .h5 {
        font-size: 1rem;
    }

    /* Display headings */
    .display-1 {
        font-size: 3rem;
    }

    .display-2 {
        font-size: 2.5rem;
    }

    .display-3 {
        font-size: 2rem;
    }

    .display-4 {
        font-size: 1.75rem;
    }

    /* Texto do corpo */
    body {
        font-size: 0.9375rem;
    }

    .small, small {
        font-size: 0.8125rem;
    }
}

/* ==============================================
   UTILITÁRIOS MOBILE
   ============================================== */

@media (max-width: 768px) {
    /* Spacing reduzido */
    .py-4 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }

    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .mb-4 {
        margin-bottom: 1.5rem !important;
    }

    .mb-5 {
        margin-bottom: 2rem !important;
    }

    /* Overflow scroll suave */
    .overflow-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Imagens responsivas */
    img {
        max-width: 100%;
        height: auto;
    }
}

/* ==============================================
   CHAT E MENSAGENS
   ============================================== */

@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 200px);
        max-height: 600px;
    }

    .chat-messages {
        padding: 1rem;
    }

    .message-bubble {
        max-width: 85%;
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }

    .chat-input {
        padding: 0.75rem;
    }

    .chat-input .form-control {
        font-size: 1rem;
    }
}

/* ==============================================
   DOCUMENTOS E UPLOAD
   ============================================== */

@media (max-width: 768px) {
    .document-card {
        padding: 1rem;
    }

    .document-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }

    .document-actions .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Upload zone */
    .upload-zone {
        padding: 2rem 1rem;
        min-height: 150px;
    }

    .upload-zone-text {
        font-size: 0.9375rem;
    }
}

/* ==============================================
   SAFE AREA (iPhone notch)
   ============================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .navbar-custom {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-top: max(0.5rem, env(safe-area-inset-top));
    }

    .sidebar-custom {
        padding-left: max(0px, env(safe-area-inset-left));
    }
}

/* ==============================================
   PWA STANDALONE MODE
   ============================================== */

@media (display-mode: standalone) {
    /* Ajustes quando rodando como PWA instalado */
    .navbar-custom {
        padding-top: calc(env(safe-area-inset-top) + 0.5rem);
    }

    /* Esconder elementos desnecessários no app */
    .pwa-hide-standalone {
        display: none !important;
    }
}

/* ==============================================
   LANDSCAPE MODE
   ============================================== */

@media (max-width: 768px) and (orientation: landscape) {
    /* Navbar mais compacta em landscape */
    .navbar-custom {
        padding: 0.25rem 1rem;
    }

    /* Sidebar mais estreita */
    .sidebar-custom {
        width: 240px;
    }

    .sidebar-custom.show {
        left: 0;
    }

    /* Modal ajustado */
    .modal-body {
        max-height: calc(100vh - 120px);
    }
}

/* ==============================================
   ANIMAÇÕES SUAVES
   ============================================== */

@media (prefers-reduced-motion: no-preference) {
    .sidebar-custom,
    .dropdown-menu,
    .modal,
    .alert {
        transition: all 0.3s ease;
    }
}

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

/* ==============================================
   DARK MODE (futuro)
   ============================================== */

@media (prefers-color-scheme: dark) {
    /* Preparado para implementação futura de dark mode */
}

/* ==============================================
   PRINT (ocultar elementos desnecessários)
   ============================================== */

@media print {
    .sidebar-custom,
    .navbar-custom,
    .btn,
    .pwa-notification,
    .pwa-offline-indicator {
        display: none !important;
    }

    .main-wrapper {
        margin-left: 0 !important;
    }

    body {
        background: white !important;
    }
}
