/**
 * ============================================================================
 * PharmAssist Loading States Styles
 * ============================================================================
 * Location: public_html/styles/loading-states.css
 * 
 * Features:
 * - Multiple spinner animations
 * - Skeleton screen styles with pulse animation
 * - Progress bars
 * - Button loading states
 * - Dark/light theme support
 * 
 * @version 1.0.0
 * @created February 2026
 * ============================================================================
 */

/* ============================================================================
   CSS VARIABLES
   ============================================================================ */

:root {
    --loading-primary: #00d4ff;
    --loading-secondary: #7c3aed;
    --loading-bg: rgba(0, 0, 0, 0.7);
    --skeleton-bg: #1a1a1a;
    --skeleton-shimmer: #2a2a2a;
}

body.light-mode {
    --loading-primary: #3b82f6;
    --loading-secondary: #8b5cf6;
    --loading-bg: rgba(255, 255, 255, 0.9);
    --skeleton-bg: #e5e7eb;
    --skeleton-shimmer: #f3f4f6;
}

/* ============================================================================
   LOADING OVERLAY
   ============================================================================ */

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--loading-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: inherit;
    backdrop-filter: blur(2px);
}

/* ============================================================================
   SPINNER CONTAINERS
   ============================================================================ */

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.loading-spinner-small {
    --spinner-size: 20px;
}

.loading-spinner-medium {
    --spinner-size: 40px;
}

.loading-spinner-large {
    --spinner-size: 60px;
}

.loading-text {
    color: var(--loading-primary);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.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;
}

/* ============================================================================
   DEFAULT SPINNER
   ============================================================================ */

.loading-default {
    width: var(--spinner-size, 40px);
    height: var(--spinner-size, 40px);
    border: 3px solid rgba(0, 212, 255, 0.2);
    border-top-color: var(--loading-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================================================
   DOTS SPINNER
   ============================================================================ */

.loading-dots {
    display: flex;
    gap: 8px;
}

.loading-dot {
    width: calc(var(--spinner-size, 40px) / 3);
    height: calc(var(--spinner-size, 40px) / 3);
    background: var(--loading-primary);
    border-radius: 50%;
    animation: dots-bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes dots-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================================================
   PULSE SPINNER
   ============================================================================ */

.loading-pulse {
    width: var(--spinner-size, 40px);
    height: var(--spinner-size, 40px);
    background: linear-gradient(135deg, var(--loading-primary) 0%, var(--loading-secondary) 100%);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    50% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================================================
   CIRCLE SPINNER
   ============================================================================ */

.loading-circle {
    width: var(--spinner-size, 40px);
    height: var(--spinner-size, 40px);
    position: relative;
}

.loading-circle::before,
.loading-circle::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: circle-spin 1.5s ease-in-out infinite;
}

.loading-circle::before {
    border-top-color: var(--loading-primary);
    animation-delay: -0.45s;
}

.loading-circle::after {
    border-bottom-color: var(--loading-secondary);
}

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

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

.skeleton-container {
    width: 100%;
    animation: skeleton-fade-in 0.3s ease;
}

@keyframes skeleton-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Base skeleton elements */
.skeleton-rect,
.skeleton-circle,
.skeleton-text {
    background: var(--skeleton-bg);
    position: relative;
    overflow: hidden;
}

.skeleton-rect::after,
.skeleton-circle::after,
.skeleton-text::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        var(--skeleton-shimmer),
        transparent
    );
    animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.skeleton-text {
    height: 12px;
    border-radius: 4px;
    margin: 8px 0;
}

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

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

.skeleton-text.skeleton-body {
    height: 12px;
    width: 90%;
}

.skeleton-text.short {
    width: 50%;
}

.skeleton-rect {
    border-radius: 8px;
}

.skeleton-circle {
    border-radius: 50%;
}

/* Card Grid Skeleton */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.skeleton-card {
    background: #141414;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    padding: 16px;
}

body.light-mode .skeleton-card {
    background: #ffffff;
    border-color: #e5e7eb;
}

.skeleton-card-image {
    height: 150px;
    margin-bottom: 12px;
}

/* Table Skeleton */
.skeleton-table {
    width: 100%;
}

.skeleton-table-header,
.skeleton-table-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid #2a2a2a;
}

body.light-mode .skeleton-table-header,
body.light-mode .skeleton-table-row {
    border-bottom-color: #e5e7eb;
}

.skeleton-table-header-cell {
    height: 16px;
}

.skeleton-table-cell {
    height: 12px;
}

/* Form Skeleton */
.skeleton-form {
    max-width: 600px;
}

.skeleton-form-field {
    margin-bottom: 20px;
}

.skeleton-label {
    width: 30%;
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-input {
    height: 40px;
}

/* List Skeleton */
.skeleton-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid #2a2a2a;
}

body.light-mode .skeleton-list-item {
    border-bottom-color: #e5e7eb;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.skeleton-list-content {
    flex: 1;
}

.skeleton-list-title {
    width: 70%;
    height: 14px;
}

.skeleton-list-subtitle {
    width: 50%;
    height: 12px;
}

/* ============================================================================
   BUTTON LOADING STATE
   ============================================================================ */

.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

/* ============================================================================
   PROGRESS BAR
   ============================================================================ */

.progress-container {
    width: 100%;
    margin: 12px 0;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

body.light-mode .progress-bar {
    background: #e5e7eb;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--loading-primary) 0%, var(--loading-secondary) 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: progress-shimmer 1.5s infinite;
}

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

.progress-text {
    text-align: center;
    font-size: 12px;
    color: var(--loading-primary);
    margin-top: 4px;
    font-weight: 500;
}

/* ============================================================================
   FADE OUT ANIMATION
   ============================================================================ */

.loading-fade-out {
    animation: fade-out 0.2s ease forwards;
}

@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 768px) {
    .skeleton-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    .loading-default,
    .loading-dot,
    .loading-pulse,
    .loading-circle::before,
    .loading-circle::after,
    .btn-spinner {
        animation-duration: 3s;
    }

    .skeleton-rect::after,
    .skeleton-circle::after,
    .skeleton-text::after,
    .progress-fill::after {
        animation: none;
    }
}

/* Print styles */
@media print {
    .loading-overlay,
    .loading-spinner,
    .skeleton-container,
    .btn-loading,
    .progress-container {
        display: none !important;
    }
}
