/**
 * Topscore Extra - Document Widget CSS
 * Frontend styles for document viewer
 */

/* Wrapper */
.topscore-doc-wrapper {
    display: flex;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    position: relative; /* For search absolute positioning */
    transition: all 0.3s ease;
}

/* Helper Class for Search */
.topscore-doc-tab.hidden, 
.topscore-doc-accordion-item.hidden {
    display: none !important;
}

.topscore-doc-wrapper.layout-tabs-top {
    flex-direction: column;
}

.topscore-doc-wrapper.layout-tabs-right {
    flex-direction: row-reverse;
}

.topscore-doc-wrapper.layout-accordion {
    flex-direction: column;
    border: none;
}

/* Search */
/* Search */
.topscore-doc-search-wrapper {
    position: relative;
    width: 100%;
    z-index: 1;
    margin-bottom: 15px;
    background: transparent;
    padding: 0;
    border: none;
}

/* External Search (Standalone) */
.topscore-doc-search-wrapper.external-search {
    display: block;
}

.topscore-doc-search {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 6px 10px;
    transition: all 0.2s ease;
    max-width: 300px; /* Optional: limit width if desired, or keep 100% */
}

.topscore-doc-search:focus-within {
    border-color: #0073aa;
    box-shadow: 0 0 0 1px #0073aa;
}

.topscore-doc-search .dashicons {
    color: #999;
    font-size: 16px;
    width: 16px;
    height: 16px;
}

.topscore-doc-search-input {
    border: none !important;
    background: transparent !important;
    padding: 4px 8px !important;
    margin: 0 !important;
    width: 100%;
    font-size: 13px !important;
    outline: none !important;
    box-shadow: none !important;
    height: 28px !important;
    min-height: unset !important;
}

.topscore-doc-search-clear {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    color: #999;
    display: none;
}

.topscore-doc-search-clear:hover {
    color: #d63638;
}

/* Tabs Container */
.topscore-doc-tabs-content-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
}

.topscore-doc-wrapper.layout-tabs-right .topscore-doc-tabs-content-wrapper {
    flex-direction: row-reverse;
}

.topscore-doc-wrapper.layout-tabs-top .topscore-doc-tabs-content-wrapper {
    flex-direction: column;
}

.topscore-doc-tabs {
    width: 25%;
    background: #f5f5f5;
    border-right: 1px solid #e0e0e0;
    overflow-y: auto;
    max-height: 700px;
    /* transition: width 0.3s ease; */
}

/* No offset needed for external search */
.topscore-doc-tabs[role="tablist"] {
    padding-top: 0; 
}

.topscore-doc-wrapper.layout-tabs-right .topscore-doc-tabs {
    border-right: none;
    border-left: 1px solid #e0e0e0;
}

.topscore-doc-tabs.horizontal {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
    max-height: none;
    overflow-y: visible;
}

/* Individual Tab */
.topscore-doc-tab {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #e8e8e8;
    /* Smooth height animation for filtering */
    max-height: 100px; 
    opacity: 1;
    overflow: hidden;
}

.topscore-doc-tab.hidden {
    padding-top: 0;
    padding-bottom: 0;
    max-height: 0;
    border-bottom: none;
    opacity: 0;
    pointer-events: none;
}

.topscore-doc-tabs.horizontal .topscore-doc-tab {
    border-bottom: none;
    border-right: 1px solid #e8e8e8;
    flex: 0 0 auto;
}

.topscore-doc-tab:hover {
    background: #eaeaea;
}

.topscore-doc-tab.active {
    background: #0073aa;
    color: #fff;
}

.topscore-doc-tab .tab-icon {
    font-size: 18px;
    opacity: 0.7;
    flex-shrink: 0;
}

.topscore-doc-tab.active .tab-icon {
    opacity: 1;
}

/* Featured Image Icon in Tabs */
.topscore-doc-tab .tab-icon-image {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    overflow: hidden;
    opacity: 1;
}

.topscore-doc-tab .tab-icon-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.topscore-doc-tab .tab-title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Content Area */
.topscore-doc-content {
    flex: 1;
    background: #fff;
    min-height: 400px;
    position: relative;
    /* Smooth fade */
}

/* Document Panel */
.topscore-doc-panel {
    display: none;
    height: 100%;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.topscore-doc-panel.active {
    display: flex;
}

/* File Navigation (for multiple files) */
.topscore-doc-file-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 15px;
    background: #fafafa;
    border-bottom: 1px solid #e0e0e0;
}

.file-nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.file-nav-btn:hover {
    background: #f0f0f0;
    border-color: #bbb;
}

.file-nav-btn.active {
    background: #0073aa;
    color: #fff;
    border-color: #0073aa;
}

.file-nav-btn .file-name {
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Document File */
.topscore-doc-file {
    display: none;
    flex-direction: column;
    flex: 1;
    height: 100%;
}

.topscore-doc-file.active {
    display: flex;
}

/* File Header */
.topscore-doc-file-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #fafafa;
    border-bottom: 1px solid #e0e0e0;
}

.topscore-doc-file-header .file-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.topscore-doc-file-header .file-name {
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.topscore-doc-file-header .file-meta {
    font-size: 12px;
    color: #666;
}

.topscore-doc-file-header .file-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: #666;
    position: relative; /* For tooltip */
}

.action-btn:hover {
    background: #0073aa;
    border-color: #0073aa;
    color: #fff;
}

/* Tooltip for Share Button */
.action-btn[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 100;
}

.action-btn[data-tooltip].show-tooltip::before {
    opacity: 1;
    visibility: visible;
    bottom: -34px;
}

/* Document Viewer (iframe container) */
.topscore-doc-viewer {
    flex: 1;
    height: 70vh;
    min-height: 500px;
    background: #f5f5f5;
    position: relative;
    overflow: hidden;
}

.topscore-doc-viewer iframe.doc-viewer-iframe {
    width: 100%;
    height: 100%;
    min-height: inherit;
    border: none;
    display: block;
    opacity: 0; /* Hidden until loaded */
    transition: opacity 0.5s ease;
}

.topscore-doc-viewer.loaded iframe.doc-viewer-iframe {
    opacity: 1;
}

/* Loading Indicator */
.topscore-doc-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    z-index: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.topscore-doc-viewer.loaded .topscore-doc-loading {
    opacity: 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

.loading-text {
    font-size: 13px;
    color: #666;
}

/* Download Prompt (for non-PDF files) */
.topscore-doc-download-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
    text-align: center;
    z-index: 2; /* Ensure above loading */
    position: relative;
    background: #fff;
}

.topscore-doc-download-prompt .file-icon.large {
    font-size: 64px;
    margin-bottom: 20px;
}

.topscore-doc-download-prompt h4 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #333;
}

.topscore-doc-download-prompt p {
    margin: 0 0 20px;
    color: #666;
}

.topscore-doc-download-prompt .download-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #0073aa;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 500;
    transition: background 0.2s;
}

.topscore-doc-download-prompt .download-link:hover {
    background: #005a87;
}

/* No Files Message */
.topscore-doc-no-files {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    text-align: center;
    padding: 40px;
}

.topscore-doc-no-files .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    margin-bottom: 15px;
}

/* Empty State */
.topscore-doc-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    text-align: center;
    background: #f9f9f9;
    border: 2px dashed #ddd;
    border-radius: 8px;
}

.topscore-doc-empty p {
    margin: 15px 0 0;
    color: #666;
}

/* File Icons */
.file-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #e0e0e0;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
    color: #666;
}

.file-icon-pdf { background: #e74c3c; color: #fff; }
.file-icon-doc, .file-icon-docx { background: #2b579a; color: #fff; }
.file-icon-xls, .file-icon-xlsx { background: #217346; color: #fff; }
.file-icon-ppt, .file-icon-pptx { background: #d24726; color: #fff; }
.file-icon-txt { background: #666; color: #fff; }
.file-icon-csv { background: #107c10; color: #fff; }

.file-icon::before {
    content: attr(data-ext);
}

/* Accordion Layout */
.topscore-doc-accordion {
    width: 100%;
}

/* ========================================
   FILES LIST LAYOUT (Per-file tabs)
   ======================================== */

/* Group Heading - document title as section header */
.topscore-doc-group-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    border-bottom: 1px solid #e8e8e8;
    background: #eee;
    user-select: none;
}

.topscore-doc-group-heading.hidden {
    display: none !important;
}

.topscore-doc-group-heading .group-icon {
    font-size: 14px;
    width: 14px;
    height: 14px;
    opacity: 0.6;
    flex-shrink: 0;
}

.topscore-doc-group-heading .group-icon-image {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    overflow: hidden;
    opacity: 1;
}

.topscore-doc-group-heading .group-icon-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.topscore-doc-group-heading .group-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* File Tab within files-list - show file extension badge */
.topscore-doc-tab.file-tab {
    gap: 8px;
    padding: 10px 15px;
}

.topscore-doc-tab.file-tab .file-icon {
    width: 22px;
    height: 22px;
    font-size: 10px;
    flex-shrink: 0;
}

.topscore-doc-tab.file-tab .tab-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topscore-doc-tab.file-tab .tab-ext {
    font-size: 10px;
    opacity: 0.6;
    text-transform: uppercase;
    flex-shrink: 0;
}

.topscore-doc-tab.file-tab.active .tab-ext {
    opacity: 0.8;
}

/* Files-list tabs scrollable */
.topscore-doc-tabs.files-list-tabs {
    overflow-y: auto;
}

.topscore-doc-accordion-item {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.topscore-doc-accordion-item:last-child {
    margin-bottom: 0;
}

.topscore-doc-accordion-item.hidden {
    display: none;
}

.accordion-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    background: #f5f5f5;
    cursor: pointer;
    transition: background 0.2s;
}

.accordion-header:hover {
    background: #eaeaea;
}

.topscore-doc-accordion-item.active .accordion-header {
    background: #0073aa;
    color: #fff;
}

.accordion-header .accordion-icon {
    font-size: 20px;
    flex-shrink: 0;
}

/* Featured Image Icon in Accordion */
.accordion-header .accordion-icon-image {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    overflow: hidden;
}

.accordion-header .accordion-icon-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.accordion-header .accordion-title {
    flex: 1;
    font-weight: 500;
    font-size: 15px;
}

.accordion-header .accordion-toggle {
    transition: transform 0.3s;
}

.topscore-doc-accordion-item.active .accordion-toggle {
    transform: rotate(180deg);
}

.accordion-content {
    display: none;
    padding: 15px 20px;
    background: #fff;
}

.topscore-doc-accordion-item.active .accordion-content {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.accordion-files {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.accordion-file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    text-decoration: none;
    color: #333;
    transition: all 0.2s;
}

.accordion-file-item:hover {
    background: #f0f0f0;
    border-color: #0073aa;
}

.accordion-file-item .file-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.accordion-file-item .file-name {
    font-weight: 500;
    font-size: 14px;
}

.accordion-file-item .file-meta {
    font-size: 12px;
    color: #666;
}

/* Fullscreen Mode */
.topscore-doc-wrapper.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    border-radius: 0;
}

.topscore-doc-wrapper.fullscreen .topscore-doc-viewer {
    height: calc(100vh - 60px);
}

/* Responsive Design */
@media (max-width: 768px) {
    .topscore-doc-wrapper {
        flex-direction: column !important;
    }
    
    .topscore-doc-tabs-content-wrapper {
        flex-direction: column !important;
    }

    .topscore-doc-search-wrapper {
        width: 100% !important;
        position: relative; /* Normal flow on mobile */
        border-right: none !important;
    }
    
    .topscore-doc-tabs[role="tablist"] {
        padding-top: 0 !important;
        width: 100% !important;
        max-height: none;
        border-right: none !important;
        border-left: none !important;
        border-bottom: 1px solid #e0e0e0;
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .topscore-doc-tab {
        border-bottom: none;
        border-right: 1px solid #e8e8e8;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .topscore-doc-content {
        width: 100% !important;
    }
    
    .topscore-doc-viewer {
        height: 400px;
    }
    
    .topscore-doc-file-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .topscore-doc-file-header .file-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* Files List responsive - tabs become horizontal scroll */
    .topscore-doc-tabs.files-list-tabs {
        width: 100% !important;
        max-height: none;
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none !important;
        border-bottom: 1px solid #e0e0e0;
    }

    .topscore-doc-tabs.files-list-tabs .topscore-doc-group-heading {
        display: none; /* Hide group headings on mobile horizontal scroll */
    }

    .topscore-doc-tabs.files-list-tabs .topscore-doc-tab {
        flex-shrink: 0;
        border-bottom: none;
        border-right: 1px solid #e8e8e8;
    }

    /* Adjust order for right layout on mobile */
    .topscore-doc-wrapper.layout-tabs-right .topscore-doc-tabs-content-wrapper {
        flex-direction: column !important;
    }
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */

/* Dark mode using prefers-color-scheme */
@media (prefers-color-scheme: dark) {
    .topscore-doc-wrapper {
        background: #1e1e1e;
        border-color: #3a3a3a;
    }

    .topscore-doc-search-wrapper {
        background: #252525;
        border-color: #3a3a3a;
    }

    .topscore-doc-search {
        background: #1e1e1e;
        border-color: #444;
    }

    .topscore-doc-search-input {
        color: #e0e0e0 !important;
    }

    .topscore-doc-search:focus-within {
        border-color: #0073aa;
        box-shadow: 0 0 0 1px #0073aa;
    }

    .topscore-doc-tabs {
        background: #252525;
        border-color: #3a3a3a;
    }

    .topscore-doc-tab {
        color: #e0e0e0;
        border-color: #3a3a3a;
    }

    .topscore-doc-tab:hover {
        background: #333333;
    }

    .topscore-doc-tab.active {
        background: #0073aa;
        color: #fff;
    }

    .topscore-doc-content {
        background: #1e1e1e;
    }

    .topscore-doc-file-nav {
        background: #252525;
        border-color: #3a3a3a;
    }

    .file-nav-btn {
        background: #333333;
        border-color: #4a4a4a;
        color: #e0e0e0;
    }

    .file-nav-btn:hover {
        background: #404040;
        border-color: #5a5a5a;
    }

    .file-nav-btn.active {
        background: #0073aa;
        color: #fff;
        border-color: #0073aa;
    }

    .topscore-doc-file-header {
        background: #252525;
        border-color: #3a3a3a;
    }

    .topscore-doc-file-header .file-name {
        color: #e0e0e0;
    }

    .topscore-doc-file-header .file-meta {
        color: #999;
    }

    .action-btn {
        background: #333333;
        border-color: #4a4a4a;
        color: #e0e0e0;
    }

    .action-btn:hover {
        background: #0073aa;
        border-color: #0073aa;
        color: #fff;
    }

    .topscore-doc-viewer {
        background: #2a2a2a;
    }

    .topscore-doc-loading {
        background: #2a2a2a;
    }

    .loading-spinner {
        border-color: #444;
        border-top-color: #0073aa;
    }

    .loading-text {
        color: #888;
    }

    .topscore-doc-download-prompt {
        background: #2a2a2a;
    }

    .topscore-doc-download-prompt h4 {
        color: #e0e0e0;
    }

    .topscore-doc-download-prompt p {
        color: #999;
    }

    .topscore-doc-no-files {
        color: #777;
    }

    .topscore-doc-empty {
        background: #252525;
        border-color: #3a3a3a;
    }

    .topscore-doc-empty p {
        color: #999;
    }

    /* Accordion Dark Mode */
    .topscore-doc-accordion-item {
        border-color: #3a3a3a;
    }

    /* Files List Dark Mode */
    .topscore-doc-group-heading {
        color: #999;
        background: #1a1a1a;
        border-color: #3a3a3a;
    }

    .accordion-header {
        background: #252525;
        color: #e0e0e0;
    }

    .accordion-header:hover {
        background: #333333;
    }

    .topscore-doc-accordion-item.active .accordion-header {
        background: #0073aa;
        color: #fff;
    }

    .accordion-content {
        background: #1e1e1e;
    }

    .accordion-file-item {
        background: #252525;
        border-color: #3a3a3a;
        color: #e0e0e0;
    }

    .accordion-file-item:hover {
        background: #333333;
        border-color: #0073aa;
    }

    .accordion-file-item .file-meta {
        color: #999;
    }

    /* Search Dark Mode */
    .topscore-doc-search-wrapper {
        background: #252525;
        border-color: #3a3a3a;
    }

    .topscore-doc-search {
        background: #1e1e1e;
        border-color: #444;
    }

    .topscore-doc-search-input {
        color: #e0e0e0 !important;
    }

    .topscore-doc-search:focus-within {
        border-color: #0073aa;
        box-shadow: 0 0 0 1px #0073aa;
    }

    /* Responsive Dark Mode */
    @media (max-width: 768px) {
        .topscore-doc-tabs {
            border-color: #3a3a3a;
        }

        .topscore-doc-tab {
            border-color: #3a3a3a;
        }
    }
}
