/**
 * Button Feedback Styles
 * Full-page loading overlay for navigation and form submissions
 */

/* Full-page loading overlay */
#page-loading-overlay {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100vh !important;
    min-height: -webkit-fill-available !important;
    z-index: 99999 !important;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    /* Mobile Safari fix for fixed positioning */
    -webkit-overflow-scrolling: touch;
    overflow: hidden;
    visibility: hidden;
    opacity: 0;
    /* Force GPU acceleration for better mobile performance */
    -webkit-transform: translate3d(0,0,0);
    transform: translate3d(0,0,0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Ensure overlay covers address bar on mobile */
    -webkit-transform: translateZ(0);
}

/* When overlay is shown via JS */
#page-loading-overlay[style*="display: flex"],
#page-loading-overlay[style*="display: -webkit-flex"] {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Semi-transparent backdrop */
.loading-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    background: rgba(0, 0, 0, 0.5);
    /* Fallback for browsers without backdrop-filter support (most mobile) */
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    /* Force GPU acceleration */
    -webkit-transform: translate3d(0,0,0);
    transform: translate3d(0,0,0);
}

/* Mobile browsers fallback - darker background when blur not supported */
@supports not (backdrop-filter: blur(2px)) {
    .loading-overlay-backdrop {
        background: rgba(0, 0, 0, 0.7);
    }
}

/* Centered content container */
.loading-overlay-content {
    position: relative;
    z-index: 1;
    text-align: center;
    background: white;
    padding: 2rem 3rem;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    -webkit-animation: fadeInScale 0.2s ease-out;
    animation: fadeInScale 0.2s ease-out;
    max-width: 90%;
    /* Prevent content from being selected/highlighted on mobile */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Mobile responsive padding */
@media (max-width: 576px) {
    .loading-overlay-content {
        padding: 1.5rem 2rem;
        max-width: 85%;
    }
}

/* Close button */
.loading-overlay-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    -webkit-transition: color 0.2s ease;
    transition: color 0.2s ease;
    z-index: 2;
    /* Ensure touch target is large enough for mobile */
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.loading-overlay-close:hover {
    color: #333;
}

.loading-overlay-close:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
    border-radius: 4px;
}

.loading-overlay-close:active {
    color: #000;
}

/* Make backdrop clickable */
.loading-overlay-backdrop {
    cursor: pointer;
    /* Enable touch events on mobile */
    touch-action: auto;
}

/* Loading text */
.loading-overlay-text {
    color: #333;
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 1rem;
}

/* Fade in animation */
@-webkit-keyframes fadeInScale {
    from {
        opacity: 0;
        -webkit-transform: scale(0.9);
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        -webkit-transform: scale(1);
        transform: scale(1);
    }
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        -webkit-transform: scale(0.9);
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        -webkit-transform: scale(1);
        transform: scale(1);
    }
}

/* Spinner animation */
@-webkit-keyframes spinner {
    to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

@keyframes spinner {
    to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

.spinner-border {
    -webkit-animation: spinner 0.75s linear infinite;
    animation: spinner 0.75s linear infinite;
}

/* Add smooth transitions to buttons and links */
.btn, a {
    -webkit-transition: all 0.2s ease-in-out;
    transition: all 0.2s ease-in-out;
}

/* Active state for buttons - visual press effect */
.btn:active:not(:disabled) {
    -webkit-transform: scale(0.98);
    transform: scale(0.98);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Disabled button cursor */
.btn:disabled,
.btn.disabled {
    cursor: not-allowed !important;
    opacity: 0.65;
}

/* Loading link state */
a.link-loading {
    opacity: 0.7;
    pointer-events: none;
    cursor: wait !important;
}

/* Loading button state */
.btn-loading {
    position: relative;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    -webkit-animation: spinner 0.6s linear infinite;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

/* Link active state - subtle color change */
a:active:not(.btn) {
    opacity: 0.7;
}

/* Prevent text selection during rapid clicks */
.btn,
.btn * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Card/clickable element feedback */
.card-clickable {
    cursor: pointer;
    -webkit-transition: -webkit-transform 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    transition: transform 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.card-clickable:hover {
    -webkit-transform: translateY(-2px);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card-clickable:active {
    -webkit-transform: translateY(0);
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Loading overlay for forms */
.form-loading {
    position: relative;
    pointer-events: none;
}

.form-loading::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

.form-loading::after {
    content: "";
    position: absolute;
    width: 40px;
    height: 40px;
    top: 50%;
    left: 50%;
    margin-left: -20px;
    margin-top: -20px;
    border: 4px solid #007bff;
    border-radius: 50%;
    border-top-color: transparent;
    -webkit-animation: spinner 0.8s linear infinite;
    animation: spinner 0.8s linear infinite;
    z-index: 11;
}

/* Spinner animation for Bootstrap spinner-border */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}
