/* ══════════════════════════════════════════════════════════════════════
   HMI LIMS — Branded Loading & Micro-Interaction System
   ══════════════════════════════════════════════════════════════════════
   Uses the Hybrinomics logo symbol (microscope + DNA circle) as the
   base for all loading, success, and processing animations.
   ══════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --hmi-teal: #00BCD4;
    --hmi-teal-dark: #00838F;
    --hmi-indigo: #6366f1;
    --hmi-indigo-dark: #4338ca;
    --hmi-white: #ffffff;
    --hmi-loader-size: 64px;
    --hmi-loader-size-sm: 28px;
    --hmi-loader-size-xs: 18px;
}

/* ══════════════════════════════════════════════════════════════
   1. FULL-PAGE LOADER — replaces the old loading.gif overlay
   ══════════════════════════════════════════════════════════════ */
#loading.loader {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 14px;
}
#loading.loader.show,
#loading.loader[style*="display: block"],
#loading.loader[style*="display:block"] {
    display: flex !important;
}

/* Hide the old GIF image */
#loading #loading-image {
    display: none !important;
}

/* The branded loader element */
.hmi-loader {
    position: relative;
    width: var(--hmi-loader-size);
    height: var(--hmi-loader-size);
}

/* Outer spinning ring — teal gradient */
.hmi-loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--hmi-teal);
    border-right-color: var(--hmi-teal-dark);
    animation: hmi-spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
}

/* Inner counter-spinning ring — indigo */
.hmi-loader-ring-inner {
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    border-bottom-color: var(--hmi-indigo);
    border-left-color: rgba(99, 102, 241, 0.4);
    animation: hmi-spin-reverse 0.8s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
}

/* Center logo symbol — microscope SVG */
.hmi-loader-symbol {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: hmi-pulse 2s ease-in-out infinite;
}
.hmi-loader-symbol svg {
    width: 55%;
    height: 55%;
}

/* DNA orbit dots */
.hmi-loader-dot {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--hmi-teal);
}
.hmi-loader-dot:nth-child(1) {
    animation: hmi-orbit 1.6s linear infinite;
    top: 0; left: 50%; transform-origin: 0 32px;
}
.hmi-loader-dot:nth-child(2) {
    animation: hmi-orbit 1.6s linear infinite 0.8s;
    top: 0; left: 50%; transform-origin: 0 32px;
    background: var(--hmi-indigo);
}

/* Loading text beneath the spinner */
.hmi-loader-text {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    animation: hmi-text-pulse 2s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════════════
   2. INLINE SPINNER — for buttons, AJAX, form submits
   ══════════════════════════════════════════════════════════════ */

/* Replaces fa-spinner fa-spin everywhere */
.hmi-spin {
    display: inline-block;
    width: var(--hmi-loader-size-sm);
    height: var(--hmi-loader-size-sm);
    position: relative;
    vertical-align: middle;
}
.hmi-spin::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2.5px solid rgba(0, 188, 212, 0.2);
    border-top-color: var(--hmi-teal);
    animation: hmi-spin 0.7s linear infinite;
}
.hmi-spin::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-bottom-color: var(--hmi-indigo);
    animation: hmi-spin-reverse 0.6s linear infinite;
}

/* Extra small variant — for inside text/buttons */
.hmi-spin-xs {
    width: var(--hmi-loader-size-xs);
    height: var(--hmi-loader-size-xs);
}
.hmi-spin-xs::before {
    border-width: 2px;
}
.hmi-spin-xs::after {
    inset: 3px;
    border-width: 1.5px;
}

/* White variant — for dark backgrounds / buttons */
.hmi-spin-white::before {
    border-color: rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
}
.hmi-spin-white::after {
    border-bottom-color: rgba(255, 255, 255, 0.7);
}

/* ══════════════════════════════════════════════════════════════
   3. SUCCESS TICK — animated checkmark after actions
   ══════════════════════════════════════════════════════════════ */
.hmi-success {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    position: relative;
    vertical-align: middle;
}

/* Circle fills in */
.hmi-success-circle {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hmi-teal), var(--hmi-teal-dark));
    animation: hmi-circle-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Checkmark draws in */
.hmi-success-check {
    width: 14px;
    height: 14px;
    stroke: white;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    stroke-dasharray: 20;
    stroke-dashoffset: 20;
    animation: hmi-check-draw 0.35s ease 0.25s forwards;
}

/* Small success — for inline use */
.hmi-success-sm {
    width: 18px;
    height: 18px;
}
.hmi-success-sm .hmi-success-check {
    width: 10px;
    height: 10px;
    stroke-width: 2;
}

/* ══════════════════════════════════════════════════════════════
   4. SENT / DELIVERED TICKS — for chat & messages
   ══════════════════════════════════════════════════════════════ */
.hmi-msg-status {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    vertical-align: middle;
    margin-left: 4px;
}

/* Single tick — sent */
.hmi-tick {
    width: 14px;
    height: 14px;
    stroke: var(--hmi-teal);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    stroke-dasharray: 12;
    stroke-dashoffset: 12;
    animation: hmi-tick-draw 0.3s ease forwards;
}
.hmi-tick-pending {
    stroke: #94a3b8;
}
.hmi-tick-read {
    stroke: var(--hmi-teal);
}

/* Double tick — delivered */
.hmi-msg-status .hmi-tick:nth-child(2) {
    margin-left: -8px;
    animation-delay: 0.15s;
}

/* Sending dots */
.hmi-sending {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    vertical-align: middle;
}
.hmi-sending-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--hmi-teal);
    animation: hmi-sending-bounce 1.2s ease-in-out infinite;
}
.hmi-sending-dot:nth-child(2) { animation-delay: 0.15s; }
.hmi-sending-dot:nth-child(3) { animation-delay: 0.3s; }

/* ══════════════════════════════════════════════════════════════
   5. OVERLAY SPINNER — replaces .lims-loading-overlay
   ══════════════════════════════════════════════════════════════ */
.hmi-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

.hmi-overlay .hmi-spin {
    width: 36px;
    height: 36px;
}

/* ══════════════════════════════════════════════════════════════
   6. SKELETON SHIMMER — branded version
   ══════════════════════════════════════════════════════════════ */
.hmi-skeleton {
    background: linear-gradient(90deg,
        #f1f5f9 25%,
        #e8ecf4 37%,
        #f1f5f9 63%
    );
    background-size: 200% 100%;
    animation: hmi-shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
}

/* ══════════════════════════════════════════════════════════════
   7. PROGRESS RING — for file uploads, long operations
   ══════════════════════════════════════════════════════════════ */
.hmi-progress-ring {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.hmi-progress-ring svg {
    transform: rotate(-90deg);
}
.hmi-progress-ring-track {
    stroke: #e2e8f0;
    fill: none;
}
.hmi-progress-ring-fill {
    stroke: var(--hmi-teal);
    fill: none;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.35s ease;
}
.hmi-progress-ring-text {
    position: absolute;
    font-size: 11px;
    font-weight: 700;
    color: var(--hmi-teal-dark);
    font-family: 'Inter', sans-serif;
}

/* ══════════════════════════════════════════════════════════════
   8. BUTTON LOADING STATE
   ══════════════════════════════════════════════════════════════ */
.btn-hmi-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.85;
}
.btn-hmi-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    right: 10px;
    margin-top: -8px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    animation: hmi-spin 0.6s linear infinite;
}

/* ══════════════════════════════════════════════════════════════
   KEYFRAME ANIMATIONS
   ══════════════════════════════════════════════════════════════ */

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

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

@keyframes hmi-pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
}

@keyframes hmi-text-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

@keyframes hmi-orbit {
    to { transform: rotate(360deg); }
}

@keyframes hmi-circle-pop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes hmi-check-draw {
    to { stroke-dashoffset: 0; }
}

@keyframes hmi-tick-draw {
    to { stroke-dashoffset: 0; }
}

@keyframes hmi-sending-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

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

/* ══════════════════════════════════════════════════════════════
   SWAL OVERRIDE — brand the SweetAlert2 loading spinner
   ══════════════════════════════════════════════════════════════ */
.swal2-popup .swal2-loading .swal2-styled {
    border-color: var(--hmi-teal) !important;
    border-right-color: transparent !important;
}
.swal2-popup .swal2-icon.swal2-success .swal2-success-ring {
    border-color: var(--hmi-teal) !important;
}
.swal2-popup .swal2-icon.swal2-success [class^='swal2-success-line'] {
    background-color: var(--hmi-teal) !important;
}

/* ══════════════════════════════════════════════════════════════
   DARK MODE SUPPORT
   ══════════════════════════════════════════════════════════════ */
[data-theme="dark"] #loading.loader,
.dark-mode #loading.loader {
    background: rgba(15, 23, 42, 0.88);
}
[data-theme="dark"] .hmi-loader-text,
.dark-mode .hmi-loader-text {
    color: #94a3b8;
}
[data-theme="dark"] .hmi-overlay,
.dark-mode .hmi-overlay {
    background: rgba(15, 23, 42, 0.8);
}
[data-theme="dark"] .hmi-skeleton,
.dark-mode .hmi-skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 37%, #1e293b 63%);
    background-size: 200% 100%;
}
