/* Codebase & Documentation Archive Styles */

/* ==========================================================================
   Unified Card Grid System
   ========================================================================== */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
    gap: var(--docsync-space-xl);
    max-width: 1200px;
    margin: var(--docsync-space-lg) auto;
}

.cards-grid--narrow {
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
}

/* ==========================================================================
   Unified Card Component
   ========================================================================== */

.doc-card {
    background: var(--docsync-background-card);
    border: 1px solid var(--docsync-border-default);
    border-radius: 8px;
    padding: var(--docsync-space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--docsync-space-lg);
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
}

.doc-card:hover {
    border-color: var(--docsync-accent-strong);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--docsync-shadow-medium);
}

.doc-card--link {
    text-decoration: none;
    color: inherit;
}

.doc-card--compact {
    padding: var(--docsync-space-lg);
    gap: var(--docsync-space-md);
}

/* ==========================================================================
   Card Headers
   ========================================================================== */

.card-header {
    border-bottom: 1px solid var(--docsync-border-light);
    padding-bottom: var(--docsync-space-lg);
}

.project-title,
.card-header h3,
.card-header h4 {
    margin: 0 0 10px;
    font-size: var(--docsync-font-size-xl);
    color: var(--docsync-text-primary);
}

.card-header h4 {
    font-size: var(--docsync-font-size-lg);
}

.project-title a,
.card-header h3 a,
.card-header h4 a {
    text-decoration: none;
    color: var(--docsync-text-primary);
}

.project-title a:hover,
.card-header h3 a:hover,
.card-header h4 a:hover {
    color: var(--docsync-link-color);
}

.project-description,
.card-description {
    color: var(--docsync-body-text-color);
    line-height: 1.6;
    margin: 0;
    font-size: var(--docsync-font-size-sm);
    text-align: center;
}

/* ==========================================================================
   Stats
   ========================================================================== */

.project-stats,
.card-stats {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.card-footer .card-meta {
    font-size: var(--docsync-font-size-xs);
    color: var(--docsync-muted-text-color);
}

.card-footer .button-2 {
    font-size: var(--docsync-font-size-sm);
    padding: 6px 14px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--docsync-accent-subtle);
    border: 1px solid var(--docsync-accent-medium);
    border-radius: 12px;
    padding: 4px 12px;
    font-size: var(--docsync-font-size-sm);
    color: var(--docsync-link-color);
}

.stat-number {
    color: var(--docsync-link-color);
    font-weight: 600;
}

.stat-label {
    color: var(--docsync-text-secondary);
}

/* ==========================================================================
   Content Buttons
   ========================================================================== */

.content-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.card-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: auto;
    padding-top: var(--docsync-space-lg);
    border-top: 1px solid var(--docsync-border-light);
}

.content-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--docsync-accent-subtle);
    border: 1px solid var(--docsync-accent-medium);
    border-radius: 6px;
    padding: 8px 14px;
    color: var(--docsync-accent-color-2);
    text-decoration: none;
    font-size: var(--docsync-font-size-sm);
    transition: all 0.2s ease;
}

.content-btn:hover {
    background: var(--docsync-accent-medium);
    border-color: var(--docsync-accent-strong);
    color: var(--docsync-text-primary);
    transform: translateY(-1px);
}

.btn-label {
    font-weight: 500;
}

.btn-count {
    background: var(--docsync-accent-medium);
    border-radius: 10px;
    padding: 2px 6px;
    font-size: var(--docsync-font-size-sm);
    min-width: 18px;
    text-align: center;
}

/* ==========================================================================
   External Buttons & Actions
   ========================================================================== */

.external-buttons,
.project-actions,
.card-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    border-top: 1px solid var(--docsync-border-light);
    padding-top: var(--docsync-space-lg);
    margin-top: auto;
}

.card-actions {
    align-items: center;
    justify-content: space-between;
}

.external-btn,
.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 6px;
    text-decoration: none;
    font-size: var(--docsync-font-size-sm);
    font-weight: 500;
    transition: all 0.2s ease;
}

.card-actions .btn {
    flex: 1;
    text-align: center;
    padding: 12px 20px;
    white-space: nowrap;
    justify-content: center;
}

.external-btn.primary,
.btn.primary {
    background: var(--docsync-accent-color-2);
    color: var(--docsync-text-contrast);
}

.external-btn.primary:hover,
.btn.primary:hover {
    background: var(--docsync-accent-active);
    transform: translateY(-1px);
}

.external-btn.secondary,
.btn.secondary {
    background: var(--docsync-background-interactive);
    border: 1px solid var(--docsync-border-default);
    color: var(--docsync-text-primary);
}

.external-btn.secondary:hover,
.btn.secondary:hover {
    background: var(--docsync-border-default);
    border-color: var(--docsync-border-light);
    transform: translateY(-1px);
}

.external-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.external-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--docsync-border-default);
    border: 1px solid var(--docsync-border-default);
    border-radius: 6px;
    color: var(--docsync-body-text-color);
    text-decoration: none;
    transition: all 0.3s ease;
}

.external-link:hover {
    background: var(--docsync-accent-subtle);
    border-color: var(--docsync-accent-strong);
    color: var(--docsync-accent-color-2);
}

.btn-icon,
.external-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.external-link svg {
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   Section Headers
   ========================================================================== */

.project-cards-section,
.docs-category-cards-section {
    padding: 40px 0;
}

.documentation-category-section,
.docs-category-header {
    padding: 40px 0;
    border-bottom: 1px solid var(--docsync-border-faint);
}

.documentation-category-section:last-child {
    border-bottom: none;
}

.category-header {
    text-align: center;
    margin-bottom: 40px;
}

.category-header h2 {
    margin: 0 0 15px;
    font-size: var(--docsync-font-size-2xl);
    color: var(--docsync-accent-color-2);
}

.category-header p {
    max-width: 600px;
    margin: 0 auto;
    font-size: var(--docsync-font-size-md);
}

.docs-category-header h1 {
    margin-bottom: 15px;
}

.docs-category-header p {
    max-width: 600px;
    margin: 0 auto;
    font-size: var(--docsync-font-size-md);
}

/* ==========================================================================
   No Content States
   ========================================================================== */

.no-content,
.no-docs-category {
    text-align: center;
    padding: 60px 20px;
    max-width: 500px;
    margin: 0 auto;
}

/* ==========================================================================
   Overflow Protection
   ========================================================================== */

.archive-documentation .archive-posts {
    overflow-x: hidden;
}

/* ==========================================================================
   Documentation Taxonomy Archive
   ========================================================================== */

.docs-archive-header {
    padding: 40px 0 10px;
    text-align: center;
    border-bottom: 1px solid var(--docsync-border-faint);
}

.docs-archive-header h1 {
    margin-bottom: 10px;
}

.docs-archive-content {
    padding: 30px 0 50px;
}

.documentation-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    margin-top: 20px;
}

.doc-item {
    background: var(--docsync-background-card);
    border: 1px solid var(--docsync-border-default);
    border-radius: 10px;
    padding: 22px;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.doc-item:hover {
    border-color: var(--docsync-accent-strong);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--docsync-shadow-light);
}

.doc-item h3 {
    margin: 0 0 10px;
    font-size: var(--docsync-font-size-lg);
}

.doc-item h3 a {
    color: var(--docsync-text-primary);
    text-decoration: none;
}

.doc-item h3 a:hover {
    color: var(--docsync-accent-color-2);
}

.doc-excerpt {
    color: var(--docsync-text-secondary);
    margin: 8px 0 12px;
    line-height: 1.6;
    font-size: var(--docsync-font-size-sm);
}

.doc-meta {
    text-align: center;
    margin: 6px 0 8px;
}

.doc-meta small {
    color: var(--docsync-muted-text-color);
}

/* ==========================================================================
   Documentation Groups (Hierarchical Archive)
   ========================================================================== */

.documentation-group {
    margin-bottom: 40px;
}

.group-title {
    font-size: var(--docsync-font-size-xl);
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--docsync-border-light);
    color: var(--docsync-text-primary);
}

.group-title a {
    color: var(--docsync-text-primary);
    text-decoration: none;
}

.group-title a:hover {
    color: var(--docsync-accent-color-2);
}

.group-description {
    color: var(--docsync-text-secondary);
    margin-bottom: 20px;
    font-size: var(--docsync-font-size-base);
    max-width: 800px;
}

.documentation-group.child-section {
    margin-top: 50px;
}

/* ==========================================================================
   Term Sections (Hierarchical Archive)
   ========================================================================== */

.term-section {
    margin-bottom: 2rem;
}

.term-section.depth-1 {
    margin-top: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--docsync-border-light);
}

.term-section.depth-1:last-child {
    border-bottom: none;
}

.term-section-header h3,
.term-section-header h4,
.term-section-header h5 {
    margin: 0 0 1rem;
}

.term-section.depth-2,
.term-section.depth-3 {
    background: var(--docsync-background-muted);
    border: 1px solid var(--docsync-border-default);
    border-radius: 8px;
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.term-section .view-all-wrapper {
    text-align: center;
    margin-top: 1.5rem;
}

/* ==========================================================================
   Project Info Card
   ========================================================================== */

.project-info-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem;
    background: var(--docsync-background-card);
    border: 1px solid var(--docsync-border-default);
    border-radius: 12px;
    max-width: 800px;
    margin: 0 auto 2rem;
}

.project-info-card .project-description {
    text-align: center;
    margin: 0;
    color: var(--docsync-body-text-color);
    line-height: 1.6;
    max-width: 600px;
}

.project-info-card .project-stats {
    padding-top: 0;
}

.project-info-card .project-actions {
    border-top: none;
    padding-top: 0;
    justify-content: center;
}

/* Override theme .btn to restore icon+text alignment inside project cards */
.project-info-card .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .cards-grid {
        grid-template-columns: 1fr;
        gap: var(--docsync-space-lg);
    }

    .cards-grid--narrow {
        grid-template-columns: 1fr;
    }

    .doc-card {
        padding: var(--docsync-space-lg);
        gap: var(--docsync-space-md);
    }

    .doc-card--compact {
        padding: var(--docsync-space-md);
    }

    .content-buttons {
        flex-direction: column;
    }

    .content-btn {
        justify-content: space-between;
    }

    .external-buttons {
        flex-direction: column;
    }

    .external-btn {
        text-align: center;
        justify-content: center;
    }

    .card-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .external-links {
        justify-content: center;
    }

    .card-stats {
        justify-content: center;
    }

    .documentation-list {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    /* Project info card — compact but not stretched */
    .project-info-card {
        padding: 1.25rem;
        gap: 1rem;
    }

    .project-info-card .project-actions {
        flex-wrap: wrap;
        justify-content: center;
        width: auto;
    }

    .project-info-card .btn {
        width: auto;
        justify-content: center;
    }

    /* Nested term sections — flatten to left-border accent on mobile
       instead of heavy background boxes that waste horizontal space */
    .term-section.depth-2,
    .term-section.depth-3 {
        background: transparent;
        border: none;
        border-left: 3px solid var(--docsync-accent-medium);
        border-radius: 0;
        padding: 0 0 0 1rem;
        margin-top: 1rem;
    }

    /* Tighter cards inside nested sections */
    .term-section.depth-2 .doc-card--compact,
    .term-section.depth-3 .doc-card--compact {
        padding: var(--docsync-space-md);
    }
}

@media (max-width: 480px) {
    .project-stats,
    .card-stats {
        justify-content: center;
    }

    .stat-item {
        flex-direction: column;
        gap: 2px;
        text-align: center;
        min-width: 70px;
    }
}

/* ==========================================================================
   Documentation Search Bar
   ========================================================================== */

.docs-search-wrapper {
    max-width: 600px;
    margin: 0 auto 30px;
    position: relative;
}

.docs-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--docsync-background-card);
    border: 1px solid var(--docsync-border-default);
    border-radius: 8px;
    box-shadow: 0 8px 30px var(--docsync-shadow-medium);
    z-index: 100;
    max-height: 400px;
    overflow-y: auto;
}

.docs-search-results[hidden] {
    display: none;
}

.docs-search-loading,
.docs-search-error,
.docs-search-empty {
    padding: 20px;
    text-align: center;
    color: var(--docsync-text-secondary);
}

.docs-search-error {
    color: var(--docsync-error-color, #dc3545);
}

.docs-search-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.docs-search-item {
    border-bottom: 1px solid var(--docsync-border-faint);
}

.docs-search-item:last-child {
    border-bottom: none;
}

.docs-search-link {
    display: block;
    padding: 14px 18px;
    text-decoration: none;
    transition: background 0.2s ease;
}

.docs-search-link:hover {
    background: var(--docsync-accent-subtle);
}

.docs-search-title {
    display: block;
    font-weight: 600;
    color: var(--docsync-text-primary);
    margin-bottom: 4px;
}

.docs-search-project {
    display: inline-block;
    font-size: var(--docsync-font-size-xs);
    background: var(--docsync-accent-subtle);
    color: var(--docsync-accent-color-2);
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.docs-search-excerpt {
    display: block;
    font-size: var(--docsync-font-size-sm);
    color: var(--docsync-text-secondary);
    line-height: 1.5;
}

.docs-search-view-all {
    display: block;
    padding: 14px 18px;
    text-align: center;
    background: var(--docsync-background-muted);
    color: var(--docsync-accent-color-2);
    text-decoration: none;
    font-weight: 500;
    border-top: 1px solid var(--docsync-border-default);
    border-radius: 0 0 8px 8px;
    transition: background 0.2s ease;
}

.docs-search-view-all:hover {
    background: var(--docsync-accent-subtle);
}

@media (max-width: 768px) {
    .docs-search-wrapper {
        margin: 0 15px 25px;
    }

    .docs-search-results {
        max-height: 300px;
    }

    .docs-search-link {
        padding: 12px 14px;
    }
}

/* ==========================================================================
   Documentation Content Tables
   ========================================================================== */

/* Wrap tables in a scrollable container for mobile */
.documentation-content table,
.entry-content table,
.single-documentation table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--docsync-space-xl) 0;
    font-size: var(--docsync-font-size-sm);
}

.documentation-content th,
.entry-content th,
.single-documentation th {
    background: var(--docsync-background-secondary);
    color: var(--docsync-text-primary);
    font-weight: 600;
    font-family: 'Space Grotesk', sans-serif;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 2px solid var(--docsync-accent-medium);
    white-space: nowrap;
}

.documentation-content td,
.entry-content td,
.single-documentation td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--docsync-border-default);
    color: var(--docsync-body-text-color);
    text-align: left;
}

.documentation-content tbody tr:nth-child(even),
.entry-content tbody tr:nth-child(even),
.single-documentation tbody tr:nth-child(even) {
    background: var(--docsync-background-muted);
}

.documentation-content tbody tr:hover,
.entry-content tbody tr:hover,
.single-documentation tbody tr:hover {
    background: var(--docsync-accent-subtle);
}

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--docsync-space-xl) 0;
}

.table-responsive table {
    margin: 0;
}

/* ==========================================================================
   Content Overflow Protection
   ========================================================================== */

/* Pre/code blocks scroll horizontally instead of stretching the page */
.single-documentation pre,
.documentation-content pre,
.entry-content pre {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.single-documentation code,
.documentation-content code,
.entry-content code {
    word-break: break-all;
}

/* Long URLs and text don't break layout */
.single-documentation .post-content,
.documentation-content,
.entry-content {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Images constrained to content width */
.single-documentation img,
.documentation-content img {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.docsync-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin: 2rem 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--docsync-border-light, #e9ecef);
    flex-wrap: wrap;
}

.docsync-pagination a,
.docsync-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--docsync-border-default, #dee2e6);
    border-radius: 6px;
    font-size: var(--docsync-font-size-sm, 0.875rem);
    text-decoration: none;
    transition: all 0.15s ease;
}

.docsync-pagination a {
    color: var(--docsync-text-secondary, #495057);
    background: var(--docsync-background-card, #ffffff);
}

.docsync-pagination a:hover {
    color: var(--docsync-accent-strong, #0066cc);
    border-color: var(--docsync-accent-strong, #0066cc);
    background: var(--docsync-accent-subtle, #e6f0fa);
}

.docsync-pagination .current {
    color: var(--docsync-text-contrast, #ffffff);
    background: var(--docsync-accent-strong, #0066cc);
    border-color: var(--docsync-accent-strong, #0066cc);
    font-weight: 600;
}

.docsync-pagination .dots {
    border: none;
    background: none;
    color: var(--docsync-text-secondary, #495057);
    min-width: auto;
    padding: 0 0.25rem;
}

@media (max-width: 768px) {
    .docsync-pagination {
        gap: 0.35rem;
    }

    .docsync-pagination a,
    .docsync-pagination span {
        min-width: 2rem;
        height: 2rem;
        padding: 0.25rem 0.5rem;
        font-size: var(--docsync-font-size-xs, 0.75rem);
    }
}
