/* ============================================================================
   DOCUMENT LIST COMPONENT
   ============================================================================

   Filtered table view for browsing documents in the Alnaql corpus.
   Includes search, inline filters (year range, genre), and sortable table.

   Layout: title → compact toolbar (search + filters + count) → table

   ============================================================================ */

/* ============================================================================
   MAIN CONTAINER
   ============================================================================ */

.document-list-container {
    padding: var(--space-5) var(--space-10) var(--space-10);
    max-width: var(--content-max-width);
    margin: 0 auto;
}


/* ============================================================================
   LIST HEADER
   ============================================================================ */

.list-header {
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 2px solid var(--color-sand);
}

.list-header h2 {
    font-size: 1.75rem;
    color: var(--color-primary-darker);
    margin: 0;
}


/* ============================================================================
   DOCUMENT TOOLBAR  (search + filters + count in one row)
   ============================================================================ */

.document-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

/* Search input takes remaining space */
.document-toolbar .general-search-container {
    flex: 1;
    min-width: 200px;
    position: relative;
    margin-bottom: 0;
}

.general-search-input {
    width: 100%;
    padding: 0.625rem var(--space-10) 0.625rem var(--space-4);
    font-size: var(--font-size-base);
    border: 2px solid var(--color-sand);
    border-radius: var(--radius-md);
    background-color: var(--color-sand-lighter);
    transition: var(--transition-all);
    font-family: var(--font-primary);
}

.general-search-input:focus {
    outline: none;
    border-color: var(--color-sand-medium);
    box-shadow: 0 0 0 3px rgba(232, 213, 183, 0.3);
}

.general-search-input::placeholder {
    color: var(--color-text-secondary);
}

.clear-search-button {
    position: absolute;
    inset-inline-start: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    transition: var(--transition-all);
}

.clear-search-button:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--color-primary-darker);
}


/* ============================================================================
   TOOLBAR FILTERS  (inline group: death year + genre + clear)
   ============================================================================ */

.toolbar-filters {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-shrink: 0;
}

/* Override death year filter to be a compact inline row */
.toolbar-filters .death-year-filter {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.375rem;
}

.toolbar-filters .death-year-filter .filter-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary-darker);
    margin-bottom: 0;
    white-space: nowrap;
}

.toolbar-filters .death-year-inputs {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.toolbar-filters .death-year-input {
    width: 4.5rem;
    padding: 0.4375rem var(--space-2);
    font-size: var(--font-size-sm);
    border: 2px solid var(--color-sand);
    border-radius: var(--radius-md);
    background-color: var(--color-white);
    transition: var(--transition-all);
    font-family: var(--font-primary);
}

.toolbar-filters .death-year-input:focus {
    outline: none;
    border-color: var(--color-sand-medium);
    box-shadow: 0 0 0 3px rgba(232, 213, 183, 0.3);
}

.toolbar-filters .year-separator {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.toolbar-filters .clear-year-button {
    background: none;
    border: none;
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    transition: var(--transition-all);
}

.toolbar-filters .clear-year-button:hover {
    background-color: rgba(255, 0, 0, 0.1);
    color: var(--color-danger);
}

/* Genre filter button — compact */
.toolbar-filters .genre-filter-container {
    position: relative;
}

.toolbar-filters .genre-filter-button {
    padding: 0.4375rem 0.875rem;
    font-size: var(--font-size-sm);
    background-color: var(--color-white);
    border: 2px solid var(--color-sand);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    transition: var(--transition-all);
    min-width: 8.75rem;
    justify-content: space-between;
    font-family: var(--font-primary);
}

.toolbar-filters .genre-filter-button:hover {
    border-color: var(--color-sand-medium);
    background-color: var(--color-sand-lighter);
}

.dropdown-arrow {
    font-size: 0.75rem;
    transition: var(--transition-transform);
}


/* ============================================================================
   GENRE DROPDOWN  (with enter animation)
   ============================================================================ */

@keyframes dropdown-enter {
    from {
        opacity: 0;
        transform: translateY(calc(-1 * var(--space-2)));
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.genre-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    inset-inline-start: 0;
    min-width: 15.625rem;
    background-color: var(--color-white);
    border: 2px solid var(--color-sand);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    max-height: 25rem;
    overflow-y: auto;
    animation: dropdown-enter var(--duration-fast) var(--ease-out) both;
}

.genre-dropdown-header {
    display: flex;
    gap: 0.625rem;
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-sand);
    background-color: var(--color-sand-light);
}

.genre-action-button {
    flex: 1;
    padding: 0.375rem var(--space-3);
    font-size: var(--font-size-sm);
    background-color: var(--color-white);
    border: 1px solid var(--color-sand-medium);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-all);
    font-family: var(--font-primary);
}

.genre-action-button:hover {
    background-color: var(--color-sand);
}

.genre-checkbox-list {
    padding: var(--space-2);
}

.genre-checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem var(--space-3);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition-bg);
}

.genre-checkbox-item:hover {
    background-color: var(--color-sand-light);
}

.genre-checkbox-item input[type="checkbox"] {
    width: var(--font-size-lg);
    height: var(--font-size-lg);
    cursor: pointer;
}

.genre-label {
    font-size: 0.9375rem;
    color: var(--color-primary-darker);
    flex: 1;
    font-family: var(--font-primary);
}

.genre-count {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}


/* ============================================================================
   HAS-MATCHES TOGGLE BUTTON
   ============================================================================ */

.has-matches-toggle {
    padding: 0.4375rem 0.875rem;
    font-size: var(--font-size-sm);
    background-color: var(--color-white);
    border: 2px solid var(--color-sand);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-all);
    font-family: var(--font-primary);
    white-space: nowrap;
}

.has-matches-toggle:hover {
    border-color: var(--color-sand-medium);
    background-color: var(--color-sand-lighter);
}

.has-matches-toggle.active {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
}

.has-matches-toggle.active:hover {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}


/* ============================================================================
   CLEAR ALL FILTERS BUTTON  (compact icon button in toolbar)
   ============================================================================ */

.clear-all-filters-button {
    padding: 0.375rem 0.625rem;
    background-color: var(--color-white);
    color: var(--color-danger);
    border: 2px solid var(--color-danger);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: var(--transition-all);
    font-family: var(--font-primary);
    line-height: 1;
}

.clear-all-filters-button:hover {
    background-color: var(--color-danger);
    color: var(--color-white);
}


/* ============================================================================
   RESULTS COUNT  (inline in toolbar, pushed to far end)
   ============================================================================ */

.document-toolbar .results-count {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary-darker);
    white-space: nowrap;
    margin-inline-start: auto;
    font-family: var(--font-primary);
}


/* ============================================================================
   DOCUMENT TABLE
   ============================================================================ */

.document-table-container {
    background-color: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.document-table {
    width: 100%;
    border-collapse: collapse;
}

.table-header {
    background-color: var(--color-sand);
}

.table-header th {
    padding: var(--space-4) var(--space-5);
    text-align: start;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary-darker);
    border-bottom: 2px solid var(--color-sand-medium);
    font-family: var(--font-primary);
}

.table-header th.sortable {
    cursor: pointer;
    user-select: none;
    transition: var(--transition-bg);
}

.table-header th.sortable:hover {
    background-color: var(--color-sand-medium);
}


/* ============================================================================
   TABLE ROW ENTRANCE ANIMATION
   ============================================================================ */

@keyframes row-enter {
    from {
        opacity: 0;
        transform: translateY(var(--space-2));
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.table-row {
    transition: var(--transition-bg);
    border-bottom: 1px solid var(--color-border-subtle);
    cursor: pointer;
    animation: row-enter var(--duration-base) var(--ease-out) both;
}

.table-row:hover {
    background-color: var(--color-sand-light);
}

.table-row:nth-child(even) {
    background-color: var(--color-sand-lighter);
}

.table-row:last-child {
    border-bottom: none;
}

.table-cell {
    padding: var(--space-4) var(--space-5);
    font-size: 0.9375rem;
    color: var(--color-text-primary);
    font-family: var(--font-primary);
    line-height: var(--line-height-loose);
}

.column-author {
    width: 20%;
    font-weight: var(--font-weight-semibold);
}

.column-title {
    width: 45%;
    font-weight: var(--font-weight-medium);
}

.column-death-year {
    width: 15%;
    text-align: center;
    color: var(--color-text-secondary);
}

.column-genre {
    width: 20%;
    color: var(--color-text-secondary);
}


/* ============================================================================
   AUTHOR PERS_NAME SUBTITLE + DOCUMENT SIZE
   ============================================================================ */

.author-name {
    /* Inherit font-weight from .column-author */
}

.author-pers-name {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-normal);
    margin-top: var(--space-1);
    line-height: var(--line-height-normal);
}

.doc-size {
    display: inline-block;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-top: var(--space-1);
}


/* ============================================================================
   NO RESULTS MESSAGE
   ============================================================================ */

.no-results {
    padding: var(--space-15) var(--space-5);
    text-align: center;
    background-color: var(--color-sand-light);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--color-sand);
}

.no-results-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary-darker);
    margin: 0 0 var(--space-2);
    font-family: var(--font-primary);
}

.no-results-hint {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    margin: 0;
    font-family: var(--font-primary);
}

/* Legacy fallback for unclassed <p> inside .no-results */
.no-results p:not([class]) {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    margin: 0;
    font-family: var(--font-primary);
}


/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 1024px) {
    .document-list-container {
        padding: var(--space-5);
    }

    /* Toolbar wraps: search on top row, filters below */
    .document-toolbar {
        gap: 0.625rem;
    }

    .document-toolbar .general-search-container {
        flex-basis: 100%;
    }

    .toolbar-filters {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .list-header h2 {
        font-size: var(--font-size-2xl);
    }

    .toolbar-filters {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .toolbar-filters .death-year-filter {
        flex-wrap: wrap;
    }

    .toolbar-filters .genre-filter-button {
        width: 100%;
        min-width: unset;
    }

    .has-matches-toggle {
        width: 100%;
        text-align: center;
    }

    .document-table-container {
        overflow-x: auto;
    }

    .document-table {
        min-width: 37.5rem;
    }

    .column-title {
        width: 40%;
    }

    .column-author,
    .column-genre {
        width: 20%;
    }

    .column-death-year {
        width: 20%;
    }
}


/* ============================================================================
   GENRE BADGE
   ============================================================================ */

.genre-badge {
    display: inline-block;
    padding: 0.125rem 0.625rem;
    font-size: var(--font-size-sm);
    background-color: var(--color-sand-light);
    border: 1px solid var(--color-sand-medium);
    border-radius: var(--radius-full);
    color: var(--color-primary-dark);
    white-space: nowrap;
    font-family: var(--font-primary);
}


/* ============================================================================
   ERROR STATE + RETRY
   ============================================================================ */

.error-container {
    padding: var(--space-12) var(--space-6);
    text-align: center;
    background-color: var(--color-sand-light);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--color-sand);
}

.error-container h3 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary-darker);
    margin: 0 0 var(--space-2);
    font-family: var(--font-primary);
}

.error-container p {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-5);
    font-family: var(--font-primary);
}

.retry-button {
    display: inline-block;
    padding: var(--space-2) var(--space-6);
    font-size: 0.9375rem;
    font-weight: var(--font-weight-semibold);
    font-family: var(--font-primary);
    color: var(--color-white);
    background-color: var(--color-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-all);
}

.retry-button:hover {
    background-color: var(--color-primary-dark);
}

.retry-button:focus-visible {
    outline: 2px solid var(--color-primary-darker);
    outline-offset: 2px;
}


/* ============================================================================
   SKELETON LOADING STATE
   ============================================================================ */

@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.skeleton-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.skeleton-bar {
    height: 2.25rem;
    border-radius: var(--radius-md);
    background: linear-gradient(
        90deg,
        var(--color-sand-light) 25%,
        var(--color-sand) 50%,
        var(--color-sand-light) 75%
    );
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite ease-in-out;
}

.skeleton-search-bar {
    flex: 1;
    min-width: 200px;
}

.skeleton-filter-bar {
    width: 7rem;
}

.skeleton-row {
    cursor: default;
    animation: none;
}

.skeleton-row:hover {
    background-color: transparent;
}

.skeleton-cell {
    height: var(--space-4);
    width: 70%;
    border-radius: var(--radius-sm);
    background: linear-gradient(
        90deg,
        var(--color-sand-light) 25%,
        var(--color-sand) 50%,
        var(--color-sand-light) 75%
    );
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite ease-in-out;
}

.skeleton-wide {
    width: 90%;
}

.skeleton-narrow {
    width: 40%;
}


/* ============================================================================
   KEYBOARD ACCESSIBILITY — FOCUS-VISIBLE STYLES
   ============================================================================ */

.table-row:focus-visible {
    outline: 2px solid var(--color-primary-darker);
    outline-offset: -2px;
    background-color: var(--color-sand-light);
}

.table-header th.sortable:focus-visible {
    outline: 2px solid var(--color-primary-darker);
    outline-offset: -2px;
    background-color: var(--color-sand-medium);
}

.genre-filter-button:focus-visible,
.genre-action-button:focus-visible {
    outline: 2px solid var(--color-primary-darker);
    outline-offset: 2px;
}

.clear-search-button:focus-visible,
.clear-year-button:focus-visible,
.clear-all-filters-button:focus-visible,
.has-matches-toggle:focus-visible {
    outline: 2px solid var(--color-primary-darker);
    outline-offset: 2px;
}

.genre-checkbox-item:focus-within {
    background-color: var(--color-sand-light);
    outline: 2px solid var(--color-primary-darker);
    outline-offset: -2px;
}


/* ============================================================================
   PAGINATION CONTROLS
   ============================================================================ */

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-5) 0 var(--space-2);
}

.pagination-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0 var(--space-3);
    font-size: var(--font-size-lg);
    font-family: var(--font-primary);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary-darker);
    background-color: var(--color-white);
    border: 2px solid var(--color-sand);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-all);
}

.pagination-button:hover:not(:disabled) {
    border-color: var(--color-sand-medium);
    background-color: var(--color-sand-lighter);
}

.pagination-button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pagination-button:focus-visible {
    outline: 2px solid var(--color-primary-darker);
    outline-offset: 2px;
}

.pagination-info {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary-darker);
    font-family: var(--font-primary);
    white-space: nowrap;
}
