:root {
    /* Light Theme Variables - Matching Nukta AI */
    --doc-bg: #f0efe9;
    --doc-card-bg: #ffffff;
    --doc-card-hover: #fafafa;
    --doc-text: #1a1a1a;
    --doc-text-muted: #6b7280;
    --doc-primary: #4a90d9;
    --doc-primary-hover: #3b82f6;
    --doc-border: #e5e7eb;
    --doc-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --doc-shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.08);
}

.documents-page {
    background-color: var(--doc-bg);
    color: var(--doc-text);
    min-height: 100vh;
}

/* List hero title uses /finance header pattern (finance.css); no local header block */

.documents-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 0;
    align-items: center;
}

.search-container {
    flex: 1;
    min-width: 250px;
    position: relative;
}

.search-input {
    width: 100%;
    background: var(--doc-card-bg);
    border: 1px solid var(--doc-border);
    border-radius: 12px;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    color: var(--doc-text);
    font-size: 1rem;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--doc-primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--doc-text-muted);
}

/* Chip row scrolls horizontally; "Zinginezo" sits outside so its dropdown is not clipped (overflow). */
.documents-filter-bar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.documents-filter-chip-scroll {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    padding-bottom: 2px;
    align-items: center;
    flex: 1;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
}

/* Type filters use shared .filter-chip styles from discover.css (same as Gundua). */

.filter-more {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.documents-filter-bar .filter-more {
    flex-shrink: 0;
}

.filter-more--documents-popover .filter-more-menu {
    z-index: 10060;
}

.filter-more-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.filter-more-btn svg {
    transition: transform 0.18s ease;
}

.filter-more.open .filter-more-btn svg,
.filter-more-btn.active svg {
    transform: rotate(180deg);
}

.filter-more-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    max-height: min(280px, 70vh);
    overflow: auto;
    background: var(--doc-card-bg);
    border: 1px solid var(--doc-border);
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}

.filter-more.open .filter-more-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.filter-dropdown-item {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    color: var(--doc-text);
    border-radius: 10px;
    padding: 10px 10px;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.2;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.filter-dropdown-item:hover {
    background: rgba(74, 144, 217, 0.08);
    border-color: rgba(74, 144, 217, 0.25);
}

.filter-dropdown-item.active {
    background: rgba(74, 144, 217, 0.14);
    border-color: rgba(74, 144, 217, 0.35);
    color: #0f172a;
    font-weight: 600;
}

.documents-page .finance-detail-content {
    /* Match finance detail pages spacing */
    padding: 0 40px 60px;
}

.documents-page .documents-list {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 12px;
    padding: 1rem 0;
    align-content: start;
}

.document-row {
    background: var(--doc-card-bg);
    border: 1px solid var(--doc-border);
    border-radius: 12px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: all 0.2s ease;
    position: relative;
    cursor: pointer;
    box-shadow: var(--doc-shadow);
    overflow: hidden;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.document-cover {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #e5e7eb;
    position: relative;
    overflow: hidden;
}

.document-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.document-cover-placeholder {
    width: 100%;
    height: 100%;
    min-height: 80px;
    background: linear-gradient(145deg, #d1d5db 0%, #e5e7eb 45%, #d1d5db 100%);
}

.document-row-body {
    padding: 0.75rem 0.85rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.document-row-top {
    display: block;
    margin-bottom: 0;
}

.document-row:hover {
    background: var(--doc-card-hover);
    border-color: var(--doc-primary);
    z-index: 1; /* Stay above neighbors on hover */
    transform: translateY(-1px);
    box-shadow: var(--doc-shadow-hover);
}

.row-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    flex: 1;
    min-width: 0;
}

.document-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--doc-text);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
    min-width: 0;
}

.document-type-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    background: rgba(99, 102, 241, 0.1);
    color: var(--doc-primary);
    font-weight: 600;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.document-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.75rem;
    font-size: 0.72rem;
    color: var(--doc-text-muted);
    align-items: flex-start;
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
}

.meta-item {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.25rem;
    min-width: 0;
    max-width: 100%;
}

.meta-text {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    line-height: 1.35;
}

.document-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem 0.65rem;
    align-items: flex-start;
    justify-content: space-between;
    margin-top: 0;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.document-actions--no-meta {
    justify-content: flex-end;
}

.document-actions-btns {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
}

.secondary-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.btn-view {
    background: var(--doc-primary);
    color: white !important;
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-view:hover {
    background: var(--doc-primary-hover);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fdfdfd;
    border: 1px solid var(--doc-border);
    border-radius: 6px;
    color: var(--doc-text-muted);
    cursor: pointer;
    text-decoration: none !important;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #fff;
    border-color: var(--doc-primary);
    color: var(--doc-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* Animations */
@keyframes fadeInSlide {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.document-row {
    animation: fadeInSlide 0.3s ease-out forwards;
}

/* ========================================
   Mobile Card Layout
   ======================================== */
@media (max-width: 768px) {

    /* Tighten list padding */
    .documents-page .finance-detail-content {
        padding: 0 16px 40px;
    }

    .documents-page .documents-list {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        padding: 0.75rem 0;
        gap: 10px;
    }

    .document-row {
        border-radius: 10px;
        box-shadow: none;
    }

    .document-row-body {
        padding: 0.65rem 0.7rem 0.75rem;
    }

    .document-cover {
        aspect-ratio: 16 / 10;
    }

    .document-row-top {
        margin-bottom: 0;
    }

    .row-header {
        gap: 0.25rem;
        width: 100%;
    }

    .document-title {
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        overflow: hidden;
        overflow-wrap: anywhere;
        word-break: break-word;
        font-size: 0.82rem;
        line-height: 1.25;
        max-width: 100%;
    }

    .document-type-badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.45rem;
    }

    .document-meta {
        font-size: 0.68rem;
        gap: 0.35rem 0.5rem;
    }

    .meta-text {
        max-width: 100%;
    }

    .document-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .document-actions-btns {
        width: 100%;
        justify-content: space-between;
    }

    .btn-view {
        justify-content: center;
        padding: 0.46rem 0.55rem;
        font-size: 0.72rem;
        border-radius: 10px;
        min-width: 0;
        flex: 1;
    }

    .secondary-actions {
        display: inline-flex;
    }

    .btn-icon {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .documents-controls {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0;
        margin-bottom: 1.25rem;
    }

    .search-container {
        min-width: 0;
        width: 100%;
    }

    .documents-filter-bar {
        flex-wrap: wrap;
    }

    .documents-filter-chip-scroll {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .documents-filter-chip-scroll::-webkit-scrollbar {
        display: none;
    }

    .documents-filter-bar .filter-more {
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }

    .filter-more-menu {
        right: auto;
        left: 0;
        min-width: 200px;
        max-width: 80vw;
    }
}

/* Excerpt / older card layouts: long words & URLs must stay inside the card */
.documents-page .row-content,
.documents-page .excerpt-container {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.documents-page .document-excerpt {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
    min-width: 0;
}
