/**
 * FreeRide Explorer - UI Components
 * 
 * Skeleton loaders, Progress bars, Toast notifications,
 * Empty states, Modals, Bottom sheets
 * 
 * @package FreeRide_Explorer
 * @since 2.4.0
 */

/* ===========================================
   1. SKELETON LOADERS
   =========================================== */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--fre-bg-tertiary) 0%,
        var(--fre-bg-secondary) 50%,
        var(--fre-bg-tertiary) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

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

.skeleton-text {
    height: 16px;
    margin-bottom: var(--space-2);
    border-radius: var(--radius-sm);
}

.skeleton-text:last-child {
    width: 70%;
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: var(--space-3);
    border-radius: var(--radius-sm);
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.skeleton-image {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: var(--radius-lg);
}

.skeleton-button {
    height: 44px;
    width: 120px;
    border-radius: var(--radius-lg);
}

.skeleton-card {
    padding: var(--space-4);
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-xl);
    border: 1px solid var(--fre-border-light);
}

/* Route Card Skeleton */
.skeleton-route-card {
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-xl);
    overflow: hidden;
    border: 1px solid var(--fre-border-light);
}

.skeleton-route-card .skeleton-image {
    height: 160px;
    border-radius: 0;
}

.skeleton-route-card .skeleton-content {
    padding: var(--space-4);
}

.skeleton-route-card .skeleton-meta {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-3);
}

.skeleton-route-card .skeleton-stat {
    height: 14px;
    width: 60px;
    border-radius: var(--radius-sm);
}

/* Map Skeleton */
.skeleton-map {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 300px;
    background: var(--fre-bg-tertiary);
    overflow: hidden;
}

.skeleton-map::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        linear-gradient(90deg, transparent 45%, var(--fre-border) 50%, transparent 55%),
        linear-gradient(0deg, transparent 45%, var(--fre-border) 50%, transparent 55%);
    background-size: 80px 80px;
    opacity: 0.3;
}

.skeleton-map::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    border: 3px solid var(--fre-border);
    border-top-color: var(--fre-primary);
    border-radius: var(--radius-full);
    animation: spin 1s linear infinite;
}

/* List Skeleton */
.skeleton-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.skeleton-list-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-lg);
}

.skeleton-list-item .skeleton-text {
    flex: 1;
    margin: 0;
}

/* ===========================================
   2. PROGRESS INDICATORS
   =========================================== */

/* Linear Progress */
.progress {
    width: 100%;
    height: 6px;
    background: var(--fre-bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--fre-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow) var(--ease-out);
}

.progress-bar.animated {
    background: linear-gradient(
        90deg,
        var(--fre-primary) 0%,
        var(--fre-primary-light) 50%,
        var(--fre-primary) 100%
    );
    background-size: 200% 100%;
    animation: progress-shimmer 1.5s ease-in-out infinite;
}

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

.progress-indeterminate .progress-bar {
    width: 30%;
    animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* Progress with label */
.progress-labeled {
    position: relative;
}

.progress-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--fre-text);
}

/* Circular Progress */
.progress-circular {
    position: relative;
    width: 48px;
    height: 48px;
}

.progress-circular svg {
    transform: rotate(-90deg);
}

.progress-circular-track {
    fill: none;
    stroke: var(--fre-bg-tertiary);
    stroke-width: 4;
}

.progress-circular-bar {
    fill: none;
    stroke: var(--fre-primary);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset var(--transition-slow) var(--ease-out);
}

.progress-circular-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    color: var(--fre-text);
}

/* Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--fre-bg-tertiary);
    border-top-color: var(--fre-primary);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }
.spinner-xl { width: 56px; height: 56px; border-width: 5px; }

.spinner-white { border-color: rgba(255,255,255,0.3); border-top-color: var(--fre-white); }
.spinner-secondary { border-top-color: var(--fre-secondary); }

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    background: var(--fre-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-4);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.loading-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.loading-overlay .loading-text {
    color: var(--fre-white);
    font-weight: var(--font-semibold);
    font-size: var(--text-base);
}

/* Route Calculation Progress */
.route-progress {
    position: absolute;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-fixed);
    background: var(--fre-bg-elevated);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.route-progress.visible {
    opacity: 1;
    visibility: visible;
}

.route-progress .spinner {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.route-progress span {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--fre-text-secondary);
}

/* ===========================================
   3. TOAST NOTIFICATIONS
   =========================================== */

.toast-container {
    position: fixed;
    bottom: calc(var(--safe-bottom) + var(--space-6));
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
    max-width: calc(100vw - var(--space-8));
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--fre-gray-800);
    color: var(--fre-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    pointer-events: auto;
    animation: toastSlideUp var(--transition-slow) var(--ease-out);
    max-width: 400px;
}

@keyframes toastSlideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.toast.hiding {
    animation: toastSlideDown var(--transition-base) var(--ease-in) forwards;
}

@keyframes toastSlideDown {
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
}

.toast-action {
    padding: var(--space-1) var(--space-2);
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--fre-white);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.toast-action:hover {
    background: rgba(255,255,255,0.3);
}

.toast-close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--fre-white);
    opacity: 0.6;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.toast-close:hover {
    opacity: 1;
}

.toast-close svg {
    width: 16px;
    height: 16px;
}

/* Toast Variants */
.toast-success {
    background: var(--fre-success);
}

.toast-error {
    background: var(--fre-danger);
}

.toast-warning {
    background: var(--fre-warning);
    color: var(--fre-gray-900);
}

.toast-info {
    background: var(--fre-info);
}

/* Dark mode toast */
[data-theme="dark"] .toast {
    background: var(--fre-gray-700);
}

/* ===========================================
   4. EMPTY STATES
   =========================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-12) var(--space-6);
    max-width: 400px;
    margin: 0 auto;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin-bottom: var(--space-5);
    color: var(--fre-text-muted);
    opacity: 0.5;
}

.empty-state-icon svg {
    width: 100%;
    height: 100%;
}

.empty-state-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--fre-text);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    font-size: var(--text-base);
    color: var(--fre-text-muted);
    margin-bottom: var(--space-6);
    line-height: var(--leading-relaxed);
}

.empty-state-action {
    display: inline-flex;
}

/* Empty state illustrations */
.empty-illustration {
    width: 160px;
    height: 160px;
    margin-bottom: var(--space-6);
    position: relative;
}

.empty-illustration svg {
    width: 100%;
    height: 100%;
}

/* Animated empty state */
.empty-state-animated .empty-illustration {
    animation: floatAnimation 3s ease-in-out infinite;
}

@keyframes floatAnimation {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ===========================================
   5. MODALS
   =========================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal-backdrop);
    background: var(--fre-bg-overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.modal-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    z-index: var(--z-modal);
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-slow) var(--ease-out);
}

.modal.visible {
    opacity: 1;
    visibility: visible;
}

/* Centered Modal */
.modal-centered {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: calc(100% - var(--space-8));
    max-width: 480px;
}

.modal-centered.visible {
    transform: translate(-50%, -50%) scale(1);
}

/* Full Screen Modal (Mobile) */
.modal-fullscreen {
    inset: 0;
    border-radius: 0;
    max-height: 100vh;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--fre-border-light);
    flex-shrink: 0;
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--fre-text);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.modal-title svg {
    width: 24px;
    height: 24px;
    color: var(--fre-secondary);
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fre-bg-tertiary);
    border: none;
    border-radius: var(--radius-full);
    color: var(--fre-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--fre-border);
    color: var(--fre-text);
}

.modal-close svg {
    width: 18px;
    height: 18px;
}

.modal-body {
    padding: var(--space-5);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--fre-border-light);
    flex-shrink: 0;
}

.modal-footer .btn {
    flex: 1;
}

/* ===========================================
   6. BOTTOM SHEET (Mobile)
   =========================================== */

.bottom-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal-backdrop);
    background: var(--fre-bg-overlay);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.bottom-sheet-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-modal);
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    box-shadow: var(--shadow-2xl);
    max-height: 90vh;
    transform: translateY(100%);
    transition: transform var(--transition-slow) var(--ease-out);
    display: flex;
    flex-direction: column;
}

.bottom-sheet.visible {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--fre-border);
    border-radius: var(--radius-full);
    margin: var(--space-3) auto;
    flex-shrink: 0;
}

.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--fre-border-light);
}

.bottom-sheet-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--fre-text);
}

.bottom-sheet-body {
    padding: var(--space-5);
    overflow-y: auto;
    flex: 1;
}

.bottom-sheet-footer {
    padding: var(--space-4) var(--space-5);
    padding-bottom: calc(var(--safe-bottom) + var(--space-4));
    border-top: 1px solid var(--fre-border-light);
    display: flex;
    gap: var(--space-3);
}

/* ===========================================
   7. TOOLTIPS
   =========================================== */

.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip-content {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-2) var(--space-3);
    background: var(--fre-gray-800);
    color: var(--fre-white);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-md);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    pointer-events: none;
    z-index: var(--z-tooltip);
}

.tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--fre-gray-800);
}

.tooltip:hover .tooltip-content,
.tooltip:focus .tooltip-content {
    opacity: 1;
    visibility: visible;
}

/* ===========================================
   8. TUTORIAL / ONBOARDING
   =========================================== */

.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-max);
    pointer-events: none;
}

.tutorial-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    pointer-events: auto;
}

.tutorial-spotlight {
    position: absolute;
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.75);
    pointer-events: none;
    transition: all var(--transition-slow) var(--ease-out);
}

/* Ensure tutorial target elements are fully visible */
.tutorial-target,
[data-tutorial-target] {
    position: relative;
    z-index: calc(var(--z-max) + 1);
    opacity: 1 !important;
}

/* Make toolbar buttons fully visible during tutorial */
.tutorial-overlay ~ * .btn,
.tutorial-overlay ~ * button,
.tutorial-overlay ~ * [class*="toolbar"] button {
    opacity: 1 !important;
}

.tutorial-tooltip {
    position: absolute;
    width: 320px;
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    padding: var(--space-5);
    pointer-events: auto;
    animation: slideUp var(--transition-slow) var(--ease-out);
}

.tutorial-tooltip::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--fre-bg-elevated);
    transform: rotate(45deg);
}

.tutorial-tooltip.top::before {
    bottom: -8px;
    left: 50%;
    margin-left: -8px;
}

.tutorial-tooltip.bottom::before {
    top: -8px;
    left: 50%;
    margin-left: -8px;
}

.tutorial-tooltip.left::before {
    right: -8px;
    top: 50%;
    margin-top: -8px;
}

.tutorial-tooltip.right::before {
    left: -8px;
    top: 50%;
    margin-top: -8px;
}

.tutorial-step {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--fre-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-2);
}

.tutorial-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--fre-text);
    margin-bottom: var(--space-2);
}

.tutorial-description {
    font-size: var(--text-sm);
    color: var(--fre-text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-4);
}

.tutorial-progress {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}

.tutorial-progress-dot {
    width: 8px;
    height: 8px;
    background: var(--fre-border);
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

.tutorial-progress-dot.active {
    background: var(--fre-primary);
    width: 24px;
}

.tutorial-progress-dot.completed {
    background: var(--fre-success);
}

.tutorial-actions {
    display: flex;
    gap: var(--space-3);
}

.tutorial-actions .btn {
    flex: 1;
}

.tutorial-skip {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    padding: var(--space-2) var(--space-3);
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: var(--radius-full);
    color: var(--fre-white);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    cursor: pointer;
    pointer-events: auto;
    transition: all var(--transition-fast);
}

.tutorial-skip:hover {
    background: rgba(255,255,255,0.2);
}

/* ===========================================
   9. PULL TO REFRESH
   =========================================== */

.ptr-container {
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ptr-indicator {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: var(--fre-bg-elevated);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-base);
}

.ptr-indicator svg {
    width: 20px;
    height: 20px;
    color: var(--fre-text-muted);
    transition: transform var(--transition-base);
}

.ptr-container.pulling .ptr-indicator {
    transform: translateX(-50%) translateY(60px);
}

.ptr-container.refreshing .ptr-indicator {
    transform: translateX(-50%) translateY(60px);
}

.ptr-container.refreshing .ptr-indicator svg {
    animation: spin 0.8s linear infinite;
}

/* ===========================================
   10. SWIPE ACTIONS (List Items)
   =========================================== */

.swipe-container {
    position: relative;
    overflow: hidden;
}

.swipe-content {
    position: relative;
    z-index: 1;
    background: var(--fre-bg-elevated);
    transition: transform var(--transition-fast);
}

.swipe-actions {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
}

.swipe-actions-left {
    left: 0;
}

.swipe-actions-right {
    right: 0;
}

.swipe-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    padding: var(--space-4);
    color: var(--fre-white);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    flex-direction: column;
    gap: var(--space-1);
}

.swipe-action svg {
    width: 24px;
    height: 24px;
}

.swipe-action-edit {
    background: var(--fre-info);
}

.swipe-action-delete {
    background: var(--fre-danger);
}

.swipe-action-archive {
    background: var(--fre-warning);
}
