/**
 * Skeleton Loader Styles
 * Provides loading placeholder animations for better perceived performance
 * Brew Haha Coffeehouse - CafeMS
 */

/* ==========================================================================
   Base Skeleton Styles
   ========================================================================== */

.skeleton {
    position: relative;
    overflow: hidden;
    background-color: #e9ecef;
    border-radius: 4px;
}

.skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%
    );
    animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ==========================================================================
   Skeleton Element Types
   ========================================================================== */

/* Text skeleton */
.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
}

.skeleton-text.skeleton-text-sm {
    height: 0.75em;
}

.skeleton-text.skeleton-text-lg {
    height: 1.5em;
}

/* Title skeleton */
.skeleton-title {
    height: 1.75em;
    width: 60%;
    margin-bottom: 1em;
}

/* Paragraph skeleton */
.skeleton-paragraph {
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}

.skeleton-paragraph .skeleton-text:last-child {
    width: 70%;
}

/* Button skeleton */
.skeleton-button {
    height: 38px;
    width: 100px;
    border-radius: 4px;
}

.skeleton-button.skeleton-button-sm {
    height: 31px;
    width: 80px;
}

.skeleton-button.skeleton-button-lg {
    height: 48px;
    width: 120px;
}

/* Image/Avatar skeleton */
.skeleton-image {
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-avatar.skeleton-avatar-sm {
    width: 32px;
    height: 32px;
}

.skeleton-avatar.skeleton-avatar-lg {
    width: 64px;
    height: 64px;
}

/* Card skeleton */
.skeleton-card {
    padding: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
}

.skeleton-card .skeleton-image {
    margin-bottom: 1rem;
    border-radius: 4px;
}

/* Input skeleton */
.skeleton-input {
    height: 38px;
    border-radius: 4px;
}

/* ==========================================================================
   DataTable Skeleton
   ========================================================================== */

.skeleton-table {
    width: 100%;
    border-collapse: collapse;
}

.skeleton-table-header {
    display: flex;
    padding: 12px 16px;
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    gap: 16px;
}

.skeleton-table-header .skeleton-cell {
    height: 1.25em;
}

.skeleton-table-row {
    display: flex;
    padding: 12px 16px;
    border-bottom: 1px solid #dee2e6;
    gap: 16px;
    align-items: center;
}

.skeleton-table-row:nth-child(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

.skeleton-cell {
    flex: 1;
    height: 1em;
    border-radius: 4px;
}

.skeleton-cell-sm {
    flex: 0.5;
}

.skeleton-cell-lg {
    flex: 2;
}

.skeleton-cell-action {
    flex: 0 0 150px;
    display: flex;
    gap: 8px;
}

.skeleton-cell-action .skeleton-button {
    flex: 1;
}

/* DataTable controls skeleton */
.skeleton-datatable-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.skeleton-datatable-length {
    width: 200px;
    height: 38px;
}

.skeleton-datatable-search {
    width: 250px;
    height: 38px;
}

.skeleton-datatable-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding: 0.5rem 0;
}

.skeleton-datatable-info {
    width: 200px;
    height: 1em;
}

.skeleton-datatable-pages {
    display: flex;
    gap: 4px;
}

.skeleton-datatable-page {
    width: 38px;
    height: 38px;
    border-radius: 4px;
}

/* ==========================================================================
   Form Skeleton
   ========================================================================== */

.skeleton-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.skeleton-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.skeleton-form-group .skeleton-label {
    width: 30%;
    height: 1em;
}

.skeleton-form-row {
    display: flex;
    gap: 1rem;
}

.skeleton-form-row .skeleton-form-group {
    flex: 1;
}

/* ==========================================================================
   Content Placeholders
   ========================================================================== */

.skeleton-content-block {
    padding: 1.5rem;
    background: #fff;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.skeleton-header-block {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.skeleton-header-block .skeleton-title {
    width: 40%;
    margin-bottom: 0;
}

.skeleton-header-block .skeleton-actions {
    display: flex;
    gap: 0.5rem;
}

/* ==========================================================================
   Page Loading Overlay
   ========================================================================== */

.skeleton-page-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.skeleton-page-loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

.skeleton-page-loader .loader-content {
    text-align: center;
}

.skeleton-page-loader .loader-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e9ecef;
    border-top-color: #6F4E37;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.skeleton-page-loader .loader-text {
    color: #6F4E37;
    font-size: 1rem;
    font-weight: 500;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   Lazy Load Image Styles
   ========================================================================== */

.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.lazy-image.loaded {
    opacity: 1;
}

.lazy-image-wrapper {
    position: relative;
    overflow: hidden;
    background-color: #e9ecef;
}

.lazy-image-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%
    );
    animation: skeleton-shimmer 1.5s infinite;
    z-index: 1;
}

.lazy-image-wrapper.loaded::before {
    display: none;
}

/* Low quality image placeholder */
.lqip {
    filter: blur(10px);
    transform: scale(1.1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

.lqip.loaded {
    filter: blur(0);
    transform: scale(1);
}

/* ==========================================================================
   Progressive Loading States
   ========================================================================== */

.content-loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.content-loading .loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-dots {
    display: flex;
    gap: 8px;
}

.loading-dots .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #6F4E37;
    animation: loading-dots 1.4s infinite ease-in-out both;
}

.loading-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-dots {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 768px) {
    .skeleton-datatable-controls {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .skeleton-datatable-length,
    .skeleton-datatable-search {
        width: 100%;
    }

    .skeleton-table-row {
        flex-wrap: wrap;
    }

    .skeleton-cell-action {
        flex: 1 1 100%;
        margin-top: 0.5rem;
    }

    .skeleton-form-row {
        flex-direction: column;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.skeleton-w-25 { width: 25%; }
.skeleton-w-50 { width: 50%; }
.skeleton-w-75 { width: 75%; }
.skeleton-w-100 { width: 100%; }

.skeleton-mb-0 { margin-bottom: 0; }
.skeleton-mb-1 { margin-bottom: 0.25rem; }
.skeleton-mb-2 { margin-bottom: 0.5rem; }
.skeleton-mb-3 { margin-bottom: 1rem; }
.skeleton-mb-4 { margin-bottom: 1.5rem; }

/* Hide skeleton when content is loaded */
.skeleton-container.loaded .skeleton,
.skeleton-container.loaded .skeleton-table-row,
.skeleton-container.loaded .skeleton-table-header {
    display: none;
}

.skeleton-container .real-content {
    display: none;
}

.skeleton-container.loaded .real-content {
    display: block;
}

/* ==========================================================================
   DataTable Full Width Styles
   ========================================================================== */

/* Ensure DataTables take full width of container */
#dataTable,
.dataTable,
table.dataTable {
    width: 100% !important;
}

/* DataTable wrapper should also be full width */
.dataTables_wrapper {
    width: 100% !important;
}

/* Fix table layout for proper column distribution */
table.dataTable {
    table-layout: auto !important;
}

/* Ensure the table container doesn't constrain width */
.dataTables_scroll,
.dataTables_scrollHead,
.dataTables_scrollBody {
    width: 100% !important;
}

/* Make sure skeleton table also takes full width */
.skeleton-table,
#tableSkeleton {
    width: 100% !important;
}

/* Portal-specific DataTable fixes */
.app-main__inner .table,
.app-main__inner .dataTable,
.app-main__inner #dataTable {
    width: 100% !important;
    max-width: 100% !important;
}

/* Responsive table container */
.table-responsive,
.dataTables_wrapper {
    overflow-x: auto;
    width: 100%;
}

/* Card body containing tables should not constrain */
.card-body .dataTables_wrapper,
.card-body .table {
    width: 100% !important;
}

/* Remove any max-width constraints on table cells */
table.dataTable td,
table.dataTable th {
    white-space: nowrap;
}

/* Allow text wrapping for specific columns if needed */
table.dataTable td.wrap-text,
table.dataTable th.wrap-text {
    white-space: normal;
    word-wrap: break-word;
}

/* Ensure action column has proper width */
table.dataTable td:last-child,
table.dataTable th:last-child {
    white-space: nowrap;
    min-width: 150px;
}
