/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

/* Login Screen */
.login-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color), #7c3aed);
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 500px;
    width: 95%;
}

.login-box h1 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}


.login-box>p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.login-notice {
    background-color: #f1f5f9;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #e2e8f0;
}

.login-notice p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-box input[type="password"] {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.login-box input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.login-box button {
    padding: 12px;
    font-size: 1rem;
    width: 100%;
}

.login-error {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 12px;
    min-height: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary-color), #7c3aed);
    color: white;
    border-radius: 12px;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.header .subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

.header .source-info {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: 8px;
}

/* Search Section */
.search-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.search-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.search-group {
    flex: 1;
}

.search-group.full-width {
    flex: 1 1 100%;
}

.search-group label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.search-group input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* AI Search Toggle */
.keyword-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: #9333ea;
    /* Purple for AI */
}

input:focus+.slider {
    box-shadow: 0 0 1px #9333ea;
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* AI Progress Bar */
.ai-progress {
    margin-top: 12px;
    animation: fadeIn 0.3s;
}

.ai-progress.hidden {
    display: none;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #9333ea;
    font-weight: 600;
    margin-bottom: 4px;
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background-color: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background-color: #9333ea;
    transition: width 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Filter Row */
.filter-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.filter-group {
    flex: 1;
    min-width: 200px;
}

.filter-group label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 400;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.date-range,
.duration-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-range input,
.duration-range input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
}

.date-range input:focus,
.duration-range input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Action Row */
.action-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

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

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

/* Results Info */
.results-info {
    padding: 16px 20px;
    background: var(--card-bg);
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 600;
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

/* Word Cloud Container */
.wordcloud-container {
    overflow: hidden;
}

#wordCloud {
    width: 100%;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#wordCloud text {
    cursor: pointer;
    transition: opacity 0.2s;
}

#wordCloud text:hover {
    opacity: 0.7;
}

.chart-container {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    height: 280px;
}

.chart-container h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.chart-container canvas {
    max-height: 200px;
    cursor: pointer;
}

/* Table Section */
.table-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.table-wrapper {
    overflow-x: auto;
}

#resultsTable {
    width: 100%;
    border-collapse: collapse;
}

#resultsTable th {
    background: var(--bg-color);
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

#resultsTable th:hover {
    background: #e2e8f0;
}

#resultsTable th[data-sort] {
    position: relative;
    padding-right: 28px;
}

#resultsTable th[data-sort]::after {
    content: '⇅';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
    font-size: 0.75rem;
}

#resultsTable th[data-sort]:hover::after {
    opacity: 0.6;
}

#resultsTable th.sort-asc::after {
    content: '▲';
    opacity: 1;
    color: var(--primary-color);
}

#resultsTable th.sort-desc::after {
    content: '▼';
    opacity: 1;
    color: var(--primary-color);
}

#resultsTable th .sort-icon {
    display: none;
}

#resultsTable td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

#resultsTable tbody tr {
    cursor: pointer;
    transition: background-color 0.15s;
}

#resultsTable tbody tr:hover {
    background-color: #f1f5f9;
}

.title-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pi-cell.clickable {
    color: var(--primary-color);
    cursor: pointer;
    transition: color 0.2s;
}

.pi-cell.clickable:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.in-progress {
    background: #dbeafe;
    color: #1d4ed8;
}

.status-badge.completed {
    background: #dcfce7;
    color: #166534;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 800px;
    max-height: 80vh;
    width: 90%;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

#modalBody h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    line-height: 1.4;
}

.detail-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 12px 20px;
    margin-bottom: 20px;
}

.detail-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.detail-value {
    color: var(--text-primary);
    font-size: 0.875rem;
    word-break: break-word;
}

.detail-value a {
    color: var(--primary-color);
    text-decoration: none;
}

.detail-value a:hover {
    text-decoration: underline;
}

.abstract-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.abstract-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.abstract-section p {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-primary);
}

/* Chart Modal */
.chart-modal-content {
    max-width: 900px;
    max-height: 85vh;
}

.chart-modal-content h2 {
    font-size: 1.1rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.chart-modal-container {
    height: 500px;
    position: relative;
}

.chart-modal-container canvas {
    max-height: 100%;
}

/* Chart container clickable */
.chart-container {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chart-container:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Choices.js Custom Styles */
.choices {
    margin-bottom: 0;
}

.choices__inner {
    min-height: 46px;
    border-color: var(--border-color);
    border-radius: 8px;
    background: white;
    padding: 6px 8px;
}

.choices__list--multiple .choices__item {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.choices__input {
    background: white;
}

.choices__list--dropdown {
    border-color: var(--border-color);
    border-radius: 8px;
}

.choices__list--dropdown .choices__item--selectable.is-highlighted {
    background-color: #f1f5f9;
}

/* Responsive */
@media (max-width: 1200px) {
    .charts-section {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1024px) {
    .charts-section {
        grid-template-columns: 1fr;
    }

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

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

@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .action-row {
        flex-direction: column;
        gap: 12px;
    }

    .export-buttons {
        width: 100%;
    }

    .export-buttons .btn {
        flex: 1;
    }

    #resultsTable th,
    #resultsTable td {
        padding: 10px 12px;
    }
}