:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #dbeafe;
    --accent: #0ea5e9;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --success: #059669;
    --success-bg: #d1fae5;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --info: #2563eb;
    --info-bg: #dbeafe;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

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

a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

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

/* Header */
.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    gap: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}

.logo:hover {
    text-decoration: none;
}

.logo-icon {
    color: var(--accent);
    font-size: 1.4rem;
}

.main-nav {
    display: flex;
    gap: 24px;
}

.main-nav a {
    color: var(--text);
    font-weight: 500;
    font-size: 0.95rem;
}

.main-nav a:hover {
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-form {
    display: flex;
    align-items: center;
}

.search-form input {
    width: 180px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius) 0 0 var(--radius);
    border-right: none;
    font-size: 0.9rem;
    outline: none;
}

.search-form button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 var(--radius) var(--radius) 0;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.search-form button:hover {
    background: var(--border-light);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.username {
    font-weight: 600;
    color: var(--text);
}

.admin-link {
    color: var(--warning);
    font-weight: 600;
}

.logout-link {
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.btn-outline {
    background: #fff;
    color: var(--primary);
    border-color: var(--primary);
}

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

/* Main */
.main-content {
    min-height: calc(100vh - 120px);
    padding: 24px 0 40px;
}

/* Alerts */
.flash-messages {
    margin-bottom: 20px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert-info { background: var(--info-bg); color: var(--info); }

/* Layout grids */
.two-column {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 24px;
}

@media (max-width: 900px) {
    .two-column {
        grid-template-columns: 1fr;
    }
    .main-nav { display: none; }
    .search-form { display: none; }
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.card-body {
    padding: 20px;
}

/* Post list */
.post-list {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.post-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    gap: 16px;
    align-items: flex-start;
    transition: background 0.15s ease;
}

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

.post-item:hover {
    background: #fafafa;
}

.vote-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 40px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.vote-box .count {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
}

.post-meta {
    flex: 1;
    min-width: 0;
}

.post-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 6px;
    line-height: 1.4;
}

.post-title a {
    color: inherit;
}

.post-title a:hover {
    color: var(--primary);
}

.post-excerpt {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 0 8px;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.post-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.post-info .node-tag {
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.post-info .author {
    color: var(--text-secondary);
    font-weight: 500;
}

.pinned-badge {
    background: var(--warning-bg);
    color: var(--warning);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 6px;
}

/* Sidebar */
.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 12px;
}

.node-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.node-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: all 0.15s ease;
}

.node-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    text-decoration: none;
    color: var(--primary);
}

.node-item .count {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 12px;
}

/* Forms */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: #fff;
    transition: border-color 0.15s ease;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

textarea.form-control {
    min-height: 160px;
    resize: vertical;
    line-height: 1.6;
}

select.form-control {
    height: 42px;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Auth pages */
.auth-card {
    max-width: 420px;
    margin: 40px auto;
}

.auth-card .card-body {
    padding: 32px;
}

.auth-title {
    text-align: center;
    margin: 0 0 24px;
    font-size: 1.4rem;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Post detail */
.post-detail {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.post-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-light);
}

.post-header h1 {
    margin: 0 0 12px;
    font-size: 1.5rem;
    line-height: 1.4;
}

.post-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.post-actions form {
    display: inline;
}

.post-body {
    padding: 24px;
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text);
}

.post-body p {
    margin: 0 0 16px;
}

.post-body h2, .post-body h3, .post-body h4 {
    margin-top: 24px;
    margin-bottom: 12px;
    color: var(--text);
}

.post-body pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 0.9rem;
}

.post-body code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.9em;
}

.post-body pre code {
    background: transparent;
    padding: 0;
}

.post-body blockquote {
    border-left: 4px solid var(--primary);
    margin: 16px 0;
    padding: 8px 16px;
    background: var(--primary-light);
    color: var(--primary-dark);
}

.post-body ul, .post-body ol {
    margin: 0 0 16px;
    padding-left: 24px;
}

.post-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.post-body th, .post-body td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.post-body th {
    background: var(--bg);
}

/* Replies */
.replies-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
}

.replies-section h3 {
    margin: 0 0 20px;
    font-size: 1.1rem;
}

.reply-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
}

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

.reply-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.reply-author {
    font-weight: 600;
    color: var(--text);
}

.reply-content {
    color: var(--text);
    line-height: 1.7;
}

.reply-form {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg-card);
}

.pagination a:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    text-decoration: none;
}

.pagination .current {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pagination .disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Sort tabs */
.sort-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.sort-tabs a {
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.sort-tabs a.active {
    background: var(--primary);
    color: #fff;
}

.sort-tabs a:hover {
    text-decoration: none;
    background: var(--primary-light);
    color: var(--primary);
}

.sort-tabs a.active:hover {
    background: var(--primary);
    color: #fff;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

.empty-state h3 {
    margin: 0 0 8px;
    color: var(--text);
}

/* Admin dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-card .number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.admin-section {
    margin-bottom: 32px;
}

.admin-section h3 {
    margin: 0 0 16px;
    font-size: 1.1rem;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th, .data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.data-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
}

/* Profile */
.profile-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
}

.avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
}

.profile-info h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
}

.profile-info p {
    margin: 0;
    color: var(--text-secondary);
}

.profile-stats {
    display: flex;
    gap: 24px;
    margin-top: 12px;
}

.profile-stats span {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.profile-stats strong {
    color: var(--text);
}

/* Footer */
.site-footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 24px 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.site-footer p {
    margin: 4px 0;
}

.footer-links .sep {
    margin: 0 8px;
    color: var(--border);
}
