* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
        Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2em;
    font-weight: 600;
    margin-bottom: 15px;
}

/* Navigation */
.main-nav {
    display: flex;
    gap: 15px;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.nav-link.active {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Statistics */
.stats-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.stats-header:hover {
    background: #f9f9f9;
}

.stats-header h2 {
    color: #667eea;
    font-size: 1.3em;
    margin: 0;
}

.toggle-icon {
    font-size: 1.2em;
    color: #667eea;
    transition: transform 0.3s;
}

.stats-content {
    margin-top: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    padding: 15px;
    background: #f5f5f5;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
}

.stat-item label {
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.stat-item span {
    font-size: 1.5em;
    color: #667eea;
    font-weight: 700;
}

.stats-tables {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.stat-table {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 6px;
}

.stat-table h3 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.stat-table table {
    width: 100%;
    border-collapse: collapse;
}

.stat-table th {
    background: #667eea;
    color: white;
    padding: 8px;
    text-align: left;
    font-size: 0.9em;
}

.stat-table td {
    padding: 8px;
    border-bottom: 1px solid #ddd;
    font-size: 0.9em;
}

.stat-table tbody tr:hover {
    background: #f0f0f0;
}

/* Filters */
.filters {
    background: white;
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 25px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.filters h2 {
    margin-bottom: 20px;
    color: #667eea;
    font-size: 1.3em;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    align-items: end;
}

.filter-item {
    display: flex;
    flex-direction: column;
}

.filter-item label {
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
    font-size: 0.9em;
}

.filter-item input,
.filter-item select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95em;
    transition: border-color 0.3s;
}

.filter-item input:focus,
.filter-item select:focus {
    outline: none;
    border-color: #667eea;
}

.filter-actions {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-success {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 20px 0;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pagination span {
    font-weight: 500;
    color: #555;
}

/* Threads List */
#threadsSection h2,
#commentsSection h2 {
    margin-bottom: 20px;
    color: #667eea;
    font-size: 1.5em;
}

.threads-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.thread-item {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s;
}

.thread-item:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.thread-info {
    flex: 1;
}

.thread-title {
    font-size: 1.3em;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.thread-title a {
    color: #333;
    text-decoration: none;
    transition: color 0.2s;
}

.thread-title a:hover {
    color: #667eea;
    text-decoration: underline;
}

.thread-meta {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    font-size: 0.9em;
    color: #666;
}

.thread-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.thread-text {
    margin: 15px 0;
    color: #555;
    line-height: 1.7;
}

.thread-url {
    color: #667eea;
    text-decoration: none;
    font-size: 0.95em;
    word-break: break-all;
}

.thread-url:hover {
    text-decoration: underline;
}

.thread-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.thread-actions select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 0.9em;
}

.checkbox-label input[type='checkbox'] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Comments List */
.comments-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Sticky Thread Header for Comments Section */
.sticky-thread-header {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 20px;
    margin: -20px -25px 15px -25px;
    border-radius: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 0.95em;
    font-weight: 600;
    line-height: 1.4;
}

.sticky-thread-header a {
    color: white;
    text-decoration: none;
    transition: opacity 0.2s;
}

.sticky-thread-header a:hover {
    opacity: 0.9;
    text-decoration: underline;
}

/* Adjust for mobile */
@media (max-width: 768px) {
    .sticky-thread-header {
        font-size: 0.85em;
        padding: 10px 15px;
        margin: -20px -20px 15px -20px;
    }
}

.comment-item {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border-left: 4px solid #667eea;
}

.comment-item.comment-unread {
    background: #fff9c4;
    border-left-color: #ffa000;
}

.comment-item.comment-today {
    background: #e1bee7;
    border-left-color: #9c27b0;
}

.comment-row {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.comment-row:last-of-type {
    border-bottom: none;
}

.comment-header-row {
    margin-bottom: 10px;
}

.comment-meta-line {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.9em;
}

.comment-author {
    font-weight: 600;
    color: #667eea;
}

.comment-time {
    color: #999;
    font-size: 0.85em;
}

.comment-badge {
    background: #f0f0f0;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85em;
}

.comment-body,
.comment-short-conclusion,
.comment-full-conclusion,
.comment-translation {
    color: #555;
    line-height: 1.6;
}

.expandable-text.truncated {
    cursor: pointer;
}

.expandable-text.truncated:hover {
    background: #f9f9f9;
}

.comment-permalink {
    color: #667eea;
    text-decoration: none;
    font-size: 1em;
}

.comment-permalink:hover {
    text-decoration: underline;
}

.comment-actions {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.copy-actions select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

.copy-actions select:hover {
    border-color: #667eea;
}

.copy-actions select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    font-size: 1.2em;
    color: #667eea;
}

/* Responsive */
@media (max-width: 768px) {
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .thread-header {
        flex-direction: column;
    }

    .thread-item {
        padding: 20px;
    }

    .comment-row-1 {
        grid-template-columns: 1fr;
    }
}

/* Knowledge Base */
.entry-item {
    background: white;
    padding: 30px 35px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
    transition: all 0.2s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.entry-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    border-color: rgba(102, 126, 234, 0.2);
}

.entry-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;
}

.entry-info {
    flex: 1;
}

.entry-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.875em;
    color: #666;
}

.entry-category {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 5px 14px;
    border-radius: 16px;
    font-size: 0.8em;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.entry-time {
    color: #999;
    font-size: 0.85em;
}

.entry-url-link {
    color: #667eea;
    text-decoration: none;
    font-size: 0.85em;
    transition: color 0.2s;
}

.entry-url-link:hover {
    color: #5568d3;
    text-decoration: underline;
}

.entry-scores {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 6px;
}

.entry-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.entry-actions {
    display: flex;
    gap: 8px;
}

.entry-key-insight {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border-left: 3px solid #667eea;
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 0 6px 6px 0;
    font-size: 0.9em;
    color: #374151;
    line-height: 1.5;
}

.insight-label {
    font-weight: 600;
    color: #667eea;
    margin-right: 6px;
}

.entry-notes-preview {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    padding: 10px 14px;
    margin-top: 12px;
    border-radius: 6px;
    font-size: 0.85em;
    color: #78350f;
    line-height: 1.5;
}

.notes-label {
    font-weight: 600;
    color: #92400e;
    margin-right: 6px;
}

.entry-content {
    color: #374151;
    line-height: 1.75;
    font-size: 1em;
}

.entry-content.truncated {
    cursor: pointer;
}

.entry-content.truncated .text-content {
    display: block;
}

.entry-content.truncated .text-full {
    display: none;
}

.entry-content h1,
.entry-content h2,
.entry-content h3 {
    color: #1f2937;
    font-weight: 600;
    margin: 24px 0 12px 0;
    line-height: 1.4;
}

.entry-content h1 {
    font-size: 1.75em;
    margin-top: 0;
    padding-top: 0;
}

.entry-content h2 {
    font-size: 1.5em;
    margin-top: 32px;
}

.entry-content h3 {
    font-size: 1.25em;
    margin-top: 24px;
}

.entry-content p {
    margin: 16px 0;
    line-height: 1.75;
}

.entry-content ul,
.entry-content ol {
    margin: 16px 0;
    padding-left: 28px;
}

.entry-content li {
    margin: 8px 0;
    line-height: 1.75;
}

.entry-content ul li {
    list-style-type: disc;
}

.entry-content ol li {
    list-style-type: decimal;
}

.entry-content code {
    background: #f3f4f6;
    color: #e74c3c;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'Courier New', monospace;
    font-size: 0.9em;
    border: 1px solid #e5e7eb;
}

.entry-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 20px 0;
    line-height: 1.6;
    border: 1px solid #334155;
}

.entry-content pre code {
    background: none;
    color: #e2e8f0;
    padding: 0;
    border: none;
    font-size: 0.875em;
}

.entry-content a {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s;
}

.entry-content a:hover {
    color: #5568d3;
    border-bottom-color: #5568d3;
}

.entry-content strong {
    font-weight: 600;
    color: #1f2937;
}

.entry-content em {
    font-style: italic;
    color: #4b5563;
}

.entry-content blockquote {
    border-left: 4px solid #667eea;
    margin: 20px 0;
    padding: 12px 20px;
    background: #f9fafb;
    color: #4b5563;
    font-style: italic;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85em;
}

.btn-preview {
    background: #667eea;
    color: white;
}

.btn-preview:hover {
    background: #5568d3;
}

.knowledge-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    align-items: end;
}

.entry-title {
    font-size: 1.4em;
    font-weight: 600;
    color: #1f2937;
    margin: 16px 0;
    line-height: 1.4;
}

/* Mobile responsiveness for entry items */
@media (max-width: 768px) {
    .entry-item {
        padding: 20px 16px;
    }

    .entry-header {
        flex-direction: column;
        gap: 12px;
    }

    .entry-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .entry-title {
        font-size: 1.2em;
        margin: 12px 0;
    }

    .entry-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .entry-item {
        padding: 16px 12px;
    }

    .entry-title {
        font-size: 1.1em;
    }

    .entry-actions {
        flex-wrap: wrap;
    }

    .btn-small {
        padding: 5px 10px;
        font-size: 0.8em;
    }
}

/* Distilled Knowledge Styles */
.distilled-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.distilled-item {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s;
    cursor: pointer;
}

.distilled-item:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.distilled-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

.distilled-field {
    margin-bottom: 12px;
}

.distilled-field label {
    font-weight: 600;
    color: #667eea;
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.distilled-field p {
    color: #555;
    line-height: 1.6;
    margin: 0;
}

.distilled-meta {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
    font-size: 0.85em;
    color: #999;
}

.distilled-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.preview-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
}

.preview-section h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.2em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.preview-field {
    margin-bottom: 15px;
}

.preview-field label {
    font-weight: 600;
    color: #555;
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.preview-field p {
    color: #333;
    line-height: 1.7;
    margin: 0;
    white-space: pre-wrap;
}

.preview-field .badge {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
}

/* Parsed key-value tables */
.parsed-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    background: white;
    border-radius: 6px;
    overflow: hidden;
}

.parsed-table tr {
    border-bottom: 1px solid #e0e0e0;
}

.parsed-table tr:last-child {
    border-bottom: none;
}

.parsed-table td {
    padding: 12px 15px;
    vertical-align: top;
}

.parsed-table td:first-child {
    font-weight: 600;
    color: #667eea;
    width: 30%;
    background: #f5f5f5;
}

.parsed-table td:last-child {
    color: #333;
    line-height: 1.6;
}

/* Reddit link style */
.reddit-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.reddit-link:hover {
    color: #5568d3;
    text-decoration: underline;
}

/* Mobile responsiveness for distilled */
@media (max-width: 768px) {
    .distilled-item {
        padding: 20px;
    }

    .parsed-table td:first-child {
        width: 40%;
        font-size: 0.85em;
    }

    .parsed-table td {
        padding: 10px;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: white;
    margin: 50px auto;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    color: #667eea;
    font-size: 1.5em;
}

.btn-close-modal {
    background: transparent;
    border: none;
    font-size: 1.5em;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-close-modal:hover {
    background: #f0f0f0;
    color: #333;
}

.modal-body {
    padding: 25px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px 25px;
    border-top: 1px solid #e0e0e0;
}

/* Mobile responsiveness for modal */
@media (max-width: 768px) {
    .modal-content {
        margin: 20px auto;
        width: 95%;
    }

    .modal-header {
        padding: 15px 20px;
    }

    .modal-header h2 {
        font-size: 1.3em;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        padding: 15px 20px;
        flex-wrap: wrap;
    }

    .modal-footer button {
        flex: 1;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        margin: 10px;
        width: calc(100% - 20px);
    }

    .modal-header h2 {
        font-size: 1.2em;
    }

    .modal-body {
        padding: 15px;
    }
}
