/* Base styles */
:root {
    --primary-color: #8B4513;
    --primary-dark: #5D2E0C;
    --accent-color: #C4A35A;
    --bg-color: #FAF8F5;
    --card-bg: #FFFFFF;
    --text-color: #333333;
    --text-muted: #666666;
    --border-color: #E0DCD5;
    --highlight-bg: #FFF9E6;
    --sidebar-bg: #F5F3F0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

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

/* Main content */
main {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
}

/* Search container */
.search-container {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 1rem;
}

.search-box {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-box input {
    flex: 1;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-box button {
    padding: 0.875rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-box button:hover {
    background: var(--primary-dark);
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.filter-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
}

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

/* Stats bar */
.stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Content wrapper */
.content-wrapper {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
}

/* Sidebar */
.sidebar {
    background: var(--sidebar-bg);
    border-radius: 12px;
    padding: 1.25rem;
    height: fit-content;
    position: sticky;
    top: 1rem;
}

.sidebar h3 {
    font-size: 0.95rem;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.topic-list {
    list-style: none;
    max-height: 400px;
    overflow-y: auto;
}

.topic-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.topic-list li:last-child {
    border-bottom: none;
}

.topic-list a {
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topic-list a:hover {
    color: var(--primary-color);
}

.topic-list .count {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--border-color);
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
}

.sidebar-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.source-note {
    font-style: italic;
}

/* Results */
.results-container {
    min-height: 400px;
}

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

.welcome-message {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
}

.welcome-message h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.welcome-message p {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.search-suggestions {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

.search-suggestions a {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--highlight-bg);
    color: var(--primary-color);
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.search-suggestions a:hover {
    background: var(--accent-color);
    color: white;
}

/* Topic grid for welcome page */
.search-suggestions.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.5rem;
    text-align: left;
    max-width: 900px;
    margin: 1.5rem auto 0;
}

.search-suggestions.topic-grid li {
    margin: 0;
}

.search-suggestions.topic-grid a {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.4;
}

.search-suggestions .topic-count {
    color: var(--text-muted);
    font-size: 0.8rem;
    opacity: 0.8;
}

.search-suggestions.topic-grid a:hover .topic-count {
    color: rgba(255,255,255,0.8);
}

/* Post card */
.post-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s;
}

.post-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.post-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    gap: 1rem;
}

.post-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    flex: 1;
}

.post-title:hover {
    text-decoration: underline;
}

.post-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.post-source {
    background: var(--accent-color);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.post-source.esangha {
    background: #6B8E23;
}

.post-preview {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
    overflow: hidden;
    max-height: 4.5em;
}

.post-preview mark {
    background: var(--highlight-bg);
    color: var(--text-color);
    padding: 0 2px;
    border-radius: 2px;
}

.post-expand {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.expand-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0;
}

.expand-btn:hover {
    text-decoration: underline;
}

.dharmawheel-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    margin-left: 1rem;
    opacity: 0.8;
}

.dharmawheel-link:hover {
    text-decoration: underline;
    opacity: 1;
}

.post-full-content {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 8px;
    white-space: pre-wrap;
    font-size: 0.95rem;
    line-height: 1.7;
    max-height: 500px;
    overflow-y: auto;
}

.post-full-content mark {
    background: #FFEB3B;
    padding: 0 2px;
    border-radius: 2px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    padding: 1rem;
}

.pagination button {
    padding: 0.625rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

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

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    max-width: 800px;
    max-height: 90vh;
    width: 100%;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:hover {
    background: var(--border-color);
}

#modal-body {
    padding: 2rem;
}

#modal-body h2 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    padding-right: 2rem;
}

#modal-body .modal-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#modal-body .modal-content-text {
    white-space: pre-wrap;
    line-height: 1.8;
}

#modal-body .modal-content-text mark {
    background: #FFEB3B;
    padding: 0 2px;
    border-radius: 2px;
}

/* Footer */
footer {
    background: var(--sidebar-bg);
    padding: 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2rem;
}

footer a {
    color: var(--primary-color);
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 900px) {
    .content-wrapper {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        order: -1;
    }

    .topic-list {
        max-height: 200px;
    }
}

@media (max-width: 600px) {
    header {
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    main {
        padding: 1rem;
    }

    .search-container {
        padding: 1rem;
    }

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

    .post-header {
        flex-direction: column;
    }

    .post-meta {
        flex-wrap: wrap;
    }
}

/* No results */
.no-results {
    text-align: center;
    padding: 3rem;
    background: var(--card-bg);
    border-radius: 12px;
}

.no-results h3 {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.no-results p {
    color: var(--text-muted);
    font-size: 0.9rem;
}
