/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --max-width: 800px;
}

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

.bg-wrapper {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    overflow: hidden;
    background: #dce4ec;
}
.bg-blur {
    position: absolute;
    top: -20px; left: -20px; right: -20px; bottom: -20px;
    background: center / cover no-repeat;
}
.bg-blur::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.55);
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-hover); }

/* === Keyframes === */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); max-height: 0; }
    to   { opacity: 1; transform: translateY(0); max-height: 60px; }
}
@keyframes subtlePulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.03); }
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* === Navbar === */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 14px 0 18px 0;
    margin-bottom: 8px;
}
.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text) !important;
    transition: opacity 0.2s;
}
.logo:hover { opacity: 0.7; }
.nav-links a {
    margin-left: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    position: relative;
    transition: color 0.2s;
}
.nav-links a::after {
    content: '';
    position: absolute;
    bottom: -8px; left: 0; right: 0;
    height: 2px;
    background: var(--primary);
    transform: scaleX(0);
    transition: transform 0.25s;
}
.nav-links a:hover { color: var(--primary); }
.nav-links a:hover::after { transform: scaleX(1); }
.nav-avatar-link::after { display: none; }
.nav-user {
    margin-left: 8px;
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 500;
}
.nav-avatar-link { margin-left: 16px; }
.nav-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
    border: 2px solid var(--border);
    transition: border-color 0.2s, transform 0.2s;
}
.nav-avatar:hover { border-color: var(--primary); transform: scale(1.1); }
.nav-avatar-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Avatar page */
.avatar-preview-large {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto;
    border: 3px solid var(--border);
}
.avatar-preview-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 2.5rem;
    font-weight: 700;
}

/* Avatar in comments */
.comment-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.comment-avatar-text {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* === Main === */
main {
    flex: 1;
    padding: 56px 0 48px;
    animation: fadeInUp 0.5s ease;
}

/* === Flash Messages === */
.flash-messages { margin-bottom: 24px; }
.flash-msg {
    background: #dbeafe;
    color: #1e40af;
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 0.9rem;
    animation: slideDown 0.35s ease;
    overflow: hidden;
}

/* === Search === */
.search-form {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
}
.search-box {
    display: flex;
    align-items: center;
    max-width: 380px;
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.search-input {
    flex: 1;
    min-width: 0;
    padding: 10px 16px;
    border: none;
    font-size: 0.9rem;
    font-family: inherit;
    background: transparent;
    color: var(--text);
    outline: none;
}
.search-input::placeholder { color: #94a3b8; }
.search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 4px;
}
.search-btn:hover {
    color: var(--primary);
    background: #eff6ff;
}
.search-clear {
    margin-left: 12px;
    font-size: 0.85rem;
    white-space: nowrap;
    color: var(--text-secondary);
    transition: color 0.15s;
}
.search-clear:hover { color: var(--danger); }
.search-info {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/* === Blog Header === */
.blog-header {
    text-align: center;
    padding: 40px 0 32px;
}
.blog-header h1 { font-size: 2rem; margin-bottom: 8px; }
.subtitle { color: var(--text-secondary); font-size: 1.05rem; }

/* === Home Layout === */
.home-main { max-width: var(--max-width); margin: 0 auto; }

/* === Profile Widget === */
.home-sidebar {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 200px;
    z-index: 10;
}
.profile-widget {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    animation: fadeInUp 0.4s ease both;
}
.profile-tab { display: none; }
.profile-title {
    font-size: 0.95rem;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
    color: var(--text);
    text-align: center;
}
.profile-content {
    font-size: 0.83rem;
    line-height: 1.7;
    color: #64748b;
    text-align: center;
}

/* === Article List === */
.article-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: fadeInUp 0.4s ease both;
}
.article-card:nth-child(1) { animation-delay: 0.05s; }
.article-card:nth-child(2) { animation-delay: 0.1s; }
.article-card:nth-child(3) { animation-delay: 0.15s; }
.article-card:nth-child(4) { animation-delay: 0.2s; }
.article-card:nth-child(5) { animation-delay: 0.25s; }
.article-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.article-card.has-thumbnail {
    display: flex;
    gap: 20px;
    align-items: center;
}
.article-card-body { flex: 1; min-width: 0; }
.article-thumb {
    flex-shrink: 0;
    width: 120px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    display: block;
}
.article-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}
.article-thumb:hover img { transform: scale(1.08); }
.article-card h2 { font-size: 1.25rem; margin-bottom: 8px; }
.article-card .meta { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; }
.article-card.pinned {
    border-left: 3px solid #f59e0b;
    background: #fffbeb;
}

/* Pin badge */
.pin-badge {
    display: inline-block;
    background: #f59e0b;
    color: #fff;
    font-size: 0.7rem;
    padding: 1px 8px;
    border-radius: 10px;
    font-weight: 600;
    margin-right: 4px;
    vertical-align: middle;
}
.pin-badge-small { font-size: 0.65rem; padding: 1px 6px; }

.pinned-row { background: #fffbeb; }
.pin-on, .pin-on:hover {
    background: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}
.pin-off { color: var(--text-secondary); }
.article-card .summary { font-size: 0.95rem; color: #475569; margin-bottom: 12px; }
.read-more { font-size: 0.9rem; transition: margin-left 0.2s; }
.read-more:hover { margin-left: 4px; }

/* === Single Article === */
.single-article {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    margin-bottom: 24px;
}
.single-article h1 { font-size: 1.75rem; margin-bottom: 8px; }
.single-article .meta { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 24px; }
.single-article .content { font-size: 1rem; line-height: 1.9; }
.single-article .content p { margin-bottom: 16px; }
.single-article .content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    border-radius: 6px;
    max-height: 600px;
    object-fit: contain;
    transition: transform 0.3s, box-shadow 0.3s;
    animation: fadeIn 0.5s ease;
}
.single-article .content img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

/* === Comments === */
.comments-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}
.comments-section h3 { margin-bottom: 16px; }
.comment-list { list-style: none; }
.comment {
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    animation: fadeIn 0.3s ease both;
}
.comment:nth-child(1) { animation-delay: 0.03s; }
.comment:nth-child(2) { animation-delay: 0.06s; }
.comment:nth-child(3) { animation-delay: 0.09s; }
.comment:nth-child(4) { animation-delay: 0.12s; }
.comment:nth-child(5) { animation-delay: 0.15s; }
.comment:last-child { border-bottom: none; }
.comment-body {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.comment-main { flex: 1; min-width: 0; }
.comment-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 4px;
    flex-wrap: wrap;
    gap: 4px;
}
.comment-header time { color: var(--text-secondary); }
.comment-header .comment-author { display: flex; align-items: center; gap: 8px; }
.comment-meta-right { display: flex; align-items: center; gap: 12px; }
.comment p { font-size: 0.95rem; }
.no-comments { color: var(--text-secondary); font-size: 0.9rem; }

/* Admin comment highlight */
.comment.comment-admin {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
    padding: 12px 16px 12px 12px;
    margin-left: -12px;
    border-radius: 0 6px 6px 0;
}
.admin-badge {
    display: inline-block;
    background: #f59e0b;
    color: #fff;
    font-size: 0.7rem;
    padding: 1px 8px;
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.delete-comment-form { display: inline; }
.btn-delete-comment {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
}
.btn-delete-comment:hover { color: var(--danger); }

.comment-form {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.comment-form h4 { margin-bottom: 12px; }
.comment-as { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 12px; }
.comment-login-hint {
    margin-top: 20px;
    padding: 16px;
    background: #f0f9ff;
    border-radius: var(--radius);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.comment-login-hint a { font-weight: 500; }

/* Pinned comment */
.comment.comment-pinned {
    border-left: 3px solid #f59e0b;
    padding: 12px 16px 12px 12px;
    border-radius: 0 6px 6px 0;
}

/* Reply list (nested) */
.reply-list {
    list-style: none;
    margin-left: 32px;
    border-left: 2px solid var(--border);
    padding-left: 12px;
    margin-top: 8px;
}
.reply {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.reply:last-child { border-bottom: none; }
.reply-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.reply-avatar-text {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}
.reply .comment-body { gap: 8px; }
.reply .comment-content-text { font-size: 0.9rem; }

/* Reply button */
.btn-reply {
    background: none;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 3px 12px;
    margin-top: 8px;
    border-radius: 14px;
    transition: all 0.18s;
}
.btn-reply:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: #eff6ff;
}

/* Reply inline form */
.reply-form {
    margin-top: 8px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.reply-form-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
}

/* Edit inline form */
.edit-form {
    margin-top: 8px;
    padding: 12px;
    background: #fffbeb;
    border-radius: 6px;
    border: 1px solid #fde68a;
}
.edit-form-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
}

/* Edit / Delete text buttons — inherit .btn-small layout, only recolor */
.btn-edit-comment {
    color: var(--text-secondary);
    border-color: transparent;
    background: none;
}
.btn-edit-comment:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: #eff6ff;
}

.btn-delete-comment {
    color: #94a3b8;
    border-color: transparent;
    background: none;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 12px;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: all 0.18s;
}
.btn-delete-comment:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: #fef2f2;
}

/* Primary small button (for form submits) */
.btn-small.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-small.btn-primary:hover {
    background: var(--primary-hover);
}

/* Small input */
.input-sm {
    padding: 6px 10px;
    font-size: 0.85rem;
    margin-bottom: 0;
    width: auto;
    flex: 1;
    min-width: 0;
}

/* === File Input === */
.file-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}
.file-input-wrap input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.file-input-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    background: var(--card-bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
}
.file-input-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}
.file-input-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* === Forms === */
.input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    margin-bottom: 12px;
    font-family: inherit;
    transition: border-color 0.15s;
}
.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    background: var(--primary);
    color: #fff !important;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: var(--text) !important; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-small {
    display: inline-block;
    padding: 4px 12px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    cursor: pointer;
    color: var(--text);
}
.btn-small:hover { background: var(--bg); }
.btn-small.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-small.btn-danger:hover { background: #fef2f2; }

/* === Admin === */
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.admin-actions { display: flex; gap: 8px; }
.admin-container {
    max-width: 600px;
    margin: 0 auto;
}
.admin-form {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}
.admin-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9rem;
}
.form-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* === Quill Editor === */
.quill-editor {
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 0;
}
.ql-toolbar.ql-snow {
    border-color: var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
}
.ql-container.ql-snow {
    border-color: var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    min-height: 400px;
    font-size: 1rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
}
.ql-editor img {
    max-width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: contain;
    border-radius: 4px;
    margin: 8px 0;
}

/* === Attachment Card (in editor + published article) === */
.attachment-card {
    margin: 16px 0;
}
.attachment-card a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    text-decoration: none;
    color: #1e293b;
    transition: all 0.25s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.attachment-card a:hover {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1e293b;
    box-shadow: 0 6px 16px rgba(59,130,246,0.12);
    transform: translateY(-2px);
}
.att-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #dbeafe;
    color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.attachment-card a:hover .att-icon {
    transform: scale(1.08);
}
.att-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.att-name {
    font-size: 0.92rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.att-size {
    font-size: 0.78rem;
    color: #64748b;
}
.att-dl-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: #3b82f6;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}
.attachment-card a:hover .att-dl-btn {
    background: #2563eb;
    transform: scale(1.1);
}

/* === Image Resize Toolbar === */
.img-size-bar {
    display: none;
    position: fixed;
    z-index: 9999;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    gap: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    white-space: nowrap;
}
.img-size-bar.show { display: flex; align-items: center; }
.img-size-bar button {
    display: inline-block;
    padding: 5px 12px;
    font-size: 0.82rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    cursor: pointer;
    color: var(--text);
    transition: all 0.18s;
    font-family: inherit;
}
.img-size-bar button:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.img-size-bar .img-size-input {
    width: 60px;
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    text-align: center;
    font-family: inherit;
    transition: border-color 0.15s;
}
.img-size-bar .img-size-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.img-size-bar .img-size-sep {
    width: 1px; height: 22px; background: var(--border); margin: 0 4px;
}

/* === Upload === */
.upload-area {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}
.upload-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.upload-status {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.user-table td, .user-table th {
    vertical-align: middle;
}
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.admin-table th, .admin-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    transition: background 0.15s;
}
.admin-table tbody tr { transition: background 0.15s; }
.admin-table tbody tr:hover { background: #f8fafc; }
.admin-table th { background: #f1f5f9; font-weight: 600; }
.admin-table .actions { white-space: nowrap; }
.admin-table .comment-content { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Pagination === */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
}
.page-link {
    display: inline-block;
    width: 36px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text);
    transition: background 0.2s, transform 0.2s, color 0.2s;
}
.page-link:hover { background: var(--bg); transform: translateY(-1px); }
.page-link.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* === Footer === */
footer {
    text-align: center;
    padding: 24px 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

/* === Background === */
.bg-preview-wrap { text-align: center; margin-bottom: 16px; }
.bg-preview-wrap h4 { margin-bottom: 12px; }
.bg-preview-img {
    max-width: 100%;
    max-height: 240px;
    border-radius: 8px;
    border: 1px solid var(--border);
    object-fit: cover;
}
.bg-preview-url { font-size: 0.8rem; color: var(--text-secondary); margin-top: 8px; word-break: break-all; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.blur-form { text-align: center; margin-bottom: 16px; }
.blur-form label { display: block; margin-bottom: 8px; }
.blur-row {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 360px;
    margin: 0 auto 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.blur-row input[type="range"] { flex: 1; accent-color: var(--primary); }

/* === Captcha === */
.captcha-row {
    display: flex;
    gap: 10px;
    align-items: center;
}
.captcha-input { flex: 1; margin-bottom: 0 !important; }
.captcha-img {
    height: 58px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.captcha-img:hover { opacity: 0.8; }
.captcha-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 4px;
    margin-bottom: 8px;
}

/* === Media Modal === */
.media-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
}
.media-modal-bg {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
}
.media-modal-body {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 560px;
    max-height: 75vh;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.media-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.media-modal-header h4 { margin: 0; }
.media-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    line-height: 1;
}
.media-close:hover { color: var(--text); }
.media-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
}
.media-item {
    aspect-ratio: 4/3;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s;
    background: #f1f5f9;
}
.media-item:hover { border-color: var(--primary); }
.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
@media (max-width: 640px) {
    .media-grid { grid-template-columns: repeat(4, 1fr); }
}

/* === Image Management === */
.img-preview-thumb {
    width: 64px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    display: block;
    transition: opacity 0.2s;
}
.img-preview-thumb:hover { opacity: 0.7; }
.img-filename {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.status-used { color: #16a34a; font-size: 0.85rem; font-weight: 500; }
.status-unused { color: var(--text-secondary); font-size: 0.85rem; }
.user-avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
    display: block;
}
.user-avatar-txt {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    vertical-align: middle;
}

/* === Misc === */
.empty-state {
    text-align: center;
    padding: 60px 0;
    color: var(--text-secondary);
}
.back-link { margin-top: 24px; font-size: 0.9rem; }

/* === Responsive === */

@media (max-width: 640px) {
    /* --- Layout --- */
    .container { padding: 0 16px; }
    main { padding: 32px 0 36px; }
    .home-layout { flex-direction: column; }
    .home-sidebar {
        display: block;
        position: static;
        width: 100%;
        margin-bottom: 16px;
        transform: none;
    }
    .profile-widget {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        cursor: default;
    }
    .profile-tab { display: none; }
    .profile-title {
        font-size: 0.85rem;
        white-space: nowrap;
        flex-shrink: 0;
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
    }
    .profile-content {
        font-size: 0.78rem;
        line-height: 1.4;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* --- Navbar --- */
    .navbar .container { flex-wrap: wrap; gap: 8px; }
    .nav-links { display: flex; flex-wrap: wrap; gap: 6px; }
    .nav-links a { margin-left: 0; font-size: 0.85rem; }
    .nav-avatar-link { margin-left: 0; }
    .nav-user { margin-left: 0; font-size: 0.8rem; }

    /* --- Blog header --- */
    .blog-header { padding: 24px 0 20px; }
    .blog-header h1 { font-size: 1.5rem; }
    .subtitle { font-size: 0.95rem; }

    /* --- Article cards --- */
    .article-card { padding: 16px; }
    .article-card h2 { font-size: 1.1rem; }
    .article-card.has-thumbnail { flex-direction: column; align-items: stretch; }
    .article-thumb { width: 100%; height: 160px; }

    /* --- Single article --- */
    .single-article { padding: 20px 16px; }
    .single-article h1 { font-size: 1.35rem; }
    .single-article .content { font-size: 0.95rem; line-height: 1.8; }
    .single-article .content img {
        max-height: none;
        border-radius: 4px;
        margin: 14px auto;
    }

    /* --- Comments --- */
    .comments-section { padding: 16px; }
    .comment-body { gap: 8px; }
    .comment-header { font-size: 0.8rem; }
    .comment-header .comment-meta-right { gap: 6px; }
    .comment.comment-admin { margin-left: -16px; padding-left: 12px; }
    .comment.comment-pinned { margin-left: -16px; padding-left: 12px; }
    .reply-list { margin-left: 12px; padding-left: 8px; }
    .comment-avatar, .comment-avatar-text { width: 30px; height: 30px; }
    .reply-avatar, .reply-avatar-text { width: 24px; height: 24px; }

    /* --- Admin --- */
    .admin-header { flex-direction: column; align-items: flex-start; }
    .admin-actions { flex-wrap: wrap; }
    .admin-actions .btn { font-size: 0.85rem; padding: 8px 14px; }
    .admin-form { padding: 16px; }
    .admin-form label { font-size: 0.85rem; }
    .admin-container { max-width: 100%; }

    /* --- Tables --- */
    .admin-table { min-width: 540px; }
    .admin-table th, .admin-table td { padding: 8px 10px; font-size: 0.8rem; }
    .admin-table .actions { white-space: nowrap; }

    /* --- Forms --- */
    .input { font-size: 0.9rem; padding: 8px 10px; }
    .btn { font-size: 0.9rem; padding: 10px 18px; }
    .btn-small { padding: 6px 12px; font-size: 0.8rem; }

    /* --- Upload --- */
    .upload-row { flex-wrap: wrap; }
    .upload-area { padding: 10px; }

    /* --- Media modal --- */
    .media-modal-body { width: 95%; max-height: 80vh; }
    .media-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px; }

    /* --- Attachment card --- */
    .attachment-card a { padding: 12px 14px; gap: 10px; }
    .att-icon { width: 36px; height: 36px; border-radius: 8px; font-size: 1.1rem; }
    .att-dl-btn { width: 36px; height: 36px; border-radius: 8px; font-size: 1rem; }
    .att-name { font-size: 0.85rem; }
    .att-size { font-size: 0.72rem; }

    /* --- Pagination --- */
    .page-link { width: 32px; height: 32px; line-height: 32px; font-size: 0.85rem; }

    /* --- Misc --- */
    .empty-state { padding: 40px 0; }
    .back-link { font-size: 0.85rem; }
}

@media (max-width: 480px) {
    /* --- Typography --- */
    .blog-header h1 { font-size: 1.3rem; }
    .single-article h1 { font-size: 1.2rem; }
    .article-card h2 { font-size: 1rem; }

    /* --- Navbar --- */
    .logo { font-size: 1.1rem; }

    /* --- Comments --- */
    .reply-list { margin-left: 6px; padding-left: 6px; }
    .edit-form-row, .reply-form-row { flex-wrap: wrap; }
    .input-sm { width: 100%; }

    /* --- Forms --- */
    .captcha-row { flex-direction: column; }
    .captcha-img { height: 48px; align-self: flex-start; }

    /* --- Media modal --- */
    .media-grid { grid-template-columns: repeat(3, 1fr); }

    /* --- Attachment card --- */
    .attachment-card a { padding: 10px 12px; gap: 8px; }
    .att-icon { width: 32px; height: 32px; }
    .att-dl-btn { width: 32px; height: 32px; }

    /* --- Buttons --- */
    .btn { width: 100%; text-align: center; }
    .admin-actions { width: 100%; }
    .admin-actions .btn { flex: 1; text-align: center; }
    .btn-small { min-height: 36px; }
}
