/**
 * ==========================================================================
 * CAMDEMICS HIGH-PERFORMANCE SKELETON LOADING ENGINE
 * ==========================================================================
 * Hardware-accelerated shimmering skeleton screens for slow internet connections.
 * Supports:
 *  1. Bootstrap Tables (auto-adapts to column widths & row counts)
 *  2. Student & Applicant Grid Cards
 *  3. Dashboard KPI Stat Cards
 *  4. Form / Modal Dynamic Loaders
 *  5. Full Dark Mode & Custom Color Theme Integration
 * ==========================================================================
 */

/* ── Base Shimmer Keyframe ───────────────────────────────────────────── */
@keyframes skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.45;
    }
}

/* ── Shimmer Color Tokens (Light Mode Default) ────────────────────────── */
:root {
    --skeleton-base: #f1f5f9;
    --skeleton-highlight: #ffffff;
    --skeleton-shimmer-gradient: linear-gradient(
        90deg,
        rgba(241, 245, 249, 0.85) 0%,
        rgba(255, 255, 255, 0.95) 50%,
        rgba(241, 245, 249, 0.85) 100%
    );
    --skeleton-border: rgba(226, 232, 240, 0.7);
    --skeleton-card-bg: #ffffff;
}

/* ── Shimmer Color Tokens (Dark Mode) ─────────────────────────────────── */
html[data-theme="dark"],
html.dark-theme,
[data-theme="dark"] {
    --skeleton-base: #1e293b;
    --skeleton-highlight: #334155;
    --skeleton-shimmer-gradient: linear-gradient(
        90deg,
        rgba(30, 41, 59, 0.9) 0%,
        rgba(51, 65, 85, 0.95) 50%,
        rgba(30, 41, 59, 0.9) 100%
    );
    --skeleton-border: rgba(51, 65, 85, 0.5);
    --skeleton-card-bg: #162032;
}

/* ── Core Atomic Skeleton Class ───────────────────────────────────────── */
.skeleton-shimmer,
.skeleton-box,
.skeleton-text,
.skeleton-circle,
.skeleton-pill,
.skeleton-btn,
.skeleton-chk {
    background: var(--skeleton-shimmer-gradient);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    border-radius: 6px;
    display: inline-block;
    vertical-align: middle;
    pointer-events: none;
    user-select: none;
}

/* ── Text Lines ───────────────────────────────────────────────────────── */
.skeleton-text {
    height: 12px;
    margin-bottom: 6px;
    border-radius: 4px;
    width: 100%;
}
.skeleton-text:last-child {
    margin-bottom: 0;
}
.skeleton-text.w-25 { width: 25% !important; }
.skeleton-text.w-35 { width: 35% !important; }
.skeleton-text.w-50 { width: 50% !important; }
.skeleton-text.w-65 { width: 65% !important; }
.skeleton-text.w-75 { width: 75% !important; }
.skeleton-text.w-85 { width: 85% !important; }
.skeleton-text.w-90 { width: 90% !important; }
.skeleton-text.w-100 { width: 100% !important; }

.skeleton-text.text-sm { height: 10px; }
.skeleton-text.text-md { height: 14px; }
.skeleton-text.text-lg { height: 18px; border-radius: 6px; }
.skeleton-text.text-title { height: 22px; border-radius: 6px; }

/* ── Shapes & Components ─────────────────────────────────────────────── */
.skeleton-circle {
    border-radius: 50% !important;
    flex-shrink: 0;
}
.skeleton-circle.size-24 { width: 24px; height: 24px; }
.skeleton-circle.size-32 { width: 32px; height: 32px; }
.skeleton-circle.size-40 { width: 40px; height: 40px; }
.skeleton-circle.size-48 { width: 48px; height: 48px; }
.skeleton-circle.size-64 { width: 64px; height: 64px; }

.skeleton-avatar-square {
    width: 106px;
    height: 106px;
    border-radius: 22px;
    margin: 0 auto;
}

.skeleton-pill {
    height: 22px;
    width: 68px;
    border-radius: 20px;
}

.skeleton-btn {
    height: 32px;
    width: 80px;
    border-radius: 8px;
}

.skeleton-chk {
    width: 18px;
    height: 18px;
    border-radius: 5px;
}

/* ── Universal Slow Internet Notice Indicator ────────────────────────── */
.slow-connection-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #f8fafc;
    padding: 9px 18px;
    border-radius: 30px;
    font-size: 12.5px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 50000;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    opacity: 0;
    pointer-events: none !important;
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.slow-connection-banner.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: none !important;
}
.slow-connection-banner i.pulse-icon {
    color: #f59e0b;
    animation: skeleton-pulse 1.2s infinite;
}

/* Guarantee banner never overlays any modal, dialog, or popup */
body.modal-open .slow-connection-banner,
body.has-cbui-popup .slow-connection-banner,
.modal.show ~ .slow-connection-banner,
.modal.show .slow-connection-banner,
#camdemics-slow-network-banner:not(.show) {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -999999 !important;
}

/* ══════════════════════════════════════════════════════════════════════
   1. BOOTSTRAP TABLE SKELETON LOADER OVERRIDES
   ══════════════════════════════════════════════════════════════════════ */
.bootstrap-table .fixed-table-container .fixed-table-body .fixed-table-loading {
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(3px) !important;
    -webkit-backdrop-filter: blur(3px) !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 280px;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 99 !important;
    transition: opacity 0.25s ease, visibility 0.25s ease !important;
    overflow: hidden !important;
}

[data-theme="dark"] .bootstrap-table .fixed-table-container .fixed-table-body .fixed-table-loading {
    background: rgba(15, 23, 42, 0.96) !important;
}

.bootstrap-table .fixed-table-container .fixed-table-body .fixed-table-loading:not(.open) {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    z-index: -1 !important;
}

.bootstrap-table .fixed-table-container .fixed-table-body .fixed-table-loading.open {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    z-index: 99 !important;
}

/* Inner Table Skeleton Container */
.skeleton-table-wrapper {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
}

.skeleton-table-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    background: rgba(var(--primary-rgb, 0, 115, 59), 0.05);
    border-bottom: 1px solid var(--skeleton-border);
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color, #00733B);
}
[data-theme="dark"] .skeleton-table-notice {
    background: rgba(var(--primary-rgb, 0, 115, 59), 0.12);
    color: #86efac;
}

.skeleton-table-body {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 6px 12px;
}

.skeleton-table-row {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--skeleton-border);
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.skeleton-table-row:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}
[data-theme="dark"] .skeleton-table-row:nth-child(even) {
    background: rgba(30, 41, 59, 0.3);
}

.skeleton-table-cell {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}
.skeleton-table-cell.cell-chk {
    flex: 0 0 28px;
    justify-content: center;
}
.skeleton-table-cell.cell-no {
    flex: 0 0 36px;
}
.skeleton-table-cell.cell-avatar {
    flex: 0 0 46px;
    justify-content: center;
}
.skeleton-table-cell.cell-matricule {
    flex: 0 0 110px;
}
.skeleton-table-cell.cell-name {
    flex: 2;
    min-width: 130px;
}
.skeleton-table-cell.cell-status {
    flex: 0 0 100px;
}
.skeleton-table-cell.cell-action {
    flex: 0 0 100px;
    justify-content: flex-end;
}

/* ══════════════════════════════════════════════════════════════════════
   2. STUDENT & APPLICANT CARD SKELETON
   ══════════════════════════════════════════════════════════════════════ */
.skeleton-card-item {
    background: var(--skeleton-card-bg);
    border: 1px solid var(--skeleton-border);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0,0,0,0.03);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.skeleton-card-banner {
    height: 72px;
    background: var(--skeleton-shimmer-gradient);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.skeleton-card-profile {
    text-align: center;
    margin-top: -46px;
    padding: 0 16px 12px;
    position: relative;
}

.skeleton-card-content {
    padding: 14px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-top: 1px solid var(--skeleton-border);
}

.skeleton-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--skeleton-border);
    margin-top: 12px;
}

/* ══════════════════════════════════════════════════════════════════════
   3. KPI & METRIC STATS SKELETON
   ══════════════════════════════════════════════════════════════════════ */
.skeleton-kpi-card {
    background: var(--skeleton-card-bg);
    border: 1px solid var(--skeleton-border);
    border-radius: 16px;
    padding: 16px 18px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.035);
    height: 100%;
}

/* ══════════════════════════════════════════════════════════════════════
   4. MODAL / FORM SKELETON
   ══════════════════════════════════════════════════════════════════════ */
.skeleton-modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

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

.skeleton-form-input {
    height: 42px;
    width: 100%;
    border-radius: 10px;
    background: var(--skeleton-shimmer-gradient);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}

/* ── Smooth Fade Transition on Data Influx ───────────────────────────── */
.fade-in-content {
    animation: skeleton-content-reveal 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes skeleton-content-reveal {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ══════════════════════════════════════════════════════════════════════
   GLOBAL BOOTSTRAP TABLE CONTROLS & VERTICAL/HORIZONTAL SCROLL
   ══════════════════════════════════════════════════════════════════════ */
.bootstrap-table {
    width: 100%;
    position: relative;
}

.bootstrap-table .fixed-table-container {
    position: relative;
    clear: both;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #ffffff;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

[data-theme="dark"] .bootstrap-table .fixed-table-container {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.08);
}

/* Vertical and horizontal scroll for table body */
.bootstrap-table .fixed-table-container .fixed-table-body {
    overflow-x: auto !important;
    overflow-y: auto !important;
    max-height: 70vh;
    min-height: 120px;
    -webkit-overflow-scrolling: touch !important;
}

/* Ensure sticky table header during vertical scroll */
.bootstrap-table .fixed-table-container thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .bootstrap-table .fixed-table-container thead th {
    background: #0f172a;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Toolbar Controls Visibility & Alignment */
.bootstrap-table .fixed-table-toolbar {
    margin-bottom: 8px;
    position: relative;
    z-index: 5;
}

.bootstrap-table .fixed-table-toolbar .bs-bars {
    margin-top: 4px;
    margin-bottom: 4px;
}

.bootstrap-table .fixed-table-toolbar .columns {
    margin-top: 4px;
    margin-bottom: 4px;
    z-index: 100;
}

.bootstrap-table .fixed-table-toolbar .columns .dropdown-menu {
    z-index: 1050 !important;
    max-height: 380px;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
}

/* Table Actions & Buttons wrap cleanly */
.bootstrap-table table td .btn-action,
.bootstrap-table table td .btn-sm,
.bootstrap-table table td .btn-xs {
    margin: 1px 2px;
}

/* Smooth Touch & Desktop Scrollbars */
.bootstrap-table .fixed-table-container .fixed-table-body::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.bootstrap-table .fixed-table-container .fixed-table-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
}

.bootstrap-table .fixed-table-container .fixed-table-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.bootstrap-table .fixed-table-container .fixed-table-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

