/* Mobile Optimizations - Sistema de Agendamento */

/* Touch-friendly buttons */
.btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Prevent zoom on input focus (iOS) */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
select,
textarea {
    font-size: 16px !important;
}

/* Bloquear zoom por gesto (complementa o viewport) */
html, body {
    touch-action: pan-x pan-y;
    -ms-touch-action: pan-x pan-y;
    overscroll-behavior: none;
}

/* Mobile table → cards legíveis (sem sobreposição) */
@media (max-width: 768px) {
    .table-responsive {
        border-radius: 12px;
        box-shadow: none;
        border: none;
        overflow: visible;
    }

    .table {
        font-size: 0.9rem;
        width: 100%;
        margin-bottom: 0;
    }

    /* Empilhar linhas como cards em qualquer mobile (<=768) */
    .table-responsive table,
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive th,
    .table-responsive td,
    .table-responsive tr {
        display: block;
        width: 100%;
    }

    .table-responsive thead {
        display: none;
    }

    .table-responsive tr {
        border: 1px solid #E2E8F0;
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 12px 14px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .table-responsive td {
        border: none !important;
        position: static !important;
        padding: 6px 0 !important;
        text-align: left !important;
        white-space: normal !important;
        word-break: break-word;
        overflow-wrap: anywhere;
        line-height: 1.4;
        display: block;
        width: 100%;
    }

    /* Sem label → não inventa ":" */
    .table-responsive td:before {
        content: none !important;
    }

    /* Label acima do valor, sem sobrepor */
    .table-responsive td[data-label] {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
        border-bottom: 1px solid #F1F5F9 !important;
    }

    .table-responsive td[data-label]:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    .table-responsive td[data-label]:before {
        content: attr(data-label) !important;
        display: block !important;
        position: static !important;
        width: auto !important;
        padding: 0 !important;
        margin: 0 0 4px 0 !important;
        font-weight: 600;
        font-size: 0.7rem;
        color: #64748B;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        line-height: 1.2;
    }

    /* Ações em linha, sem empilhar por cima do texto */
    .table-responsive td[data-label="Ações"] {
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
        padding-top: 12px !important;
    }

    .table-responsive td[data-label="Ações"]:before {
        flex: 0 0 100%;
        margin-bottom: 6px !important;
    }

    .table-responsive td[data-label="Ações"] .btn {
        margin: 0 !important;
        flex: 0 0 auto;
    }
}

/* Mobile form optimizations */
@media (max-width: 768px) {
    .form-control,
    .form-select {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 16px;
        border-radius: var(--border-radius-lg);
    }
    
    .form-label {
        font-weight: var(--font-weight-semibold);
        margin-bottom: var(--spacing-xs);
    }
    
    .input-group {
        margin-bottom: 1rem;
    }
    
    .form-check {
        margin-bottom: 1rem;
    }
    
    .form-check-input {
        width: 20px;
        height: 20px;
    }
    
    .form-check-label {
        font-size: 16px;
        padding-left: 8px;
    }
}

/* Mobile modal optimizations */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
    
    .modal-content {
        border-radius: var(--border-radius-2xl);
    }
    
    .modal-header {
        padding: var(--spacing-md);
    }
    
    .modal-body {
        padding: var(--spacing-md);
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: var(--spacing-md);
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* Mobile card optimizations */
@media (max-width: 768px) {
    .card {
        margin-bottom: var(--spacing-md);
        border-radius: var(--border-radius-xl);
    }
    
    .card-header {
        padding: var(--spacing-md);
        font-size: 1.1rem;
    }
    
    .card-body {
        padding: var(--spacing-md);
    }
    
    .card-title {
        font-size: 1.2rem;
        margin-bottom: var(--spacing-sm);
    }
}

/* Mobile navigation optimizations */
@media (max-width: 768px) {
    .navbar {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    .navbar-nav .nav-link {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 1rem;
    }
    
    .dropdown-menu {
        border-radius: var(--border-radius-lg);
        box-shadow: var(--shadow-lg);
    }
}

/* Mobile button optimizations */
@media (max-width: 768px) {
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .btn-group .btn {
        width: 100%;
        margin: 0;
    }
    
    .btn-sm {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 0.9rem;
    }
    
    .btn-lg {
        padding: var(--spacing-sm) var(--spacing-lg);
        font-size: 1.1rem;
    }
}

/* Mobile stats optimizations */
@media (max-width: 768px) {
    .stats-card {
        margin-bottom: var(--spacing-md);
    }
    
    .stats-number {
        font-size: 2rem;
    }
    
    .stats-label {
        font-size: 0.9rem;
    }
}

/* Mobile alert optimizations */
@media (max-width: 768px) {
    .alert {
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-md);
        border-radius: var(--border-radius-lg);
        font-size: 0.9rem;
    }
    
    .alert-dismissible .btn-close {
        padding: var(--spacing-sm);
    }
}

/* Mobile pagination optimizations */
@media (max-width: 768px) {
    .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: var(--spacing-xs);
    }
    
    .page-link {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 0.9rem;
        border-radius: var(--border-radius-sm);
    }
}

/* Mobile loading optimizations */
@media (max-width: 768px) {
    .spinner-border {
        width: 2rem;
        height: 2rem;
    }
    
    .spinner-border-sm {
        width: 1rem;
        height: 1rem;
    }
}

/* Mobile text optimizations */
@media (max-width: 768px) {
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.6rem; }
    h3 { font-size: 1.4rem; }
    h4 { font-size: 1.2rem; }
    h5 { font-size: 1.1rem; }
    h6 { font-size: 1rem; }
    
    .lead {
        font-size: 1.1rem;
    }
    
    .small {
        font-size: 0.85rem;
    }
}

/* Mobile utility classes */
@media (max-width: 768px) {
    .d-mobile-none {
        display: none !important;
    }
    
    .d-mobile-block {
        display: block !important;
    }
    
    .d-mobile-flex {
        display: flex !important;
    }
    
    .text-mobile-center {
        text-align: center !important;
    }
    
    .mb-mobile-3 {
        margin-bottom: var(--spacing-md) !important;
    }
    
    .p-mobile-2 {
        padding: var(--spacing-sm) !important;
    }
}

/* Performance optimizations */
* {
    -webkit-tap-highlight-color: transparent;
}

img {
    max-width: 100%;
    height: auto;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Prevent text selection on buttons */
.btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

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

/* =========================================================
   UX/UI Quick wins — Mobile (agendamentos, tabelas, toasts)
   ========================================================= */

/* Modal de agendamento: footer fixo + área de scroll */
@media (max-width: 768px) {
    .modal-dialog.modal-xl,
    .modal-dialog.modal-lg {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-dialog.modal-xl .modal-content,
    .modal-dialog.modal-lg .modal-content {
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-dialog.modal-xl .modal-header,
    .modal-dialog.modal-lg .modal-header {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 2;
        background: #fff;
        border-bottom: 1px solid #E2E8F0;
    }

    .modal-dialog.modal-xl .modal-body,
    .modal-dialog.modal-lg .modal-body {
        flex: 1 1 auto;
        max-height: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 1rem;
    }

    .modal-dialog.modal-xl .modal-footer,
    .modal-dialog.modal-lg .modal-footer {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: #fff;
        border-top: 1px solid #E2E8F0;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
    }

    /* Blocos de passageiro mais compactos e legíveis */
    .passageiro-item {
        padding: 0.75rem !important;
        margin-bottom: 0.75rem !important;
        border-radius: 12px !important;
        background: #F8FAFC !important;
    }

    .passageiro-item .row > [class*="col-"] {
        margin-bottom: 0.5rem;
    }

    /* Botões de ação em tabelas — alvo maior */
    .table .btn-sm {
        min-height: 40px;
        min-width: 40px;
        padding: 0.4rem 0.6rem;
    }

    /* Toast / alert fixo — não cortar no mobile */
    .alert.position-fixed {
        left: 12px !important;
        right: 12px !important;
        top: 12px !important;
        min-width: auto !important;
        max-width: none !important;
        width: auto !important;
    }

    /* Main content padding quando sidebar some */
    .main-content {
        margin-left: 0 !important;
    }

    /* Stats em 2 colunas */
    .row.g-3 > [class*="col-"] {
        margin-bottom: 0.5rem;
    }
}

/* Portal do motorista — botões grandes para uso em campo */
@media (max-width: 768px) {
    body .navbar .btn {
        min-height: 40px;
    }

    #viagensTable .btn {
        min-height: 44px;
        min-width: 44px;
        margin: 2px;
    }

    .container.py-4 {
        padding-top: 1rem !important;
        padding-bottom: 2rem !important;
    }
}

/* Safe area (iPhone notch) */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .modal-footer,
        .navbar {
            padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
        }
    }
}

/* Overlay do menu lateral */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 998;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Sidebar mobile — painel fixo à esquerda, altura total */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

/* Botão mobile do menu (hambúrguer) acima do overlay */
.mobile-menu-btn {
    z-index: 1001;
}

/* Travar scroll do body com menu aberto */
body.menu-open {
    overflow: hidden;
}

/* Marca do sidebar legível (não truncar com largura fixa) */
.sidebar-brand {
    white-space: normal;
    overflow: visible;
}

.sidebar-brand strong {
    display: block;
    line-height: 1.2;
}

/* =========================================================
   Dashboard inicial — UX mobile (header, stats, gráficos)
   ========================================================= */
@media (max-width: 768px) {
    /* Header em 2 linhas: título + usuário (sem competir pelo espaço) */
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    /* Espaço à esquerda do título para não colar sob o ☰ fixo
       (botão ~44px + left 15px ≈ 59px) */
    .dashboard-header .dashboard-title {
        padding-left: 60px;
        margin-bottom: 0;
        font-size: 1.4rem;
    }

    .dashboard-header .dashboard-user-info {
        font-size: 0.8rem;
        color: var(--text-secondary);
    }

    /* Reforço: Exportar some no mobile (classe d-none d-md-inline-flex já cobre) */
    #btnExportarViagens {
        display: none !important;
    }

    /* Stats: grid 2 colunas com gap uniforme de 12px */
    .stats-grid {
        --bs-gutter-x: 12px;
        --bs-gutter-y: 12px;
    }

    .stats-grid .stats-card {
        min-height: 88px;
        padding: 0.75rem;
    }

    .stats-grid .stats-number {
        font-size: 1.6rem;
    }

    .stats-grid .text-muted.small {
        font-size: 0.72rem;
        margin-bottom: 0;
    }

    /* Gráficos: container com altura fixa e padding menor */
    .chart-container {
        padding: 1rem;
    }

    .chart-box {
        height: 240px !important;
        min-height: 220px;
        overflow: hidden;
    }
}

/* Evitar tremor residual em hover no touch */
@media (hover: none) {
    .card:hover {
        transform: none !important;
        box-shadow: var(--shadow-sm) !important;
    }
    .btn:hover {
        transform: none !important;
    }
}
