/* Tile View Styles for Collection Document Display */

/* Container for tiles */
.tile-container {
    display: none; /* Hidden by default, shown when tile view is active */
    padding: 20px 0;
}

.tile-container.active {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    width: 100%;
    padding: 10px;
}

/* Individual tile card */
.document-tile {
    position: relative;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 0;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: none;
    min-height: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
}

.document-tile:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

/* Document icon in tile */
.tile-icon {
    font-size: 64px;
    margin-bottom: 15px;
    color: #666;
}

.tile-icon i.material-icons {
    font-size: 48px;
    font-family: "Material Icons" !important;
    font-weight: normal;
    font-style: normal;
    display: inline-block;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "liga";
}

/* Document thumbnail in tile - A4 aspect ratio */
.tile-thumbnail {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1.414;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tile-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

/* File type specific icon colors */
.tile-icon.pdf {
    color: #d32f2f;
}
.tile-icon.doc {
    color: #1976d2;
}
.tile-icon.docx {
    color: #1976d2;
}
.tile-icon.xls {
    color: #388e3c;
}
.tile-icon.xlsx {
    color: #388e3c;
}
.tile-icon.ppt {
    color: #f57c00;
}
.tile-icon.pptx {
    color: #f57c00;
}
.tile-icon.txt {
    color: #616161;
}
.tile-icon.image {
    color: #7b1fa2;
}
.tile-icon.video {
    color: #c2185b;
}
.tile-icon.audio {
    color: #0097a7;
}
.tile-icon.archive {
    color: #5d4037;
}
.tile-icon.default {
    color: #757575;
}

/* Document title overlay on tile */
.tile-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    padding: 8px 10px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: break-word;
    background: #9c27b0;
    border-radius: 0 0 4px 4px;
    text-align: left;
}

.tile-title:hover::after {
    content: attr(data-full-title);
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.95);
    color: #fff;
    padding: 10px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
    word-break: break-word;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-bottom: 5px;
    display: -webkit-box;
    -webkit-line-clamp: unset;
    line-clamp: unset;
}

/* Size and date info - hidden, shown in info popup */
.tile-info {
    display: none;
}

/* Info icon button */
.tile-info-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: #9c27b0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    font-size: 16px;
    font-weight: bold;
    font-style: italic;
    font-family: Georgia, serif;
}

.tile-info-icon:hover {
    background: #9c27b0;
    color: white;
    transform: scale(1.1);
    z-index: 1001;
}

/* Metadata popup tooltip */
.tile-metadata {
    position: absolute;
    top: 40px;
    right: 8px;
    width: 280px;
    max-width: 90vw;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 8px;
    padding: 15px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow-y: auto;
    max-height: 400px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border: 1px solid #ddd;
}

/* Show metadata on hover of info icon or metadata itself */
.tile-info-icon:hover ~ .tile-metadata,
.tile-metadata:hover {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Metadata content */
.tile-metadata-content {
    text-align: left;
    font-size: 12px;
}

.metadata-row {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.metadata-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.metadata-label {
    font-weight: 600;
    color: #666;
    margin-right: 5px;
}

.metadata-value {
    color: #333;
    word-break: break-word;
}

/* View toggle button */
.view-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px;
    border: none;
    background: #9c27b0;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s ease;
    font-size: 14px;
}

.view-toggle-btn:hover {
    background: #7b1fa2;
}

.view-toggle-btn i.material-icons {
    font-size: 20px;
}

/* Hide datatable rows when tile view is active, keep pagination */
.tile-view-active .table-responsive table {
    display: none !important;
}

.tile-view-active .dataTables_filter {
    display: none !important;
}

/* Hide the original info and paginate controls in tile view (we show cloned ones at bottom) */
.tile-view-active .table-responsive + .row .dataTables_info,
.tile-view-active .table-responsive + .row .dataTables_paginate,
.tile-view-active
    .dataTables_wrapper
    .row:has(.dataTables_info)
    .dataTables_info,
.tile-view-active
    .dataTables_wrapper
    .row:has(.dataTables_paginate)
    .dataTables_paginate {
    display: none !important;
}

.tile-view-active .card-body > .row .dataTables_info,
.tile-view-active .card-body > .row .dataTables_paginate {
    display: none !important;
}

/* Ensure controls are visible in list view */
body:not(.tile-view-active) .dataTables_length,
body:not(.tile-view-active) .dataTables_info,
body:not(.tile-view-active) .dataTables_paginate {
    display: block !important;
}

/* Show entries dropdown in tile view */
.tile-view-active .dataTables_length {
    text-align: left;
    margin-bottom: 15px;
    padding: 10px 0;
}

/* Ensure length dropdown is at top in list view */
.dataTables_length {
    order: -1;
}

.dataTables_wrapper .row:first-child {
    display: flex;
    align-items: center;
}

.dataTables_wrapper .row:first-child .dataTables_length {
    margin-bottom: 1rem;
}

/* Bottom controls wrapper for tile view */
#tile-bottom-controls {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 10px 0;
    width: 100%;
}

/* Keep default DataTable styling for controls in tile view */
#tile-bottom-controls .dataTables_info {
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
}

#tile-bottom-controls .dataTables_paginate {
    margin: 0 !important;
    padding: 0 !important;
    margin-left: auto !important;
    display: block !important;
}

#tile-bottom-controls .dataTables_paginate .pagination {
    display: flex !important;
}

/* Pagination buttons maintain their original DataTable styling */

/* Loading state for tiles */
.tile-container.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.tile-loading-spinner {
    text-align: center;
}

.tile-loading-spinner img {
    width: 64px;
    height: 64px;
}

/* Approval status badge in tile */
.tile-approval-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    background: #4caf50;
    color: white;
    font-weight: 500;
}

.tile-approval-badge.pending {
    background: #ff9800;
}

.tile-approval-badge.rejected {
    background: #f44336;
}

/* Actions in tile */
.tile-actions {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.document-tile:hover .tile-actions {
    opacity: 1;
}

.tile-action-btn {
    background: #9c27b0;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease;
}

.tile-action-btn:hover {
    background: #7b1fa2;
}

.tile-action-btn i.material-icons {
    font-size: 18px;
}

/* Responsive design */
@media (max-width: 1200px) {
    .tile-container.active {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .tile-container.active {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }

    .document-tile {
        padding: 15px;
        min-height: 180px;
    }

    .tile-icon {
        font-size: 48px;
    }

    .tile-icon i.material-icons {
        font-size: 48px;
    }

    .tile-title {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .tile-container.active {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }

    .document-tile {
        padding: 12px;
        min-height: 150px;
    }

    .tile-icon {
        font-size: 40px;
    }

    .tile-icon i.material-icons {
        font-size: 40px;
    }

    .tile-title {
        font-size: 12px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }

    .tile-metadata {
        font-size: 11px;
    }
}

/* List view title truncation */
#documents tbody td:nth-child(2) {
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#documents tbody td:nth-child(2):hover {
    overflow: visible;
    white-space: normal;
    word-break: break-word;
}

/* Size and Date columns - no wrap, single line */
#documents tbody td {
    vertical-align: top;
}

#documents thead th,
#documents tbody td:nth-last-child(1),
#documents tbody td:nth-last-child(2),
#documents tbody td:nth-last-child(3) {
    white-space: nowrap;
}

/* Empty state */
.tile-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.tile-empty-state i.material-icons {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.tile-empty-state p {
    font-size: 16px;
    margin: 0;
}

/* Pagination info for tile view */
.tile-pagination-info {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 15px;
    color: #666;
    font-size: 14px;
}

#tile-pagination {
    margin-top: 20px;
}
