/**
 * Horizon CRM - Mobile Polish & Animations CSS
 * Styles for pull-to-refresh, skeleton loaders, page transitions, loading states
 */

/* ============================================
   PULL-TO-REFRESH STYLES
   ============================================ */

.pull-to-refresh-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0;
    overflow: hidden;
    background: linear-gradient(180deg, #f0f9ff 0%, #e0f2fe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.pull-to-refresh-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.pull-to-refresh-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e0f2fe;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    opacity: 0;
    transition: opacity 0.3s;
}

.pull-to-refresh-indicator.ready .pull-to-refresh-spinner {
    opacity: 1;
}

.pull-to-refresh-indicator.refreshing .pull-to-refresh-spinner {
    opacity: 1;
}

.pull-to-refresh-text {
    font-size: 13px;
    font-weight: 600;
    color: #2563eb;
    opacity: 0.8;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   SWIPE GESTURE FEEDBACK
   ============================================ */

.mobile-card.swiping {
    transition: none !important;
}

.mobile-card.swiping-left {
    background: linear-gradient(90deg, transparent 0%, rgba(239, 68, 68, 0.1) 100%);
}

.mobile-card.swiping-right {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.1) 0%, transparent 100%);
}

/* ============================================
   SKELETON LOADING SCREENS
   ============================================ */

.skeleton-loader {
    animation: fadeIn 0.3s ease;
}

.skeleton-item {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 16px;
    background: white;
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

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

.skeleton-text-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skeleton-text {
    height: 16px;
    border-radius: 4px;
    background: linear-gradient(
        90deg,
        #e5e7eb 0%,
        #f3f4f6 50%,
        #e5e7eb 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-text-title {
    width: 60%;
    height: 18px;
}

.skeleton-text-subtitle {
    width: 40%;
    height: 14px;
}

.skeleton-text-body {
    width: 100%;
}

.skeleton-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.skeleton-card .skeleton-text {
    margin-bottom: 12px;
}

.skeleton-button {
    height: 40px;
    width: 120px;
    border-radius: 8px;
    background: linear-gradient(
        90deg,
        #e5e7eb 0%,
        #f3f4f6 50%,
        #e5e7eb 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    margin-top: 8px;
}

.skeleton-table-row {
    display: flex;
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid #e5e7eb;
}

.skeleton-table-row .skeleton-text {
    height: 20px;
}

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

.skeleton-loader.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ============================================
   PAGE TRANSITIONS
   ============================================ */

body {
    transition: opacity 0.25s ease, transform 0.25s ease;
}

body.page-transition-out {
    opacity: 0;
    transform: scale(0.98);
}

body.page-transition-in {
    animation: pageTransitionIn 0.3s ease;
}

@keyframes pageTransitionIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================
   LOADING SPINNERS
   ============================================ */

.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

/* Button loading state */
.btn[disabled] {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Overlay loading spinner */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.2s ease;
}

.loading-overlay .spinner-border {
    width: 48px;
    height: 48px;
    border-width: 4px;
    border-color: #2563eb;
    border-right-color: transparent;
}

.loading-overlay .loading-text {
    margin-top: 16px;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

/* ============================================
   HAPTIC FEEDBACK VISUAL EFFECTS
   ============================================ */

.btn:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
}

.btn-primary:active {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
}

.btn-danger:active {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

.btn-success:active {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

/* ============================================
   TOAST NOTIFICATIONS (Enhanced)
   ============================================ */

.toast-container {
    z-index: 9999;
}

.toast {
    min-width: 280px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    animation: slideInUp 0.3s ease;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast.hide {
    animation: slideOutDown 0.3s ease;
}

@keyframes slideOutDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

.toast-body {
    display: flex;
    align-items: center;
    font-size: 15px;
    font-weight: 500;
    padding: 14px 16px;
}

.toast-body i {
    font-size: 18px;
}

/* ============================================
   SMOOTH SCROLL
   ============================================ */

html {
    scroll-behavior: smooth;
}

/* ============================================
   CARD HOVER EFFECTS (Desktop)
   ============================================ */

@media (min-width: 768px) {
    .mobile-card {
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .mobile-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    }
}

/* ============================================
   RIPPLE EFFECT (Optional Enhancement)
   ============================================ */

.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.ripple:active::after {
    width: 300px;
    height: 300px;
}

/* ============================================
   MOBILE-SPECIFIC ANIMATIONS
   ============================================ */

@media (max-width: 767px) {
    /* Faster animations on mobile */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Reduce motion for accessibility */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
        }
    }
}

/* ============================================
   LOADING STATES FOR SPECIFIC COMPONENTS
   ============================================ */

/* Form loading state */
.form-loading {
    pointer-events: none;
    opacity: 0.6;
    position: relative;
}

.form-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin-top: -16px;
    margin-left: -16px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* List loading state */
.list-loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty state enhancement */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    animation: fadeIn 0.5s ease;
}

.empty-state i {
    font-size: 64px;
    color: #d1d5db;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

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

.empty-state h3 {
    font-size: 20px;
    font-weight: 700;
    color: #374151;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 15px;
    color: #6b7280;
    margin-bottom: 24px;
}

/* ============================================
   SUCCESS/ERROR ANIMATIONS
   ============================================ */

.success-checkmark {
    width: 80px;
    height: 80px;
    margin: 0 auto;
    border-radius: 50%;
    display: block;
    stroke-width: 2;
    stroke: #10b981;
    stroke-miterlimit: 10;
    animation: scaleIn 0.3s ease, checkmark 0.8s ease;
}

@keyframes scaleIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes checkmark {
    0% {
        stroke-dashoffset: 100;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.error-icon {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}
