/* Touch-Friendly UI Elements */

/* Base touch target size (minimum 44px for accessibility) */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Button improvements for touch */
.btn {
    min-height: 44px;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    touch-action: manipulation;
    user-select: none;
}

.btn-xs {
    min-height: 36px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.btn-sm {
    min-height: 40px;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
}

.btn-lg {
    min-height: 52px;
    padding: 1rem 1.5rem;
    font-size: 1.125rem;
}

/* Touch feedback for buttons */
.btn:active {
    transform: scale(0.98);
}

@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
    }
    
    .btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* Form controls touch-friendly */
.form-control {
    min-height: 44px;
    padding: 0.75rem;
    font-size: 1rem; /* Prevents zoom on iOS */
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

.form-select {
    min-height: 44px;
    padding: 0.75rem;
    font-size: 1rem;
    border-radius: 0.375rem;
    background-position: right 0.75rem center;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125rem;
    border-radius: 0.25rem;
}

.form-check-label {
    padding-left: 0.5rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

/* Input groups touch-friendly */
.input-group {
    display: flex;
    width: 100%;
}

.input-group .form-control {
    border-radius: 0.375rem 0 0 0.375rem;
}

.input-group .btn {
    border-radius: 0 0.375rem 0.375rem 0;
    border-left: none;
}

@media (max-width: 575.98px) {
    .input-group {
        flex-direction: column;
    }
    
    .input-group .form-control {
        border-radius: 0.375rem;
        margin-bottom: 0.5rem;
    }
    
    .input-group .btn {
        border-radius: 0.375rem;
        border: 1px solid #ced4da;
        width: 100%;
    }
}

/* Switch controls */
.form-switch {
    padding-left: 2.5rem;
}

.form-switch .form-check-input {
    width: 2rem;
    height: 1rem;
    margin-left: -2.5rem;
    background-image: none;
    background-position: left center;
    border-radius: 2rem;
    transition: background-position 0.15s ease-in-out;
}

.form-switch .form-check-input:checked {
    background-position: right center;
}

/* Range inputs */
.form-range {
    height: 1.5rem;
    padding: 0;
    background-color: transparent;
    appearance: none;
}

.form-range::-webkit-slider-track {
    height: 0.5rem;
    background-color: #dee2e6;
    border-radius: 1rem;
}

.form-range::-webkit-slider-thumb {
    width: 1.5rem;
    height: 1.5rem;
    background-color: #007bff;
    border: none;
    border-radius: 50%;
    appearance: none;
    cursor: pointer;
}

.form-range::-moz-range-track {
    height: 0.5rem;
    background-color: #dee2e6;
    border-radius: 1rem;
    border: none;
}

.form-range::-moz-range-thumb {
    width: 1.5rem;
    height: 1.5rem;
    background-color: #007bff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

/* Dropdown improvements */
.dropdown-toggle {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-menu {
    min-width: 200px;
    padding: 0.5rem 0;
    border: none;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border-radius: 0.5rem;
}

.dropdown-item {
    min-height: 44px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #495057;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: #f8f9fa;
    color: #16181b;
}

.dropdown-item.active {
    background-color: #007bff;
    color: #fff;
}

.dropdown-divider {
    height: 0;
    margin: 0.5rem 0;
    overflow: hidden;
    border-top: 1px solid #dee2e6;
}

/* Modal touch improvements */
.modal-dialog {
    margin: 1rem;
    pointer-events: none;
}

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0;
        width: 100%;
        height: 100%;
        max-width: none;
    }
    
    .modal-content {
        height: 100%;
        border: none;
        border-radius: 0;
    }
    
    .modal-header {
        padding: 1rem;
        border-bottom: 1px solid #dee2e6;
    }
    
    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        flex: 1;
    }
    
    .modal-footer {
        padding: 1rem;
        border-top: 1px solid #dee2e6;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        flex: 1;
    }
}

/* Tab navigation touch-friendly */
.nav-tabs {
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 1rem;
}

.nav-tabs .nav-link {
    min-height: 44px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid transparent;
    border-top-left-radius: 0.375rem;
    border-top-right-radius: 0.375rem;
    color: #495057;
    text-decoration: none;
    transition: all 0.15s ease;
}

.nav-tabs .nav-link:hover {
    border-color: #e9ecef #e9ecef #dee2e6;
    isolation: isolate;
}

.nav-tabs .nav-link.active {
    color: #495057;
    background-color: #fff;
    border-color: #dee2e6 #dee2e6 #fff;
}

@media (max-width: 767.98px) {
    .nav-tabs {
        flex-direction: column;
        border-bottom: none;
    }
    
    .nav-tabs .nav-link {
        border: 1px solid #dee2e6;
        border-radius: 0.375rem;
        margin-bottom: 0.25rem;
    }
    
    .nav-tabs .nav-link.active {
        background-color: #007bff;
        color: #fff;
        border-color: #007bff;
    }
}

/* Pills navigation */
.nav-pills .nav-link {
    min-height: 44px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 0.375rem;
    color: #495057;
    text-decoration: none;
    transition: all 0.15s ease;
}

.nav-pills .nav-link:hover {
    background-color: #e9ecef;
}

.nav-pills .nav-link.active {
    background-color: #007bff;
    color: #fff;
}

/* Pagination touch-friendly */
.pagination {
    display: flex;
    padding-left: 0;
    list-style: none;
    border-radius: 0.375rem;
    gap: 0.25rem;
}

.page-link {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #007bff;
    text-decoration: none;
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    transition: all 0.15s ease;
}

.page-link:hover {
    z-index: 2;
    color: #0056b3;
    background-color: #e9ecef;
    border-color: #dee2e6;
}

.page-item.active .page-link {
    z-index: 3;
    color: #fff;
    background-color: #007bff;
    border-color: #007bff;
}

.page-item.disabled .page-link {
    color: #6c757d;
    pointer-events: none;
    background-color: #fff;
    border-color: #dee2e6;
}

/* Badge touch improvements */
.badge {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.375rem;
}

.badge.badge-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Alert touch improvements */
.alert {
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
}

.alert-dismissible {
    padding-right: 3rem;
}

.alert-dismissible .btn-close {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    padding: 1rem;
    min-height: 44px;
    min-width: 44px;
}

/* Card touch improvements */
.card {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    background-color: #fff;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.card-header {
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid #dee2e6;
    border-top-left-radius: calc(0.5rem - 1px);
    border-top-right-radius: calc(0.5rem - 1px);
}

.card-body {
    padding: 1rem;
}

.card-footer {
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.03);
    border-top: 1px solid #dee2e6;
    border-bottom-right-radius: calc(0.5rem - 1px);
    border-bottom-left-radius: calc(0.5rem - 1px);
}

/* Accordion touch improvements */
.accordion-button {
    min-height: 44px;
    padding: 1rem;
    display: flex;
    align-items: center;
    width: 100%;
    font-size: 1rem;
    color: #495057;
    text-align: left;
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0;
    overflow-anchor: none;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, border-radius 0.15s ease;
}

.accordion-button:not(.collapsed) {
    color: #0c63e4;
    background-color: #e7f1ff;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.125);
}

.accordion-button::after {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    margin-left: auto;
    content: "";
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23495057'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-size: 1.25rem;
    transition: transform 0.2s ease-in-out;
}

.accordion-button:not(.collapsed)::after {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%230c63e4'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
    transform: rotate(-180deg);
}

/* Toast notifications touch-friendly */
.toast {
    min-width: 300px;
    max-width: 500px;
    font-size: 0.875rem;
    background-color: rgba(255, 255, 255, 0.85);
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border-radius: 0.375rem;
    opacity: 0;
    transition: opacity 0.15s linear;
}

.toast.show {
    opacity: 1;
}

.toast-header {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    color: #6c757d;
    background-color: rgba(255, 255, 255, 0.85);
    background-clip: padding-box;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    border-top-left-radius: calc(0.375rem - 1px);
    border-top-right-radius: calc(0.375rem - 1px);
}

.toast-body {
    padding: 0.75rem;
    word-wrap: break-word;
}

.btn-close {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
    border: 0;
    border-radius: 0.375rem;
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

.btn-close:hover {
    opacity: 0.75;
}

.btn-close:focus {
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
    opacity: 1;
}

/* Offcanvas touch improvements */
.offcanvas {
    position: fixed;
    bottom: 0;
    z-index: 1045;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    visibility: hidden;
    background-color: #fff;
    background-clip: padding-box;
    outline: 0;
    transition: transform 0.3s ease-in-out;
}

.offcanvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.offcanvas-title {
    margin-bottom: 0;
    line-height: 1.5;
}

.offcanvas-body {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
}

/* Responsive touch adjustments */
@media (max-width: 575.98px) {
    .btn {
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }
    
    .btn-xs {
        font-size: 0.8125rem;
        padding: 0.625rem 0.875rem;
    }
    
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .toast {
        min-width: 280px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
    
    .form-control:focus {
        border-width: 2px;
        box-shadow: 0 0 0 0.25rem rgba(0, 123, 255, 0.5);
    }
    
    .dropdown-item:focus {
        outline: 2px solid #007bff;
        outline-offset: -2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .btn,
    .form-control,
    .dropdown-item,
    .nav-link,
    .page-link,
    .accordion-button,
    .toast,
    .offcanvas {
        transition: none;
    }
    
    .accordion-button::after {
        transition: none;
    }
}
