/* Minimalist dark theme */
:root {
    --bg: #111;
    --bg-alt: #1a1a1a;
    --text: #eee;
    --text-dim: #888;
    --border: #333;
    --link: #6cf;
    --positive: #4c8;
    --negative: #e55;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.btn {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn:hover {
    border-color: #4b5563;
}

.btn-primary {
    background: #2563eb;
    border-color: #1d4ed8;
    color: #fff;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Country flag tooltip */
.country-flag {
    position: relative;
    cursor: default;
}

.country-flag:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 4px;
}

/* Header */
header {
    padding: 2rem;
    border-bottom: 1px solid var(--border);
}

header .header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

header .header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

header .header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 500;
}

header p {
    color: var(--text-dim);
    font-size: 0.9rem;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    width: min(600px, 100%);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.modal-content textarea {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    resize: vertical;
}

.modal-results {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-dim);
    white-space: pre-line;
}

/* Tabs */
.tabs-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
}

.tabs {
    display: flex;
    gap: 0;
}

.tabs-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--text);
    border-bottom-color: var(--link);
}

/* Main */
main {
    padding: 1.5rem 2rem;
    max-width: 1400px;
    width: 100%;
    overflow-x: hidden;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Controls */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
    margin-bottom: 1rem;
}

.controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    min-width: 0;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: var(--text-dim);
    cursor: pointer;
    white-space: nowrap;
    margin: 0;
    padding: 0;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    padding: 0;
    cursor: pointer;
    margin: 0;
}

input, select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--link);
}

input {
    width: 220px;
}

/* Table scroll wrapper for dual scrollbars */
.table-scroll-wrapper {
    position: relative;
}

.top-scrollbar {
    overflow-x: auto;
    overflow-y: hidden;
    height: 12px;
    scrollbar-width: thin;
    scrollbar-color: #555 var(--bg-alt);
}

.top-scrollbar-inner {
    height: 1px;
}

.top-scrollbar::-webkit-scrollbar {
    height: 12px;
}

.top-scrollbar::-webkit-scrollbar-track {
    background: var(--bg-alt);
    border-radius: 6px;
}

.top-scrollbar::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 6px;
    border: 2px solid var(--bg-alt);
}

.top-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* Table */
.table-container {
    overflow-x: auto;
    max-width: 100%;
    /* Always show horizontal scrollbar when content overflows */
    scrollbar-width: thin;
    scrollbar-color: #555 var(--bg-alt);
}

/* Webkit scrollbar styling (Chrome, Safari, Edge) */
.table-container::-webkit-scrollbar {
    height: 12px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--bg-alt);
    border-radius: 6px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 6px;
    border: 2px solid var(--bg-alt);
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #777;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    white-space: nowrap;
}

th:hover {
    color: var(--text);
}

th.sorted-asc::after { content: ' ↑'; }
th.sorted-desc::after { content: ' ↓'; }

tr:hover td {
    background: var(--bg-alt);
}

/* Helpers */
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.dim { color: var(--text-dim); }

.pct-sub {
    font-size: 0.75em;
    opacity: 0.7;
}

/* Archived repos */
tr.archived-repo {
    opacity: 0.5;
}

tr.archived-repo:hover {
    opacity: 0.7;
}

.archived-label {
    display: block;
    color: #9ca3af;
    font-size: 0.7rem;
    font-style: italic;
    margin-top: 0;
    line-height: 1;
}

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.chip {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 500;
    color: #fff;
    background: #374151;
    white-space: nowrap;
}
.chip a { color: inherit; }
.chip a:hover { text-decoration: none; opacity: 0.8; }

/* Category color palette */
.chip-cat-0 { background: #6366f1; } /* indigo */
.chip-cat-1 { background: #8b5cf6; } /* violet */
.chip-cat-2 { background: #ec4899; } /* pink */
.chip-cat-3 { background: #f43f5e; } /* rose */
.chip-cat-4 { background: #f97316; } /* orange */
.chip-cat-5 { background: #eab308; } /* yellow */
.chip-cat-6 { background: #22c55e; } /* green */
.chip-cat-7 { background: #14b8a6; } /* teal */
.chip-cat-8 { background: #06b6d4; } /* cyan */
.chip-cat-9 { background: #3b82f6; } /* blue */

/* Subcat chips - muted version */
.chip-subcat {
    background: #374151;
    color: #d1d5db;
}

.chip-keyword {
    background: #1f2937;
    color: #e5e7eb;
    border: 1px solid #374151;
}

.desc-cell {
    max-width: 280px;
    max-height: 2.8em;
    line-height: 1.4;
    overflow: hidden;
    cursor: pointer;
}

.desc-cell:hover {
    color: var(--link);
}

.desc-cell.expanded {
    max-height: none;
    max-width: 400px;
}

.devs-cell, .repos-cell {
    cursor: pointer;
}

.devs-cell {
    min-width: 200px;
}

.devs-cell .chips-preview, .repos-cell .chips-preview { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.devs-cell .chips-full, .repos-cell .chips-full { display: none; }
.devs-cell .more-indicator, .repos-cell .more-indicator { color: var(--text-dim); font-size: 0.75rem; cursor: pointer; }
.devs-cell .more-indicator:hover, .repos-cell .more-indicator:hover { color: var(--link); }

.devs-cell.expanded .chips-preview, .repos-cell.expanded .chips-preview { display: none; }
.devs-cell.expanded .chips-full, .repos-cell.expanded .chips-full { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.repo-cell {
    max-width: 140px;
    padding-right: 1rem;
}

.repo-cell a {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    text-decoration: none;
}

.repo-cell a:hover {
    text-decoration: none;
}

.repo-cell a:hover .repo-name {
    color: #60a5fa;
}

.repo-cell a:hover .repo-owner {
    color: #93c5fd;
}

.repo-owner {
    font-size: 0.65rem;
    color: var(--text-dim);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.repo-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: #fff;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Compact rank column */
#repos-table td:first-child,
#repos-table th:first-child,
#devs-table td:first-child,
#devs-table th:first-child {
    width: 30px;
    text-align: center;
    font-size: 0.75rem;
}

/* Sticky columns for horizontal scroll */
#repos-table th:nth-child(1),
#repos-table td:nth-child(1),
#repos-table th:nth-child(2),
#repos-table td:nth-child(2),
#repos-table th:nth-child(3),
#repos-table td:nth-child(3),
#devs-table th:nth-child(1),
#devs-table td:nth-child(1),
#devs-table th:nth-child(2),
#devs-table td:nth-child(2),
#devs-table th:nth-child(3),
#devs-table td:nth-child(3) {
    position: sticky;
    background: var(--bg);
    z-index: 1;
}

#repos-table th:nth-child(1),
#repos-table td:nth-child(1),
#devs-table th:nth-child(1),
#devs-table td:nth-child(1) {
    left: 0;
    padding: 0.6rem 0.2rem;
    width: 20px;
    text-align: center;
}

#repos-table th:nth-child(2),
#repos-table td:nth-child(2),
#devs-table th:nth-child(2),
#devs-table td:nth-child(2) {
    left: 20px;
    padding: 0.6rem 0.2rem;
    width: 24px;
    max-width: 24px;
    text-align: center;
}

#repos-table th:nth-child(3),
#repos-table td:nth-child(3),
#devs-table th:nth-child(3),
#devs-table td:nth-child(3) {
    left: 44px;
}

/* Shadow on last sticky column to indicate frozen edge */
#repos-table th:nth-child(3),
#repos-table td:nth-child(3),
#devs-table th:nth-child(3),
#devs-table td:nth-child(3) {
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}

/* Sticky header cells need higher z-index */
#repos-table th,
#devs-table th {
    z-index: 2;
}

/* Sticky columns hover background */
#repos-table tr:hover td:nth-child(1),
#repos-table tr:hover td:nth-child(2),
#repos-table tr:hover td:nth-child(3),
#devs-table tr:hover td:nth-child(1),
#devs-table tr:hover td:nth-child(2),
#devs-table tr:hover td:nth-child(3) {
    background: var(--bg-alt);
}

/* Footer */
footer {
    padding: 2rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
}

/* States */
.loading, .empty {
    padding: 3rem;
    text-align: center;
    color: var(--text-dim);
}

/* Location/Charts styles */
.stats-cards {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, var(--bg-alt) 0%, #222 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: transform 0.2s, border-color 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: #444;
}

.stat-icon {
    font-size: 2rem;
    opacity: 0.9;
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-sub {
    font-size: 0.75rem;
    color: #555;
    margin-top: 0.25rem;
}

.charts-container {
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.chart-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.chart-row {
    display: flex;
    gap: 1.5rem;
}

.chart-wrapper {
    flex: 1;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    transition: border-color 0.2s;
}

.chart-wrapper:hover {
    border-color: #444;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.chart-header h3 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    margin: 0;
}

.chart-badge {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--link);
    background: rgba(102, 204, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chart-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin: -0.5rem 0 0.75rem 0;
}

/* Category filters */
.category-filters {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.filter-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
}

.filter-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.filter-option:hover {
    border-color: #555;
}

.filter-option.active {
    border-color: var(--link);
    background: rgba(102, 204, 255, 0.1);
}

.filter-option input {
    display: none;
}

.filter-option .color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.filter-option span {
    font-size: 0.8rem;
    color: var(--text);
}

.chart-container {
    position: relative;
    width: 100%;
    height: 400px;
}

.chart-container-tall {
    height: 500px;
}

.chart-wrapper-wide {
    max-width: 100%;
}

.chart-wrapper canvas {
    display: block;
}

@media (max-width: 1000px) {
    .stats-cards {
        flex-direction: column;
    }

    .chart-row {
        flex-direction: column;
    }

    main {
        padding: 1rem;
    }

    header {
        padding: 1rem;
    }

    header .header-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .tabs-bar {
        padding: 0 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .controls {
        flex-wrap: wrap;
    }

    .controls input {
        width: 100%;
    }

    .controls select {
        flex: 1;
        min-width: 120px;
    }
}

/* Category Detail View */
.category-detail-header {
    margin-bottom: 1.5rem;
}

.category-detail-header h1 {
    font-size: 1.8rem;
    margin: 0.5rem 0;
}

.category-description {
    color: var(--text-dim);
    font-size: 1rem;
    margin-top: 0.5rem;
    max-width: 800px;
}

.back-btn {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.back-btn:hover {
    background: var(--border);
}

/* Category link in repos table */
.category-link {
    cursor: pointer;
    transition: color 0.2s;
}

.category-link:hover {
    color: var(--link);
    text-decoration: underline;
}

/* Subcategory link in repos table */
.subcat-link {
    cursor: pointer;
    transition: opacity 0.2s;
    color: var(--link-color);
}

.subcat-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Keyword link in repos table */
.keyword-link {
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s, border-color 0.2s;
    color: var(--link-color);
    text-decoration: none;
}

.keyword-link:hover {
    opacity: 0.95;
    border-color: #93c5fd;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
    text-decoration: underline;
    transform: translateY(-1px);
    background: rgba(59, 130, 246, 0.15);
}

/* Sortable table headers */
.sortable-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.sortable-table th.sortable:hover {
    background: var(--bg-hover);
}

.sortable-table th.sortable .sort-icon {
    font-size: 0.75rem;
    opacity: 0.7;
}

.sortable-table th.sortable.sorted {
    background: var(--bg-hover);
}

/* Repos list cell in subcategory table */
.repos-list-cell {
    font-size: 0.85rem;
    max-width: 500px;
    line-height: 1.6;
}

.repos-list-cell a {
    color: var(--link-color);
    text-decoration: none;
}

.repos-list-cell a:hover {
    text-decoration: underline;
}

/* Multi-select dropdown */
.multi-select-dropdown {
    position: relative;
    display: inline-block;
}

.multi-select-btn {
    padding: 0.5rem 0.75rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 140px;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.multi-select-btn:hover {
    border-color: #555;
}

.multi-select-btn:focus {
    outline: none;
    border-color: var(--link);
}

.multi-select-btn .selected-count {
    background: var(--link);
    color: #000;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
}

.multi-select-btn .selected-count:empty {
    display: none;
}

.multi-select-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 100;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-top: 4px;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.multi-select-dropdown.open .multi-select-menu {
    display: block;
}

.multi-select-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
}

.multi-select-option:hover {
    background: var(--border);
}

.multi-select-option input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.multi-select-option label {
    flex: 1;
    cursor: pointer;
    font-size: 0.85rem;
}

.multi-select-option .color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--card-bg);
    border-radius: 6px;
}

.pagination.pagination-top {
    margin: 0;
    padding: 0;
    background: transparent;
    justify-content: flex-start;
    margin-left: auto;
    flex: 0 0 auto;
}

.page-btn {
    padding: 0.5rem 1rem;
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s, border-color 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: var(--border);
    border-color: var(--text-dim);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    color: var(--text-dim);
    font-size: 0.9rem;
}

.page-info span {
    color: var(--text);
    font-weight: 500;
}

.page-size-select {
    padding: 0.4rem 0.6rem;
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    margin-left: 0.5rem;
}

.page-size-select:hover {
    border-color: var(--text-dim);
}
