/* ========================================
   UX Enhancements v1.0
   Visual & Interaction Improvements
   ======================================== */

/* ===== 1. SCROLL REVEAL ANIMATIONS ===== */
.ux-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.ux-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

.ux-reveal-left {
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.ux-reveal-left.revealed {
    opacity: 1;
    transform: translateX(0);
}

.ux-reveal-right {
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.ux-reveal-right.revealed {
    opacity: 1;
    transform: translateX(0);
}

.ux-reveal-scale {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.ux-reveal-scale.revealed {
    opacity: 1;
    transform: scale(1);
}

/* Stagger delays for children */
.ux-stagger > * { transition-delay: calc(var(--i, 0) * 0.08s); }

/* ===== 2. BACK TO TOP BUTTON ===== */
.ux-back-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.9);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.8);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
    backdrop-filter: blur(4px);
}

.ux-back-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.ux-back-top:hover {
    background: rgba(99, 102, 241, 1);
    transform: translateY(-3px) scale(1.08);
    box-shadow: 0 8px 28px rgba(99, 102, 241, 0.45);
}

.ux-back-top:active {
    transform: translateY(0) scale(0.95);
}

/* Progress ring inside back-to-top */
.ux-btt-ring {
    position: absolute;
    inset: -2px;
    border-radius: 50%;
}

.ux-btt-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ux-btt-ring circle {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.15s ease;
}

.ux-btt-ring .track { stroke: rgba(255, 255, 255, 0.15); }
.ux-btt-ring .progress { stroke: rgba(255, 255, 255, 0.7); }

/* ===== 3. ENHANCED CARD HOVER EFFECTS ===== */
.ux-glass-card {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(99, 102, 241, 0.08);
    border-radius: var(--radius-md, 12px);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.ux-glass-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), transparent 50%, rgba(6, 182, 212, 0.03));
    opacity: 0;
    transition: opacity 0.35s ease;
    pointer-events: none;
}

.ux-glass-card:hover {
    border-color: rgba(99, 102, 241, 0.2);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(99, 102, 241, 0.1);
}

.ux-glass-card:hover::before { opacity: 1; }

/* Gradient border shimmer */
.ux-shimmer-border {
    position: relative;
}

.ux-shimmer-border::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: linear-gradient(120deg, transparent 30%, rgba(99, 102, 241, 0.2) 50%, transparent 70%);
    background-size: 200% 200%;
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: -1;
    pointer-events: none;
}

.ux-shimmer-border:hover::after {
    opacity: 1;
    animation: ux-shimmer-move 2s linear infinite;
}

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

/* ===== 4. ENHANCED BUTTONS ===== */
.ux-btn-glow {
    position: relative;
    overflow: hidden;
}

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

.ux-btn-glow:hover::after {
    width: 300px;
    height: 300px;
}

/* ===== 5. SKELETON LOADING ===== */
.ux-skeleton {
    background: linear-gradient(90deg,
        rgba(30, 41, 59, 0.5) 0%,
        rgba(51, 65, 85, 0.5) 40%,
        rgba(30, 41, 59, 0.5) 80%
    );
    background-size: 200% 100%;
    animation: ux-skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 8px;
}

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

.ux-skeleton-text { height: 16px; margin-bottom: 10px; width: 100%; }
.ux-skeleton-text.short { width: 60%; }
.ux-skeleton-title { height: 28px; margin-bottom: 16px; width: 80%; }
.ux-skeleton-circle { width: 48px; height: 48px; border-radius: 50%; }
.ux-skeleton-card { height: 160px; }
.ux-skeleton-avatar { width: 64px; height: 64px; border-radius: 16px; }

/* ===== 6. SMOOTH PAGE TRANSITIONS ===== */
.ux-page-enter {
    animation: ux-page-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes ux-page-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 7. TOOLTIP SYSTEM ===== */
[data-ux-tip] {
    position: relative;
    cursor: help;
}

[data-ux-tip]::after {
    content: attr(data-ux-tip);
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: rgba(15, 23, 42, 0.95);
    color: #e2e8f0;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: nowrap;
    max-width: 280px;
    border: 1px solid rgba(99, 102, 241, 0.15);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 10001;
    pointer-events: none;
    font-family: 'Tajawal', sans-serif;
    font-weight: 400;
}

[data-ux-tip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* ===== 8. ANIMATED NUMBER COUNTER ===== */
.ux-counter {
    font-variant-numeric: tabular-nums;
    direction: ltr;
    display: inline-block;
}

/* ===== 9. BREADCRUMB ENHANCEMENT ===== */
.breadcrumb a {
    position: relative;
}

.breadcrumb a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: 0;
    width: 0;
    height: 1.5px;
    background: var(--primary-light, #818cf8);
    transition: width 0.3s ease;
}

.breadcrumb a:hover::after {
    width: 100%;
}

/* ===== 10. SECTION DIVIDERS ===== */
.ux-divider {
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.2), transparent);
    margin: 48px 0;
    position: relative;
}

.ux-divider::after {
    content: '';
    position: absolute;
    top: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 7px;
    height: 7px;
    background: var(--primary, #6366f1);
    border-radius: 50%;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

/* ===== 11. FOCUS INDICATOR ENHANCEMENT ===== */
:focus-visible {
    outline: 2px solid rgba(99, 102, 241, 0.6);
    outline-offset: 3px;
    border-radius: 4px;
    transition: outline-offset 0.15s ease;
}

/* ===== 12. ENHANCED SCROLLBAR ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.3); }
::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.3), rgba(6, 182, 212, 0.2));
    border-radius: 4px;
    border: 1px solid rgba(99, 102, 241, 0.1);
}
::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.5), rgba(6, 182, 212, 0.3));
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.3) rgba(15, 23, 42, 0.3);
}

/* ===== 13. CONTENT BLOCK ELEVATION ===== */
.content-block {
    transition: box-shadow 0.3s ease;
}

.content-block:hover {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ===== 14. LINK HOVER UNDERLINE ===== */
.ux-link-fancy {
    position: relative;
    text-decoration: none;
    color: var(--primary-light, #818cf8);
}

.ux-link-fancy::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary, #6366f1), var(--secondary, #06b6d4));
    transition: width 0.3s ease;
    border-radius: 1px;
}

.ux-link-fancy:hover::after { width: 100%; }

/* ===== 15. NOTIFICATION DOT ===== */
.ux-dot-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    position: relative;
}

.ux-dot-pulse::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    animation: ux-dot-ring 1.5s ease-out infinite;
}

@keyframes ux-dot-ring {
    0% { transform: scale(0.8); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

/* ===== 16. TEXT SELECTION ===== */
::selection {
    background: rgba(99, 102, 241, 0.3);
    color: #f1f5f9;
}

::-moz-selection {
    background: rgba(99, 102, 241, 0.3);
    color: #f1f5f9;
}

/* ===== 17. SMOOTH IMAGE LOADING ===== */
img {
    transition: opacity 0.3s ease;
}

img[loading="lazy"] {
    opacity: 0;
}

img[loading="lazy"].loaded,
img:not([loading="lazy"]) {
    opacity: 1;
}

/* ===== 18. TABLE ENHANCEMENTS ===== */
.comparison-table th {
    position: relative;
    overflow: hidden;
}

.comparison-table th::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-1, linear-gradient(90deg, #6366f1, #06b6d4));
}

.comparison-table tbody tr {
    transition: background 0.2s ease;
}

.comparison-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

/* ===== 19. INPUT ENHANCEMENTS ===== */
input:not([type="radio"]):not([type="checkbox"]),
textarea,
select {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:not([type="radio"]):not([type="checkbox"]):focus,
textarea:focus,
select:focus {
    border-color: rgba(99, 102, 241, 0.4) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
}

/* ===== 20. SECTION FLOATING LABEL ===== */
.content-block > h2,
.tool-page-header h1 {
    position: relative;
}

.content-block > h2 > i {
    transition: transform 0.3s ease, color 0.3s ease;
}

.content-block:hover > h2 > i {
    transform: scale(1.15);
}

/* ========================================
   LIGHT THEME OVERRIDES
   ======================================== */
[data-theme="light"] .ux-back-top {
    background: rgba(99, 102, 241, 0.95);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.25);
}

[data-theme="light"] .ux-glass-card {
    background: rgba(255, 255, 255, 0.6);
    border-color: rgba(226, 232, 240, 0.8);
}

[data-theme="light"] .ux-glass-card:hover {
    border-color: rgba(99, 102, 241, 0.15);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(99, 102, 241, 0.08);
}

[data-theme="light"] .ux-skeleton {
    background: linear-gradient(90deg,
        rgba(226, 232, 240, 0.7) 0%,
        rgba(241, 245, 249, 0.9) 40%,
        rgba(226, 232, 240, 0.7) 80%
    );
    background-size: 200% 100%;
}

[data-theme="light"] [data-ux-tip]::after {
    background: rgba(255, 255, 255, 0.97);
    color: #334155;
    border-color: #e2e8f0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] ::-webkit-scrollbar-track { background: rgba(241, 245, 249, 0.5); }
[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.2), rgba(6, 182, 212, 0.15));
    border-color: rgba(226, 232, 240, 0.5);
}

[data-theme="light"] .ux-divider {
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.12), transparent);
}

[data-theme="light"] .comparison-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.03);
}

[data-theme="light"] ::selection {
    background: rgba(99, 102, 241, 0.2);
    color: #1e293b;
}

[data-theme="light"] * {
    scrollbar-color: rgba(99, 102, 241, 0.2) rgba(241, 245, 249, 0.5);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .ux-back-top {
        bottom: 80px;
        right: 16px;
        width: 40px;
        height: 40px;
        font-size: 0.85rem;
    }

    [data-ux-tip]::after {
        max-width: 200px;
        white-space: normal;
        font-size: 0.72rem;
    }

    .ux-reveal, .ux-reveal-left, .ux-reveal-right {
        transform: translateY(20px);
    }

    .ux-reveal-left, .ux-reveal-right {
        transform: translateY(20px);
    }
}

/* ========================================
   PRINT
   ======================================== */
@media print {
    .ux-back-top,
    .ux-dot-pulse,
    [data-ux-tip]::after {
        display: none !important;
    }

    .ux-reveal, .ux-reveal-left, .ux-reveal-right, .ux-reveal-scale {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .ux-reveal, .ux-reveal-left, .ux-reveal-right, .ux-reveal-scale {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    .ux-back-top {
        transition: opacity 0.1s ease !important;
        transform: none !important;
    }

    .ux-glass-card,
    .ux-glass-card::before,
    .ux-shimmer-border::after,
    .ux-btn-glow::after,
    .ux-skeleton,
    .ux-dot-pulse::after {
        animation: none !important;
        transition: none !important;
    }

    .ux-page-enter { animation: none !important; opacity: 1; }
    ::-webkit-scrollbar-thumb { transition: none; }
}
