/* ========================================
   OTIMIZAÇÕES DE TOQUE PARA MOBILE - GATEWISE
   ======================================== */

/* Touch-friendly button improvements */
@media (hover: none) and (pointer: coarse) {
    /* Para dispositivos touch */
    
    /* Base touch improvements */
    * {
        -webkit-tap-highlight-color: rgba(23, 92, 255, 0.2);
        -webkit-touch-callout: none;
    }
    
    /* Button touch optimization */
    .btn,
    button,
    [role="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        user-select: none;
        -webkit-user-select: none;
        touch-action: manipulation;
    }
    
    .btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    .btn-sm {
        min-height: 40px;
        min-width: 40px;
        padding: 10px 14px;
    }
    
    .btn-lg {
        min-height: 48px;
        padding: 14px 20px;
    }
    
    /* Link touch optimization */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        text-decoration: none;
        touch-action: manipulation;
    }
    
    a:active {
        opacity: 0.7;
    }
    
    /* Form input touch optimization */
    .form-control,
    .form-select,
    input,
    textarea,
    select {
        min-height: 44px;
        font-size: 16px; /* Previne zoom no iOS */
        touch-action: manipulation;
    }
    
    .form-control:focus,
    .form-select:focus {
        transform: none;
        box-shadow: 0 0 0 3px rgba(23, 92, 255, 0.25);
    }
    
    /* Checkbox and radio touch */
    .form-check-input {
        min-width: 20px;
        min-height: 20px;
        touch-action: manipulation;
    }
    
    .form-check-label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-left: 0.5rem;
        cursor: pointer;
    }
    
    /* Navigation touch optimization */
    .nav-link {
        min-height: 48px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        touch-action: manipulation;
    }
    
    .nav-link:active {
        background-color: rgba(0, 0, 0, 0.05);
    }
    
    /* Dropdown touch optimization */
    .dropdown-item {
        min-height: 44px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        touch-action: manipulation;
    }
    
    .dropdown-item:active {
        background-color: rgba(23, 92, 255, 0.1);
    }
    
    /* Card touch optimization */
    .card {
        touch-action: manipulation;
    }
    
    .card:active {
        transform: scale(0.99);
    }
    
    .card-link {
        display: block;
        text-decoration: none;
        color: inherit;
    }
    
    .card-link:hover,
    .card-link:focus {
        color: inherit;
        text-decoration: none;
    }
    
    /* Modal touch optimization */
    .modal-header .btn-close {
        min-width: 44px;
        min-height: 44px;
        padding: 12px;
        touch-action: manipulation;
    }
    
    /* Pagination touch optimization */
    .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }
    
    .page-link:active {
        background-color: rgba(23, 92, 255, 0.1);
    }
    
    /* Tab touch optimization */
    .nav-tabs .nav-link {
        min-height: 48px;
        padding: 12px 20px;
        touch-action: manipulation;
    }
    
    /* Accordion touch optimization */
    .accordion-button {
        min-height: 48px;
        padding: 12px 16px;
        touch-action: manipulation;
    }
    
    .accordion-button:not(.collapsed) {
        background-color: rgba(23, 92, 255, 0.05);
    }
    
    /* Badge touch optimization when clickable */
    .badge[href],
    .badge[role="button"] {
        min-height: 32px;
        min-width: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }
    
    /* Close button optimization */
    .btn-close {
        min-width: 44px;
        min-height: 44px;
        padding: 12px;
        touch-action: manipulation;
    }
    
    /* Slider/Range touch optimization */
    .form-range {
        min-height: 44px;
        touch-action: pan-x;
    }
    
    /* Switch touch optimization */
    .form-switch .form-check-input {
        min-width: 48px;
        min-height: 24px;
        touch-action: manipulation;
    }
    
    .form-switch .form-check-label {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* iOS specific optimizations */
@supports (-webkit-touch-callout: none) {
    .btn,
    .form-control,
    .form-select {
        -webkit-appearance: none;
        border-radius: 6px;
    }
    
    /* Fix iOS zoom on input focus */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* iOS button styling */
    .btn {
        -webkit-appearance: none;
        background-clip: padding-box;
    }
}

/* Android specific optimizations */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Android Chrome optimizations */
    .form-control:focus,
    .form-select:focus {
        outline: none;
        box-shadow: 0 0 0 2px rgba(23, 92, 255, 0.25);
    }
}

/* Accessibility improvements for touch */
@media (hover: none) and (pointer: coarse) {
    /* Focus states for keyboard navigation on touch devices */
    .btn:focus-visible,
    .form-control:focus-visible,
    .nav-link:focus-visible,
    a:focus-visible {
        outline: 2px solid #175cff;
        outline-offset: 2px;
        box-shadow: 0 0 0 3px rgba(23, 92, 255, 0.25);
    }
    
    /* Skip to content link for screen readers */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 6px;
        background: #175cff;
        color: white;
        padding: 8px 16px;
        text-decoration: none;
        z-index: 9999;
        border-radius: 4px;
        font-size: 14px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .skip-to-content:focus {
        top: 6px;
    }
    
    /* Improved contrast for touch devices */
    .text-muted {
        color: #666 !important;
    }
    
    .btn-outline-primary {
        border-width: 2px;
    }
    
    .btn-outline-secondary {
        border-width: 2px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
    
    .form-control,
    .form-select {
        border-width: 2px;
    }
    
    .card {
        border-width: 2px;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .btn:active,
    .card:active {
        transform: none;
    }
}

/* Large text preferences */
@media (prefers-reduced-motion: no-preference) {
    .btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    
    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    }
}

/* Improved spacing for better touch targets */
@media (max-width: 767.98px) {
    .btn + .btn {
        margin-left: 0;
        margin-top: 0.5rem;
    }
    
    .btn-group-vertical .btn + .btn {
        margin-top: 1px;
    }
    
    .nav-pills .nav-link {
        margin-bottom: 0.25rem;
    }
    
    .breadcrumb-item + .breadcrumb-item {
        padding-left: 1rem;
    }
    
    .list-group-item {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 12px 16px;
    }
}

/* Swipe gesture improvements */
@media (hover: none) and (pointer: coarse) {
    .carousel-inner {
        touch-action: pan-y pinch-zoom;
    }
    
    .modal-dialog {
        touch-action: pan-y pinch-zoom;
    }
    
    .offcanvas-body {
        touch-action: pan-y pinch-zoom;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive {
        touch-action: pan-x pinch-zoom;
        -webkit-overflow-scrolling: touch;
    }
}