/* ============================================
   Sequal Loan Manager - Utility Classes
   Animation, accessibility, and helper utilities
   ============================================ */

/* ----------------------------------------
   Animations (Keyframes)
   ---------------------------------------- */

/* Fade In */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Fade Out */
@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Slide Up */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide Down */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide In from Left */
@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Slide In from Right */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Scale In */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Shake (for errors) */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-4px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(4px);
    }
}

/* Spin (for loaders) */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Pulse */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Bounce */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

/* Shimmer (for skeleton loading) */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ----------------------------------------
   Animation Utility Classes
   ---------------------------------------- */
.sl-animate-fadeIn {
    animation: fadeIn var(--sl-transition-base);
}

.sl-animate-fadeOut {
    animation: fadeOut var(--sl-transition-base);
}

.sl-animate-slideUp {
    animation: slideUp var(--sl-transition-base);
}

.sl-animate-slideDown {
    animation: slideDown var(--sl-transition-base);
}

.sl-animate-slideInLeft {
    animation: slideInLeft var(--sl-transition-base);
}

.sl-animate-slideInRight {
    animation: slideInRight var(--sl-transition-base);
}

.sl-animate-scaleIn {
    animation: scaleIn var(--sl-transition-base);
}

.sl-animate-shake {
    animation: shake 0.4s ease-in-out;
}

.sl-animate-spin {
    animation: spin 1s linear infinite;
}

.sl-animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

.sl-animate-bounce {
    animation: bounce 0.5s ease infinite;
}

/* ----------------------------------------
   Reduced Motion (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;
    }
}

/* ----------------------------------------
   Accessibility Utilities
   ---------------------------------------- */

/* Screen reader only - visually hidden but accessible */
.sl-sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Focus visible outline (keyboard navigation) */
.sl-focus-visible:focus-visible {
    outline: 2px solid var(--sl-primary-500);
    outline-offset: 2px;
}

/* Skip link (for keyboard users) */
.sl-skip-link {
    position: absolute;
    top: -100%;
    left: var(--sl-space-4);
    z-index: 9999;
    padding: var(--sl-space-3) var(--sl-space-5);
    background-color: var(--sl-primary-500);
    color: var(--sl-text-inverse);
    border-radius: var(--sl-radius-md);
    text-decoration: none;
    font-weight: var(--sl-font-weight-medium);
    transition: top var(--sl-transition-fast);
}

.sl-skip-link:focus {
    top: var(--sl-space-4);
}

/* High contrast focus ring */
@media (prefers-contrast: high) {
    :focus-visible {
        outline: 3px solid currentColor !important;
        outline-offset: 3px !important;
    }
}

/* ----------------------------------------
   Glass Morphism Effects
   ---------------------------------------- */
.sl-glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .sl-glass {
    background: rgba(30, 30, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ----------------------------------------
   Gradient Backgrounds
   ---------------------------------------- */
.sl-gradient-primary {
    background: linear-gradient(135deg, var(--sl-primary-500) 0%, var(--sl-primary-700) 100%);
}

.sl-gradient-sidebar {
    background: linear-gradient(180deg, var(--sl-sidebar-gradient-start) 0%, var(--sl-sidebar-gradient-end) 70%);
}

.sl-gradient-success {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
}

.sl-gradient-danger {
    background: linear-gradient(135deg, #dc3545 0%, #a71d2a 100%);
}

/* ----------------------------------------
   Text Utilities
   ---------------------------------------- */
.sl-text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sl-text-break {
    word-wrap: break-word;
    word-break: break-word;
}

.sl-text-uppercase {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sl-text-capitalize {
    text-transform: capitalize;
}

.sl-text-mono {
    font-family: var(--sl-font-family-mono);
}

/* ----------------------------------------
   Display Utilities
   ---------------------------------------- */
.sl-flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sl-flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sl-flex-start {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.sl-flex-end {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.sl-flex-col {
    display: flex;
    flex-direction: column;
}

.sl-flex-wrap {
    flex-wrap: wrap;
}

.sl-flex-1 {
    flex: 1;
}

.sl-flex-shrink-0 {
    flex-shrink: 0;
}

/* Gap utilities */
.sl-gap-1 { gap: var(--sl-space-1); }
.sl-gap-2 { gap: var(--sl-space-2); }
.sl-gap-3 { gap: var(--sl-space-3); }
.sl-gap-4 { gap: var(--sl-space-4); }
.sl-gap-5 { gap: var(--sl-space-5); }
.sl-gap-6 { gap: var(--sl-space-6); }

/* ----------------------------------------
   Positioning Utilities
   ---------------------------------------- */
.sl-relative { position: relative; }
.sl-absolute { position: absolute; }
.sl-fixed { position: fixed; }
.sl-sticky { position: sticky; }

.sl-inset-0 { inset: 0; }
.sl-top-0 { top: 0; }
.sl-right-0 { right: 0; }
.sl-bottom-0 { bottom: 0; }
.sl-left-0 { left: 0; }

/* ----------------------------------------
   Visibility Utilities
   ---------------------------------------- */
.sl-visible { visibility: visible; }
.sl-invisible { visibility: hidden; }
.sl-hidden { display: none; }

/* Responsive visibility */
@media (max-width: 640px) {
    .sl-hidden-mobile { display: none !important; }
}

@media (min-width: 641px) {
    .sl-hidden-desktop { display: none !important; }
}

@media (max-width: 768px) {
    .sl-hidden-tablet-down { display: none !important; }
}

@media (min-width: 769px) {
    .sl-hidden-tablet-up { display: none !important; }
}

/* ----------------------------------------
   Cursor Utilities
   ---------------------------------------- */
.sl-cursor-pointer { cursor: pointer; }
.sl-cursor-default { cursor: default; }
.sl-cursor-not-allowed { cursor: not-allowed; }
.sl-cursor-grab { cursor: grab; }
.sl-cursor-grabbing { cursor: grabbing; }

/* ----------------------------------------
   Overflow Utilities
   ---------------------------------------- */
.sl-overflow-auto { overflow: auto; }
.sl-overflow-hidden { overflow: hidden; }
.sl-overflow-scroll { overflow: scroll; }
.sl-overflow-x-auto { overflow-x: auto; }
.sl-overflow-y-auto { overflow-y: auto; }

/* Custom scrollbar styling */
.sl-scrollbar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.sl-scrollbar::-webkit-scrollbar-track {
    background: var(--sl-bg-muted);
    border-radius: var(--sl-radius-full);
}

.sl-scrollbar::-webkit-scrollbar-thumb {
    background: var(--sl-gray-400);
    border-radius: var(--sl-radius-full);
}

.sl-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--sl-gray-500);
}

/* ----------------------------------------
   Border Utilities
   ---------------------------------------- */
.sl-border { border: 1px solid var(--sl-border-color); }
.sl-border-t { border-top: 1px solid var(--sl-border-color); }
.sl-border-r { border-right: 1px solid var(--sl-border-color); }
.sl-border-b { border-bottom: 1px solid var(--sl-border-color); }
.sl-border-l { border-left: 1px solid var(--sl-border-color); }
.sl-border-0 { border: 0; }

.sl-rounded { border-radius: var(--sl-radius-base); }
.sl-rounded-md { border-radius: var(--sl-radius-md); }
.sl-rounded-lg { border-radius: var(--sl-radius-lg); }
.sl-rounded-xl { border-radius: var(--sl-radius-xl); }
.sl-rounded-full { border-radius: var(--sl-radius-full); }
.sl-rounded-0 { border-radius: 0; }

/* ----------------------------------------
   Shadow Utilities
   ---------------------------------------- */
.sl-shadow-none { box-shadow: none; }
.sl-shadow-sm { box-shadow: var(--sl-shadow-sm); }
.sl-shadow { box-shadow: var(--sl-shadow-base); }
.sl-shadow-md { box-shadow: var(--sl-shadow-md); }
.sl-shadow-lg { box-shadow: var(--sl-shadow-lg); }
.sl-shadow-xl { box-shadow: var(--sl-shadow-xl); }

/* ----------------------------------------
   Z-Index Utilities
   ---------------------------------------- */
.sl-z-0 { z-index: 0; }
.sl-z-10 { z-index: 10; }
.sl-z-20 { z-index: 20; }
.sl-z-30 { z-index: 30; }
.sl-z-40 { z-index: 40; }
.sl-z-50 { z-index: 50; }
.sl-z-dropdown { z-index: var(--sl-z-dropdown); }
.sl-z-modal { z-index: var(--sl-z-modal); }

/* ----------------------------------------
   Print Styles
   ---------------------------------------- */
@media print {
    /* Hide non-printable elements */
    .sl-no-print,
    .sidebar,
    .top-row,
    .sl-btn,
    button:not(.sl-print-btn) {
        display: none !important;
    }

    /* Reset backgrounds and colors */
    * {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* Ensure links are visible */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        font-weight: normal;
    }

    /* Page breaks */
    .sl-page-break-before { page-break-before: always; }
    .sl-page-break-after { page-break-after: always; }
    .sl-avoid-break { page-break-inside: avoid; }

    /* Full width content */
    .page,
    main,
    article {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* ----------------------------------------
   Transition Utilities
   ---------------------------------------- */
.sl-transition {
    transition-property: color, background-color, border-color, box-shadow, transform, opacity;
    transition-timing-function: ease;
    transition-duration: var(--sl-transition-base);
}

.sl-transition-fast {
    transition-duration: var(--sl-transition-fast);
}

.sl-transition-slow {
    transition-duration: var(--sl-transition-slow);
}

.sl-transition-none {
    transition: none;
}

/* ----------------------------------------
   Interactive States
   ---------------------------------------- */
.sl-interactive {
    transition: all var(--sl-transition-fast);
}

.sl-interactive:hover {
    transform: translateY(-1px);
    box-shadow: var(--sl-shadow-md);
}

.sl-interactive:active {
    transform: translateY(0);
    box-shadow: var(--sl-shadow-sm);
}

/* Clickable area expansion */
.sl-click-area {
    position: relative;
}

.sl-click-area::before {
    content: "";
    position: absolute;
    top: -8px;
    right: -8px;
    bottom: -8px;
    left: -8px;
}

/* ----------------------------------------
   Selection Color
   ---------------------------------------- */
::selection {
    background-color: var(--sl-primary-100);
    color: var(--sl-primary-900);
}

[data-theme="dark"] ::selection {
    background-color: var(--sl-primary-700);
    color: var(--sl-text-inverse);
}
