/**
 * UX Enhancements Styles
 * Loading states, skeleton loaders, tooltips, accessibility
 */

/* Loading States */
.form-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 8px;
}

.button-loading-spinner,
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2596be;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

button.is-loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

/* Skeleton Loaders */
.skeleton-loader {
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.skeleton-line {
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 12px;
}

.skeleton-line.short {
    width: 60%;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-table {
    padding: 16px;
}

.skeleton-row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.skeleton-cell {
    flex: 1;
    height: 40px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-card {
    padding: 24px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: white;
}

.skeleton-header {
    height: 24px;
    width: 40%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 16px;
}

.skeleton-body {
    margin-top: 16px;
}

.skeleton-form {
    padding: 24px;
}

.skeleton-field {
    margin-bottom: 24px;
}

.skeleton-label {
    height: 14px;
    width: 30%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-input {
    height: 40px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-list {
    padding: 16px;
}

.skeleton-item {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    align-items: center;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    flex-shrink: 0;
}

.skeleton-content {
    flex: 1;
}

/* Optimistic UI Updates */
.optimistic-update {
    opacity: 0.7;
    position: relative;
}

.optimistic-update::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(37, 150, 190, 0.1);
    border-radius: 4px;
}

.optimistic-confirmed {
    animation: success-pulse 0.5s ease-out;
}

.optimistic-reverted {
    animation: error-shake 0.5s ease-out;
}

@keyframes success-pulse {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(16, 185, 129, 0.2); }
}

@keyframes error-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Enhanced Empty States */
.empty-state-enhanced {
    text-align: center;
    padding: 48px 24px;
    max-width: 500px;
    margin: 0 auto;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-state-enhanced h3 {
    font-size: 20px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
}

.empty-state-enhanced p {
    color: #6b7280;
    margin-bottom: 24px;
    line-height: 1.6;
}

.empty-state-enhanced .btn-primary {
    display: inline-block;
    padding: 12px 24px;
    background: #2596be;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
}

.empty-state-enhanced .btn-primary:hover {
    background: #1a7a9a;
    transform: translateY(-2px);
}

/* Tooltips */
.custom-tooltip {
    position: absolute;
    background: #1f2937;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    pointer-events: none;
    z-index: 10000;
    max-width: 200px;
    word-wrap: break-word;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.custom-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1f2937;
}

/* Keyboard Shortcuts Modal */
.keyboard-shortcuts-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.keyboard-shortcuts-modal .modal-content {
    background: white;
    padding: 24px;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.keyboard-shortcuts-modal h2 {
    margin-bottom: 16px;
    font-size: 24px;
    font-weight: 600;
}

.keyboard-shortcuts-modal table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.keyboard-shortcuts-modal td {
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.keyboard-shortcuts-modal kbd {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Skip Links */
.skip-links {
    position: absolute;
    top: -40px;
    left: 0;
    z-index: 10000;
}

.skip-link {
    position: absolute;
    top: 0;
    left: 0;
    background: #2596be;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    transform: translateY(-100%);
    transition: transform 0.2s;
}

.skip-link:focus {
    transform: translateY(0);
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .skeleton-row {
        flex-direction: column;
    }

    .skeleton-cell {
        width: 100%;
    }

    .empty-state-enhanced {
        padding: 32px 16px;
    }

    .empty-state-icon {
        font-size: 48px;
    }

    .keyboard-shortcuts-modal .modal-content {
        width: 95%;
        padding: 16px;
    }

    /* Touch-friendly buttons */
    button, a.btn, .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }

    /* Larger tap targets */
    input, select, textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Accessibility Enhancements */
*:focus-visible {
    outline: 3px solid #2596be;
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid #2596be;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(37, 150, 190, 0.2);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .skeleton-loader {
        background: #000;
    }

    .custom-tooltip {
        border: 2px solid white;
    }
}

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

    .skeleton-loader {
        animation: none;
    }
}

/* Print styles */
@media print {
    .skip-links,
    .custom-tooltip,
    .keyboard-shortcuts-modal,
    .form-loading-overlay {
        display: none !important;
    }
}

