/* ===== Variables ===== */
:root {
    --bg: #ffffff;
    --bg-secondary: #f7f8fa;
    --bg-sidebar: #f9fafb;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-muted: #aeaeb2;
    --border: #e5e5ea;
    --primary: #0071e3;
    --primary-hover: #0077ed;
    --primary-light: #e8f4fd;
    --primary-ghost: #f0f7ff;
    --accent: #30b354;
    --accent-light: #e8f8ed;
    --code-bg: #f5f5f7;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --card-hover-shadow: 0 4px 12px rgba(0,0,0,0.08);
    --sidebar-width: 270px;
    --navbar-height: 52px;
    --custom-bg-image: none;
    --custom-bg-opacity: 0;
    --custom-bg-brightness: 100%;
    --custom-bg-blur: 0px;
    --sidebar-bg-opacity: 0.88;
    --sidebar-surface-rgb: 255, 255, 255;
    --surface-on-bg: rgba(255, 255, 255, 0.88);
    --surface-on-bg-strong: rgba(255, 255, 255, 0.94);
    --surface-on-bg-hover: rgba(0, 113, 227, 0.12);
    --surface-on-bg-active: rgba(0, 113, 227, 0.18);
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    --font-sans: 'JetBrains Mono', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans CJK SC', monospace;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --bg-sidebar: #232325;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --text-muted: #636366;
    --border: #38383a;
    --primary: #4da6ff;
    --primary-hover: #66b3ff;
    --primary-light: #1c3a5e;
    --primary-ghost: #1a2e44;
    --accent: #30d158;
    --accent-light: #1a3d2a;
    --code-bg: #2c2c2e;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.2);
    --card-hover-shadow: 0 4px 16px rgba(0,0,0,0.4);
    --surface-on-bg: rgba(28, 28, 30, 0.88);
    --surface-on-bg-strong: rgba(28, 28, 30, 0.94);
    --sidebar-surface-rgb: 28, 28, 30;
    --surface-on-bg-hover: rgba(77, 166, 255, 0.16);
    --surface-on-bg-active: rgba(77, 166, 255, 0.24);
}

/* KaTeX dark mode */
[data-theme="dark"] .katex { color: #f5f5f7; }
[data-theme="dark"] .katex .mord.mathdefault { color: #f5f5f7; }

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--navbar-height) + 16px);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    line-height: 1.75;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

body.has-custom-background {
    background: transparent;
}

body.has-custom-background::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: var(--custom-bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: var(--custom-bg-opacity);
    filter: brightness(var(--custom-bg-brightness)) blur(var(--custom-bg-blur));
    transform: scale(1.03);
}

body.has-custom-background::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] body.has-custom-background::after {
    background: rgba(0, 0, 0, 0.42);
}

body.has-custom-background .layout {
    position: relative;
    z-index: 1;
}

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

/* ===== Navbar ===== */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--navbar-height);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(255,255,255,0.82);
}

[data-theme="dark"] .navbar {
    background: rgba(28,28,30,0.82);
}

body.has-custom-background .navbar {
    background: var(--surface-on-bg-strong);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
    flex-shrink: 0;
}
.logo:hover { color: var(--primary); text-decoration: none; }
.logo svg { color: var(--primary); }

.logo-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.10);
}

.search-box {
    flex: 1;
    max-width: 400px;
    position: relative;
    margin: 0 auto;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    height: 36px;
    padding: 0 38px 0 36px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    outline: none;
    transition: all var(--transition);
}

.search-box input:focus {
    border-color: var(--primary);
    background: var(--bg);
    box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}

.search-hint {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    background: var(--bg);
}

.menu-toggle {
    display: flex;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    transition: background var(--transition);
}
.menu-toggle:hover { background: var(--bg-secondary); }
.menu-toggle[aria-expanded="false"] {
    color: var(--primary);
    background: var(--primary-ghost);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    padding: 7px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: all var(--transition);
}
.theme-toggle:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
    color: var(--primary);
}

/* Navbar buttons */
.btn-new-article,
.btn-background,
.btn-logout {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 18px;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-new-article {
    background: var(--bg);
    color: var(--primary);
    border: 1px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 5px;
}
.btn-new-article:hover {
    background: var(--primary-ghost);
}

.btn-background {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 5px;
}
.btn-background:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-ghost);
}

.btn-logout {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-logout:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

[data-theme="light"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }

/* ===== Layout ===== */
.layout {
    display: flex;
    padding-top: var(--navbar-height);
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow: hidden;
    z-index: 50;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.has-custom-background .sidebar {
    background: rgba(var(--sidebar-surface-rgb), var(--sidebar-bg-opacity));
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 8px 0 24px rgba(0,0,0,0.08);
}

[data-theme="dark"] body.has-custom-background .sidebar {
    box-shadow: 8px 0 28px rgba(0,0,0,0.32);
}

body.sidebar-collapsed .sidebar { transform: translateX(-100%); }

.sidebar-nav {
    position: relative;
    z-index: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 20px 20px 12px;
    color: var(--text-secondary);
}

.sidebar-icon { display: flex; color: var(--text-muted); }

.sidebar-title {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.category-tree {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    list-style: none;
    padding: 4px 0 12px;
}

.sidebar-footer {
    flex: 0 0 auto;
    padding: 8px 12px 12px;
    border-top: 1px solid var(--border);
}

.sidebar-login {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    min-height: 32px;
    padding: 6px 8px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.76rem;
    cursor: pointer;
    opacity: 0.62;
    transition: color var(--transition), background var(--transition), opacity var(--transition);
}

.sidebar-overview {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    margin: 0 10px 8px;
    padding: 7px 10px;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.82;
    text-decoration: none;
    transition: color var(--transition), background var(--transition);
}

.sidebar-login:hover,
.sidebar-overview:hover,
.sidebar-overview.active {
    color: var(--primary);
    background: var(--bg-secondary);
}

.sidebar-login:hover { color: var(--text-secondary); opacity: 1; }

.sidebar-login:focus-visible,
.sidebar-overview:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.sidebar-login:focus-visible { color: var(--text-secondary); opacity: 1; }

.category-tree li { position: relative; }

.category-tree a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 20px;
    font-size: 0.9rem;
    color: var(--text);
    transition: all var(--transition);
    border-left: 3px solid transparent;
    margin-right: 2px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.category-tree a:hover {
    background: var(--primary-ghost);
    text-decoration: none;
    color: var(--primary);
}

body.has-custom-background .category-tree a:hover {
    background: var(--surface-on-bg-hover);
}

.category-tree a.active {
    color: var(--primary);
    background: var(--primary-ghost);
    border-left-color: var(--primary);
    font-weight: 500;
}

body.has-custom-background .category-tree a.active {
    background: var(--surface-on-bg-active);
}

.category-tree a .count {
    margin-left: auto;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--border);
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.category-tree a.active .count {
    background: var(--primary-light);
    color: var(--primary);
}

/* Nested */
.category-tree ul { list-style: none; }
.category-tree li li a { padding-left: 44px; }
.category-tree li li li a { padding-left: 64px; }

/* Indent guide lines */
.category-tree ul {
    position: relative;
    margin-left: 20px;
    border-left: 1px solid var(--border);
}

.category-tree .category-children {
    overflow: hidden;
    max-height: 1400px;
    opacity: 1;
    transform-origin: top;
    transition:
        max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.22s ease;
}

.category-tree li li { padding-left: 0; }

/* Collapse toggle */
.cat-toggle {
    position: absolute;
    left: 4px;
    top: 7px;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    z-index: 1;
    transition: all var(--transition);
}

.cat-toggle:hover {
    color: var(--primary);
    background: var(--primary-ghost);
}

body.has-custom-background .cat-toggle:hover {
    background: var(--surface-on-bg-hover);
}
.cat-toggle svg { transition: transform var(--transition); }
.cat-toggle.collapsed svg { transform: rotate(-90deg); }
.category-tree li.collapsed > .category-children {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.category-article-item > a {
    min-width: 0;
    padding-top: 5px;
    padding-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 400;
}

.category-article-icon {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
}

.category-article-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-articles-status {
    padding: 6px 20px 6px 44px;
    color: var(--text-muted);
    font-size: 0.76rem;
}

.category-articles-status.error { color: #e74c3c; }

.tree-loading {
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Category admin controls */
.btn-add-cat {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all var(--transition);
}
.btn-add-cat:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-ghost);
}

.cat-actions {
    display: none;
    margin-left: auto;
    gap: 2px;
    align-items: center;
}
.category-tree a:hover .cat-actions,
.category-tree a.active .cat-actions,
.category-tree a:focus-within .cat-actions {
    display: inline-flex;
}

.category-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.article-order-actions {
    flex: 0 0 auto;
}
.cat-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    transition: all var(--transition);
}
.cat-actions button:hover {
    color: var(--primary);
    background: var(--primary-ghost);
}
.cat-actions button:disabled {
    color: var(--border);
    background: transparent;
    cursor: default;
    opacity: 0.45;
}
.cat-actions .btn-del-cat:hover {
    color: #e74c3c;
    background: #fef2f2;
}

@media (hover: none) {
    .category-tree a .cat-actions {
        display: inline-flex;
    }
}

/* Category inline edit form */
.cat-edit-form {
    padding: 8px 20px 8px 28px;
    border-bottom: 1px solid var(--border);
}
.cat-edit-form input,
.cat-edit-form textarea,
.cat-edit-form select {
    width: 100%;
    padding: 5px 8px;
    margin-bottom: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all var(--transition);
}
.cat-edit-form input:focus,
.cat-edit-form textarea:focus,
.cat-edit-form select:focus {
    border-color: var(--primary);
}
.cat-edit-form textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.6;
}
.cat-edit-form .cat-edit-actions {
    display: flex;
    gap: 6px;
}
.cat-edit-form .cat-edit-actions button {
    font-size: 0.75rem;
    font-family: var(--font-sans);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all var(--transition);
}
.cat-edit-form .btn-save-cat {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.cat-edit-form .btn-save-cat:hover { background: var(--primary-hover); }
.cat-edit-form .btn-cancel-cat {
    background: var(--bg);
    color: var(--text-secondary);
}
.cat-edit-form .btn-cancel-cat:hover { background: var(--bg-secondary); }

/* ===== Main ===== */
.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    min-height: calc(100vh - var(--navbar-height));
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .main { margin-left: 0; }

.content {
    width: 100%;
    flex: 1 0 auto;
    max-width: 780px;
    margin: 0 auto;
    padding: 40px 28px 80px;
}

@media (min-width: 1100px) {
    .content {
        max-width: 840px;
        padding: 48px 36px 80px;
    }
}

@media (min-width: 1500px) {
    .content {
        max-width: 900px;
        padding: 48px 44px 80px;
    }
}

@media (min-width: 1800px) {
    .content {
        max-width: 940px;
    }
}

/* ===== Home ===== */
#homePage > .home-hero,
#homePage > .daily-quote,
#homePage > .recent-articles {
    width: 100%;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}

.home-hero {
    text-align: center;
    padding: 48px 0 32px;
}

.home-hero h1 {
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.home-hero p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.daily-quote {
    position: relative;
    margin: 8px 0 40px;
    padding: 12px 0 8px;
    overflow: hidden;
    text-align: center;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.daily-quote::before {
    content: '“';
    position: absolute;
    top: -22px;
    left: 18px;
    color: var(--primary);
    opacity: 0.1;
    font-family: Georgia, serif;
    font-size: 8rem;
    line-height: 1;
}

.daily-quote-label {
    position: relative;
    margin-bottom: 10px;
    color: var(--primary);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.18em;
}

.daily-quote blockquote {
    position: relative;
    color: var(--text);
    font-size: 1.12rem;
    font-weight: 500;
    line-height: 1.8;
}

.daily-quote-date {
    position: relative;
    margin-top: 10px;
    color: var(--text-muted);
    font-size: 0.76rem;
}

.section-header {
    margin-bottom: 16px;
}

.section-header h2,
.section-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.section-line {
    display: block;
    width: 36px;
    height: 3px;
    background: var(--primary);
    border-radius: 2px;
    margin-top: 8px;
}

.search-highlight {
    color: var(--primary);
    font-weight: 700;
}

#categoryPage > .breadcrumb,
#categoryPage > .section-header,
#categoryPage > .article-list,
#categoryPage > .pagination {
    width: 100%;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}

.category-intro {
    width: 100%;
    max-width: 720px;
    margin: 0 auto 24px;
    padding: 4px 0 18px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.category-intro p {
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.category-intro p:last-child {
    margin-bottom: 0;
}

.category-intro strong {
    color: var(--text);
}

.child-category-entries {
    margin-top: 20px;
}

.child-category-entries h2 {
    margin-bottom: 12px;
    font-size: 0.98rem;
    color: var(--text);
}

.child-category-list {
    display: grid;
    gap: 10px;
}

.child-category-entry {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.2fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text);
    transition: all var(--transition);
}

.child-category-entry:hover {
    border-color: var(--primary);
    background: var(--primary-ghost);
    color: var(--primary);
    text-decoration: none;
}

.child-category-name {
    font-weight: 600;
}

.child-category-url {
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.82rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.child-category-count {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.76rem;
    white-space: nowrap;
}

.child-category-entry:hover .child-category-url,
.child-category-entry:hover .child-category-count {
    color: var(--primary);
}

/* ===== Article List (Cards) ===== */
.article-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.article-list li {
    width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    transition: all var(--transition);
    background: transparent;
    box-shadow: none;
}

.article-list li:hover {
    border-color: transparent;
    box-shadow: none;
    transform: none;
}

.article-list li a {
    display: block;
    min-width: 0;
    padding: 18px 20px 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    overflow-wrap: anywhere;
    transition: color var(--transition);
}

.article-list li:hover a { color: var(--primary); text-decoration: none; }

.article-excerpt {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0 20px 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.75;
    display: -webkit-box;
    line-clamp: 3;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    max-height: calc(1.75em * 3 + 10px);
    overflow: hidden;
    overflow-wrap: anywhere;
}

.article-list .meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 14px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.article-list .meta a {
    display: inline;
    padding: 0;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--text-secondary);
}
.article-list .meta a:hover { color: var(--primary); }

.article-list .tags {
    display: inline-flex;
    gap: 6px;
    margin-left: auto;
}

.article-list .tag {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: var(--primary-ghost);
    color: var(--primary);
    border-radius: 4px;
    font-weight: 500;
    letter-spacing: 0.2px;
}

/* ===== Breadcrumb ===== */
.breadcrumb {
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: var(--text-muted); margin: 0 2px; }

/* ===== Article Content ===== */
.article { animation: fadeIn 0.3s ease; }

body.has-custom-background .profile-container {
    background: var(--surface-on-bg-strong);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--card-shadow);
}

body.has-custom-background .profile-container {
    padding: 22px 24px;
}

body.has-custom-background .article {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0;
}

body.has-custom-background .home-hero,
body.has-custom-background .section-header,
body.has-custom-background .breadcrumb {
    padding: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

body.has-custom-background .doc-viewer-container,
body.has-custom-background .modal,
body.has-custom-background .user-dropdown {
    background: var(--surface-on-bg-strong);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

body.has-custom-background .article code {
    background: rgba(var(--sidebar-surface-rgb), 0.38);
    border-color: rgba(148, 163, 184, 0.20);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

body.has-custom-background .article pre {
    background: rgba(var(--sidebar-surface-rgb), 0.30);
    border-color: rgba(148, 163, 184, 0.18);
    box-shadow: 0 12px 34px rgba(15, 23, 42, 0.04);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

body.has-custom-background .article pre code {
    background: transparent;
}

body.has-custom-background .child-category-entry,
body.has-custom-background .article-list li,
body.has-custom-background .doc-viewer-container {
    background: rgba(var(--sidebar-surface-rgb), 0.42);
    border-color: rgba(148, 163, 184, 0.18);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

body.has-custom-background .child-category-entry:hover,
body.has-custom-background .article-list li:hover {
    background: rgba(var(--sidebar-surface-rgb), 0.52);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.article h1 {
    font-size: 2rem;
    margin-bottom: 6px;
    font-weight: 800;
    line-height: 1.35;
    letter-spacing: -0.3px;
    scroll-margin-top: calc(var(--navbar-height) + 16px);
}

.article h2 {
    font-size: 1.35rem;
    margin-top: 36px;
    margin-bottom: 14px;
    font-weight: 700;
    letter-spacing: -0.2px;
    position: relative;
    padding-left: 16px;
    scroll-margin-top: calc(var(--navbar-height) + 16px);
}

.article h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 4px;
    background: var(--primary);
    border-radius: 2px;
}

.article h3 {
    font-size: 1.1rem;
    margin-top: 28px;
    margin-bottom: 10px;
    font-weight: 600;
    scroll-margin-top: calc(var(--navbar-height) + 16px);
}

.article h4 {
    font-size: 1rem;
    margin-top: 20px;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-secondary);
    scroll-margin-top: calc(var(--navbar-height) + 16px);
}

.article p { margin-bottom: 14px; }

.article ul, .article ol {
    margin-bottom: 14px;
    padding-left: 24px;
}

.article li { margin-bottom: 4px; }
.article li::marker { color: var(--text-muted); }

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

.article blockquote {
    margin: 20px 0;
    padding: 14px 18px;
    border-left: 4px solid var(--accent);
    background: var(--accent-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.article blockquote p:last-child { margin-bottom: 0; }

/* Inline code */
.article code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    padding: 2px 6px;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    word-break: break-word;
}

/* Code block */
.article pre {
    margin: 20px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.article pre code {
    display: block;
    padding: 18px 20px;
    font-size: 0.84rem;
    line-height: 1.6;
    background: var(--code-bg);
    border: none;
    border-radius: 0;
    overflow-x: auto;
}

/* Language label on code blocks */
.article pre {
    position: relative;
}

.hljs-lang {
    position: absolute;
    top: 6px;
    right: 10px;
    font-size: 0.68rem;
    font-family: var(--font-sans);
    color: var(--text-muted);
    user-select: none;
}

.mermaid {
    margin: 22px 0;
    padding: 18px;
    overflow-x: auto;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
    box-shadow: var(--card-shadow);
}

.mermaid svg {
    max-width: 100%;
    height: auto;
}

.mermaid-error {
    color: #e74c3c;
    text-align: left;
    white-space: pre-wrap;
}

body.has-custom-background .mermaid {
    background: rgba(var(--sidebar-surface-rgb), 0.34);
    border-color: rgba(148, 163, 184, 0.18);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Tables */
.article table {
    width: fit-content;
    max-width: 100%;
    margin: 20px 0;
    border-collapse: collapse;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

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

.article th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.article tr:last-child td { border-bottom: none; }

.article img { max-width: 100%; border-radius: var(--radius-sm); }
.article hr {
    margin: 32px 0;
    border: none;
    border-top: 1px solid var(--border);
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
    color: var(--text-muted);
    font-size: 0.84rem;
}

.article-meta .tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--primary-ghost);
    color: var(--primary);
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 32px;
}

.pagination button {
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    transition: all var(--transition);
}

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

.pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}

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

.pagination .page-dots {
    padding: 0 4px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 16px;
    color: var(--text-muted);
}

.empty-state h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.btn-back {
    display: inline-block;
    padding: 8px 20px;
    background: var(--primary);
    color: #fff !important;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}
.btn-back:hover { background: var(--primary-hover); box-shadow: var(--card-shadow); }

/* ===== Loading ===== */
.loading-text { color: var(--text-muted); padding: 16px 0; font-size: 0.9rem; }

.loading-spinner {
    width: 28px; height: 28px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 32px auto;
}

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

/* ===== Back to top ===== */
.back-to-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    box-shadow: var(--card-shadow);
    transition: all var(--transition);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.back-to-top:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--card-hover-shadow);
}

/* ===== Sidebar overlay ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: -1;
    backdrop-filter: blur(2px);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .search-box { max-width: none; }
    .search-hint { display: none; }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,0.12);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open .sidebar-overlay {
        display: block;
    }

    .main { margin-left: 0; }

    .content { padding: 24px 16px 64px; }

    .home-hero { padding: 32px 0 24px; }
    .home-hero h1 { font-size: 2rem; }
    .daily-quote { margin-bottom: 32px; padding: 22px 20px 20px; }
    .daily-quote blockquote { font-size: 1rem; }

    .article h1 { font-size: 1.5rem; }
    .article h2 { font-size: 1.2rem; }

    .back-to-top { bottom: 16px; right: 16px; }
}

@media (min-width: 1500px) {
    .article { font-size: 1.05rem; }
    .article h1 { font-size: 2.2rem; }
    .article h2 { font-size: 1.45rem; }
    .article h3 { font-size: 1.15rem; }
}

/* ===== Scrollbar ===== */
.category-tree::-webkit-scrollbar { width: 4px; }
.category-tree::-webkit-scrollbar-track { background: transparent; }
.category-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.main::-webkit-scrollbar { width: 6px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

pre::-webkit-scrollbar { height: 4px; }
pre::-webkit-scrollbar-track { background: transparent; }
pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 32px 28px 24px;
    width: 380px;
    max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0,0,0,0.18);
    position: relative;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.modal-close:hover { color: var(--text); background: var(--bg-secondary); }

.modal h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: -0.2px;
}

.background-modal {
    max-width: 520px;
}

.background-preview {
    position: relative;
    height: 160px;
    margin-bottom: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--bg-secondary), var(--primary-ghost));
    background-size: cover;
    background-position: center;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.background-preview.has-image span {
    display: none;
}

.background-controls {
    display: grid;
    gap: 10px;
}

.background-controls label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
}

.background-controls output {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
}

.background-controls input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

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

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

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,113,227,0.1);
}

.form-group textarea {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.7;
    resize: vertical;
    min-height: 280px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-error {
    color: #e74c3c;
    font-size: 0.82rem;
    margin-bottom: 12px;
    min-height: 1.2em;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.form-spacer { flex: 1; }

.btn-submit,
.btn-secondary,
.btn-danger {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: 18px;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
}

.btn-submit {
    background: var(--primary);
    color: #fff;
}
.btn-submit:hover { background: var(--primary-hover); }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.btn-secondary:hover {
    background: var(--bg);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-danger {
    background: var(--bg);
    color: #e74c3c;
    border: 1px solid #e74c3c;
}
.btn-danger:hover { background: #fef2f2; }

/* ===== Editor (legacy form styles, kept for reference) ===== */
.editor-form h1 { margin-bottom: 24px; }

.editor-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    min-height: 400px;
}

.editor-split textarea {
    resize: none;
    min-height: 400px;
    height: 100%;
}

.editor-split .toc-sidebar {
    display: none;
}

@media (min-width: 1400px) {
    .editor-split {
        grid-template-columns: 1fr 1fr 180px;
    }
    .editor-split .toc-sidebar {
        display: block;
        width: auto;
    }
    .editor-split .toc-nav {
        top: 0;
        max-height: 70vh;
    }
}

.editor-preview {
    min-height: 400px;
    max-height: 70vh;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    overflow-y: auto;
}

@media (max-width: 900px) {
    .editor-split {
        grid-template-columns: 1fr;
    }
    .editor-split textarea,
    .editor-preview {
        min-height: 280px;
        max-height: 400px;
    }
    .toc-sidebar { display: none; }
}

/* ===== Full-screen Editor ===== */
.editor-body {
    overflow: hidden;
}

.editor-body.has-custom-background {
    background: transparent;
}

.editor-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 44px;
    background: rgba(255,255,255,0.85);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

[data-theme="dark"] .editor-topbar {
    background: rgba(28,28,30,0.9);
}

body.has-custom-background .editor-topbar {
    background: var(--surface-on-bg-strong);
}

.editor-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    flex-shrink: 0;
}
.editor-back:hover {
    color: var(--primary);
    background: var(--primary-ghost);
}

.editor-save-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 28px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.editor-save-status.saved {
    color: #34c759;
    border-color: rgba(52, 199, 89, 0.35);
    background: rgba(52, 199, 89, 0.1);
}

.editor-save-status.saving {
    color: var(--primary);
    border-color: rgba(0, 122, 255, 0.35);
    background: var(--primary-ghost);
}

.editor-save-status.dirty {
    color: #ff9500;
    border-color: rgba(255, 149, 0, 0.35);
    background: rgba(255, 149, 0, 0.1);
}

.editor-save-status.error {
    color: #ff3b30;
    border-color: rgba(255, 59, 48, 0.35);
    background: rgba(255, 59, 48, 0.1);
}

.editor-save-status .status-icon {
    flex-shrink: 0;
}

.editor-save-status .status-spinner {
    animation: spin 0.8s linear infinite;
}

.editor-title-input {
    flex: 1;
    height: 32px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--text);
    background: transparent;
    outline: none;
    transition: all var(--transition);
    min-width: 0;
}
.editor-title-input:focus {
    border-color: var(--border);
    background: var(--bg-secondary);
}
.editor-title-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.editor-meta-btn,
.editor-theme-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

body.has-custom-background .editor-meta-btn,
body.has-custom-background .editor-theme-btn,
body.has-custom-background .editor-delete-btn,
body.has-custom-background .editor-meta-field input,
body.has-custom-background .editor-meta-field select,
body.has-custom-background .editor-save-status {
    background: var(--surface-on-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.editor-meta-btn:hover,
.editor-theme-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-ghost);
}

.editor-theme-btn {
    width: 30px;
    padding: 0;
    justify-content: center;
}

.editor-save-btn {
    height: 30px;
    padding: 0 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.editor-save-btn:hover { background: var(--primary-hover); }
.editor-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.editor-delete-btn {
    height: 30px;
    padding: 0 14px;
    border: 1px solid #e74c3c;
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: #e74c3c;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.editor-delete-btn:hover { background: #fef2f2; }

/* Metadata bar (always visible) */
.editor-meta-bar {
    position: fixed;
    top: 44px;
    left: 0; right: 0;
    height: 46px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    z-index: 99;
}

body.has-custom-background .editor-meta-bar {
    background: var(--surface-on-bg-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.editor-meta-field {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.editor-meta-field label {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.editor-meta-field input,
.editor-meta-field select {
    height: 28px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all var(--transition);
}
.editor-meta-field input {
    width: 160px;
}
.editor-meta-field select {
    width: 120px;
}
.editor-meta-field input:focus,
.editor-meta-field select:focus {
    border-color: var(--primary);
}

/* Main split area */
.editor-main {
    position: fixed;
    top: 90px;
    left: 0; right: 0; bottom: 0;
    display: flex;
    z-index: 1;
}

.editor-pane {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.editor-pane-left {
    background: var(--bg);
}

body.has-custom-background .editor-pane-left {
    background: rgba(var(--sidebar-surface-rgb), var(--sidebar-bg-opacity));
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.editor-pane-left textarea {
    width: 100%;
    height: 100%;
    padding: 20px 24px;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    line-height: 1.75;
    color: var(--text);
    background: var(--bg);
    tab-size: 4;
    -moz-tab-size: 4;
}

body.has-custom-background .editor-pane-left textarea {
    background: transparent;
}

.editor-pane-right {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
}

body.has-custom-background .editor-pane-right {
    background: rgba(var(--sidebar-surface-rgb), var(--sidebar-bg-opacity));
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.editor-preview-content {
    height: 100%;
    padding: 20px 28px;
    overflow-y: auto;
    max-width: 860px;
    margin: 0 auto;
}

/* Divider */
.editor-divider {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}
.editor-divider:hover,
.editor-divider.active {
    background: var(--primary);
}
.editor-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 28px;
    border-radius: 1px;
    background: var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s;
}
.editor-divider:hover::after {
    opacity: 1;
}

/* Mobile: stack vertically or toggle */
@media (max-width: 768px) {
    .editor-topbar {
        padding: 0 6px;
        gap: 4px;
    }
    .editor-title-input {
        font-size: 0.85rem;
    }
    .editor-save-status {
        width: 30px;
        padding: 0;
        gap: 0;
    }
    .editor-save-status span {
        display: none;
    }
    .editor-meta-btn span {
        display: none;
    }
    .editor-meta-btn {
        width: 30px;
        padding: 0;
        justify-content: center;
    }
    .editor-meta-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 10px;
        gap: 6px;
    }
    .editor-meta-field input {
        width: 120px;
    }
    .editor-pane-left textarea {
        padding: 14px 16px;
        font-size: 0.82rem;
    }
    .editor-preview-content {
        padding: 14px 16px;
    }
}

@media (max-width: 600px) {
    .editor-main {
        flex-direction: column;
    }
    .editor-pane {
        flex: none;
        height: 50%;
    }
    .editor-divider {
        width: 100%;
        height: 6px;
        cursor: row-resize;
    }
    .editor-pane-right {
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

/* ===== TOC Sidebar ===== */
.article-layout {
    display: flex;
    gap: 32px;
    position: relative;
}

.article-layout .article-main {
    flex: 1;
    min-width: 0;
}

.toc-sidebar {
    width: 200px;
    flex-shrink: 0;
    display: none;
}

@media (min-width: 1300px) {
    .toc-sidebar {
        display: block;
    }
}

.toc-nav {
    position: sticky;
    top: 50vh;
    transform: translateY(-50%);
    max-height: calc(100vh - var(--navbar-height) - 48px);
    overflow-y: auto;
    font-size: 0.82rem;
    border-left: 2px solid var(--border);
    padding: 4px 0 4px 16px;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    width: max-content;
    min-width: 180px;
    max-width: 220px;
}

[data-theme="dark"] .toc-nav {
    background: transparent;
}

body.has-custom-background .toc-nav {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.toc-node {
    position: relative;
}

.toc-children {
    position: relative;
}

.toc-children::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}

.toc-item {
    display: block;
    padding: 4px 0 4px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
    line-height: 1.4;
    position: relative;
    border-left: 2px solid transparent;
}

.toc-item::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 50%;
    width: 10px;
    height: 1px;
    background: var(--border);
}

.toc-item:hover {
    color: var(--primary);
}

.toc-item.active {
    color: var(--text);
    font-weight: 700;
    border-left-color: var(--primary);
}

[data-theme="dark"] .toc-item.active {
    color: #ffffff;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(255,255,255,0.22);
}

.toc-level-1 {
    padding-left: 12px;
    font-weight: 500;
    font-size: 0.84rem;
}

.toc-level-2 {
    padding-left: 28px;
    font-size: 0.8rem;
}

.toc-level-3 {
    padding-left: 44px;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.toc-nav::-webkit-scrollbar { width: 3px; }
.toc-nav::-webkit-scrollbar-track { background: transparent; }
.toc-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== Article admin actions ===== */
.article-admin-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ===== Footer ===== */
.site-footer {
    text-align: center;
    padding: 24px 28px 28px;
    color: var(--text);
    background: var(--bg);
    font-size: 0.78rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
    flex-shrink: 0;
}

.site-footer a {
    color: var(--text);
    text-decoration: none;
}

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

body.has-custom-background .site-footer {
    background: var(--surface-on-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

/* ===== User Area (navbar) ===== */
.user-area {
    position: relative;
    flex-shrink: 0;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.84rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}
.user-pill:hover {
    border-color: var(--primary);
    background: var(--primary-ghost);
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    flex-shrink: 0;
}
.user-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.user-avatar-default {
    color: var(--text-muted);
}

.user-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 160px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 150;
    padding: 4px;
    animation: fadeIn 0.15s ease;
}
.user-dropdown.open {
    display: block;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font-size: 0.84rem;
    font-family: var(--font-sans);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
}
.user-dropdown-item:hover {
    background: var(--bg-secondary);
    color: var(--primary);
}

.btn-logout-dropdown:hover {
    background: #fef2f2;
    color: #e74c3c;
}

/* ===== Site Overview ===== */
.site-overview {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
}

.overview-heading {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
    padding: 30px 32px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: var(--radius-lg);
    background:
        radial-gradient(circle at 88% 18%, rgba(16, 185, 129, 0.16), transparent 18rem),
        linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(255, 255, 255, 0.76));
    box-shadow: var(--card-shadow);
}

[data-theme="dark"] .overview-heading {
    background:
        radial-gradient(circle at 88% 18%, rgba(52, 211, 153, 0.14), transparent 18rem),
        linear-gradient(135deg, rgba(59, 130, 246, 0.18), rgba(15, 23, 42, 0.80));
}

.overview-eyebrow,
.overview-panel-kicker {
    display: block;
    margin-bottom: 7px;
    color: var(--primary);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.overview-heading h1 {
    margin: 0 0 8px;
    font-size: clamp(1.9rem, 4vw, 2.8rem);
    line-height: 1.12;
}

.overview-heading p {
    margin: 0;
    color: var(--text-secondary);
}

.overview-new-article {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 0 16px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
}

.overview-new-article:hover {
    color: #fff;
    transform: translateY(-1px);
}

.overview-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.overview-stat,
.overview-panel {
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--card-shadow);
}

.overview-stat {
    position: relative;
    overflow: hidden;
    min-width: 0;
    padding: 18px 19px;
}

.overview-stat::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: var(--overview-tone, var(--primary));
}

.overview-stat.tone-blue { --overview-tone: #3b82f6; }
.overview-stat.tone-green { --overview-tone: #10b981; }
.overview-stat.tone-amber { --overview-tone: #f59e0b; }
.overview-stat.tone-violet { --overview-tone: #8b5cf6; }

.overview-stat-label,
.overview-stat-hint {
    display: block;
    overflow: hidden;
    color: var(--text-secondary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overview-stat-label {
    margin-bottom: 8px;
    font-size: 0.74rem;
    font-weight: 700;
}

.overview-stat-value {
    display: block;
    min-height: 2.5rem;
    overflow: hidden;
    color: var(--text);
    font-size: clamp(1.35rem, 3vw, 2rem);
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overview-stat-hint {
    margin-top: 6px;
    font-size: 0.7rem;
}

.overview-panels {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    gap: 12px;
}

.overview-panel {
    min-width: 0;
    padding: 22px;
}

.overview-panel-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.overview-panel-heading h2 {
    font-size: 1rem;
}

.overview-panel-heading > a {
    flex: 0 0 auto;
    font-size: 0.75rem;
}

.overview-category-list,
.overview-recent-list {
    display: grid;
    gap: 7px;
}

.overview-category-row,
.overview-recent-item {
    min-width: 0;
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: background var(--transition), color var(--transition), transform var(--transition);
}

.overview-category-row:hover,
.overview-recent-item:hover {
    background: var(--primary-ghost);
    color: var(--primary);
    text-decoration: none;
    transform: translateX(2px);
}

.overview-category-row {
    display: grid;
    gap: 8px;
    padding: 9px 10px;
}

.overview-category-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.overview-category-info strong {
    overflow: hidden;
    font-size: 0.82rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overview-category-info span {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.overview-category-track {
    overflow: hidden;
    height: 5px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
}

.overview-category-bar {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.overview-recent-item {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 9px 10px;
}

.overview-recent-number {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
}

.overview-recent-body {
    display: grid;
    min-width: 0;
}

.overview-recent-body strong,
.overview-recent-body span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overview-recent-body strong {
    font-size: 0.8rem;
}

.overview-recent-body span {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.68rem;
}

.overview-loading,
.overview-error,
.overview-empty {
    grid-column: 1 / -1;
    padding: 22px;
    color: var(--text-muted);
    text-align: center;
}

.overview-error { color: #ef4444; }

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

    .overview-panels {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .overview-heading {
        align-items: stretch;
        flex-direction: column;
        padding: 24px 20px;
    }

    .overview-new-article {
        align-self: flex-start;
    }

    .overview-stats {
        gap: 8px;
    }

    .overview-stat,
    .overview-panel {
        padding: 16px;
    }
}

@media (max-width: 380px) {
    .overview-stats {
        grid-template-columns: 1fr;
    }
}

/* ===== Profile Page ===== */
.profile-container {
    max-width: 640px;
}

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

.profile-section-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 14px;
}

.profile-avatar-row {
    display: flex;
    align-items: center;
    gap: 20px;
}

.profile-avatar-box {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    position: relative;
}
.profile-avatar-box:hover {
    border-color: var(--primary);
    opacity: 0.85;
}
.profile-avatar-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.profile-avatar-box svg {
    color: var(--text-muted);
}

.profile-username {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.profile-avatar-btn {
    font-size: 0.8rem;
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--primary);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}
.profile-avatar-btn:hover {
    background: var(--primary-ghost);
    border-color: var(--primary);
}

.profile-form {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.profile-field {
    flex: 1;
    min-width: 200px;
}
.profile-field-full {
    flex-basis: 100%;
    min-width: 100%;
}

.profile-field label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}
.profile-field label svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.profile-field input,
.profile-field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all var(--transition);
}
.profile-field input:focus,
.profile-field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,113,227,0.1);
}
.profile-field textarea {
    resize: vertical;
    min-height: 70px;
}

.profile-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.profile-msg {
    font-size: 0.84rem;
    flex: 1;
    min-width: 0;
}
.profile-msg-success { color: var(--accent); }
.profile-msg-error { color: #e74c3c; }

/* ===== Document viewer (PDF + Word) ===== */
.doc-viewer-container {
    margin: 20px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.doc-viewer-container iframe {
    width: 100%;
    height: 600px;
    border: none;
    display: block;
}

.doc-viewer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}

.doc-viewer-toolbar svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.doc-viewer-toolbar .doc-filename {
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-viewer-toolbar .doc-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.doc-viewer-toolbar a {
    color: var(--primary);
    font-size: 0.78rem;
    white-space: nowrap;
    text-decoration: none;
    flex-shrink: 0;
}

.doc-viewer-toolbar a:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

.doc-word-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 24px;
    color: var(--text-muted);
    background: var(--bg-card);
    text-align: center;
}

.doc-word-placeholder svg {
    opacity: 0.5;
}

.doc-word-placeholder p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.6;
}

@media (max-width: 768px) {
    .doc-viewer-container iframe {
        height: 400px;
    }
    .doc-word-placeholder {
        padding: 32px 16px;
    }
}

/* ===== Responsive additions ===== */
@media (max-width: 768px) {
    .form-row { flex-direction: column; gap: 0; }
    .modal { padding: 24px 20px 20px; }
    .btn-new-article span { display: none; }
    .btn-new-article { padding: 6px 10px; }
    .btn-background span { display: none; }
    .btn-background { padding: 6px 10px; }
}

/* ===== Visual polish layer ===== */
:root {
    --bg: #fbfcff;
    --bg-secondary: #f2f5f9;
    --bg-sidebar: rgba(246, 248, 252, 0.92);
    --text: #18202f;
    --text-secondary: #607086;
    --text-muted: #91a0b4;
    --border: #dce4ee;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-ghost: #eff6ff;
    --accent: #10b981;
    --accent-light: #e9fbf4;
    --warm: #f59e0b;
    --rose: #f43f5e;
    --code-bg: #f6f8fb;
    --card-shadow: 0 1px 2px rgba(24, 32, 47, 0.04), 0 10px 30px rgba(31, 41, 55, 0.08);
    --card-hover-shadow: 0 18px 44px rgba(31, 41, 55, 0.12);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 8px;
    --surface: rgba(255, 255, 255, 0.78);
    --surface-strong: rgba(255, 255, 255, 0.92);
    --sidebar-surface-rgb: 246, 248, 252;
    --focus-ring: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

[data-theme="dark"] {
    --bg: #111827;
    --bg-secondary: #182233;
    --bg-sidebar: rgba(18, 26, 39, 0.92);
    --text: #f8fafc;
    --text-secondary: #a9b8cc;
    --text-muted: #738198;
    --border: #28374d;
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --primary-light: #1e3a5f;
    --primary-ghost: rgba(96, 165, 250, 0.14);
    --accent: #34d399;
    --accent-light: rgba(52, 211, 153, 0.12);
    --warm: #fbbf24;
    --rose: #fb7185;
    --code-bg: #0f172a;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.28), 0 16px 44px rgba(0, 0, 0, 0.28);
    --card-hover-shadow: 0 22px 54px rgba(0, 0, 0, 0.34);
    --surface: rgba(17, 24, 39, 0.76);
    --surface-strong: rgba(17, 24, 39, 0.94);
    --sidebar-surface-rgb: 18, 26, 39;
}

* {
    letter-spacing: 0;
}

body {
    background:
        radial-gradient(circle at 14% 8%, rgba(37, 99, 235, 0.10), transparent 30rem),
        radial-gradient(circle at 88% 16%, rgba(16, 185, 129, 0.10), transparent 28rem),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-secondary) 100%);
}

[data-theme="dark"] body {
    background:
        radial-gradient(circle at 14% 8%, rgba(96, 165, 250, 0.14), transparent 30rem),
        radial-gradient(circle at 88% 16%, rgba(52, 211, 153, 0.10), transparent 28rem),
        linear-gradient(180deg, #0f172a 0%, #111827 60%, #0b1120 100%);
}

.navbar {
    height: 58px;
    padding: 0 22px;
    gap: 14px;
    border-bottom-color: rgba(148, 163, 184, 0.24);
    background: rgba(255, 255, 255, 0.78);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.82), 0 10px 28px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] .navbar {
    background: rgba(15, 23, 42, 0.80);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

.layout {
    padding-top: 58px;
}

.logo {
    font-size: 1.04rem;
}

.logo svg {
    color: var(--accent);
    filter: drop-shadow(0 5px 12px rgba(16, 185, 129, 0.26));
}

.logo-icon {
    width: 34px;
    height: 34px;
    box-shadow: 0 5px 14px rgba(15, 23, 42, 0.14);
}

.menu-toggle,
.theme-toggle,
.btn-new-article,
.btn-background,
.user-pill,
.editor-meta-btn,
.editor-theme-btn,
.editor-save-btn,
.editor-delete-btn,
.btn-submit,
.btn-secondary,
.btn-danger,
.pagination button,
.back-to-top {
    min-height: 34px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55) inset;
}

.search-box {
    max-width: 520px;
}

.search-box input {
    height: 40px;
    border-color: transparent;
    border-radius: 999px;
    background: rgba(241, 245, 249, 0.92);
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.26);
}

[data-theme="dark"] .search-box input {
    background: rgba(15, 23, 42, 0.82);
}

.search-box input:focus {
    border-color: transparent;
    background: var(--surface-strong);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.42), var(--focus-ring);
}

.sidebar {
    top: 58px;
    width: 288px;
    background: rgba(var(--sidebar-surface-rgb), var(--sidebar-bg-opacity));
    border-right-color: rgba(148, 163, 184, 0.28);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.main {
    margin-left: 288px;
    min-height: calc(100vh - 58px);
}

.sidebar-header {
    padding: 22px 18px 12px;
}

.sidebar-title,
.profile-section-title {
    font-size: 0.74rem;
    font-weight: 800;
    color: var(--text-muted);
}

.category-tree {
    padding: 4px 10px 16px;
}

.category-tree a {
    min-height: 34px;
    padding: 7px 10px;
    margin: 2px 0;
    border-left: 0;
    border-radius: var(--radius);
}

.category-tree a:hover,
.category-tree a.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(16, 185, 129, 0.08));
    color: var(--primary);
}

.category-tree a.active {
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.category-tree ul {
    margin-left: 14px;
    padding-left: 8px;
}

.content {
    max-width: 860px;
    padding-top: 54px;
}

.home-hero {
    position: relative;
    text-align: left;
    padding: 42px 0 30px;
}

.home-hero::before {
    content: '';
    display: block;
    width: 58px;
    height: 4px;
    margin-bottom: 20px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--warm));
}

.home-hero h1 {
    max-width: 720px;
    font-size: 3rem;
    line-height: 1.15;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text), var(--primary) 46%, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
}

.home-hero p {
    max-width: 620px;
    font-size: 1.05rem;
}

.daily-quote {
    margin: 4px 0 36px;
    padding: 22px 24px;
    text-align: left;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.58)),
        linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(16, 185, 129, 0.08));
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

[data-theme="dark"] .daily-quote {
    background:
        linear-gradient(135deg, rgba(15, 23, 42, 0.90), rgba(17, 24, 39, 0.70)),
        linear-gradient(135deg, rgba(96, 165, 250, 0.14), rgba(52, 211, 153, 0.10));
}

.daily-quote::before {
    top: -34px;
    left: auto;
    right: 18px;
    opacity: 0.08;
}

.daily-quote-label {
    margin-bottom: 8px;
    font-size: 0.72rem;
}

.daily-quote blockquote {
    font-size: 1.08rem;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 34px 0 18px;
}

.section-header h1,
.section-header h2 {
    flex: 0 0 auto;
    font-weight: 800;
}

.section-line {
    flex: 1;
    width: auto;
    height: 1px;
    margin-top: 2px;
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.52), rgba(16, 185, 129, 0.18), transparent);
}

.article-list {
    gap: 12px;
}

.article-list li {
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.article-list li::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: linear-gradient(180deg, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity var(--transition);
}

.article-list li:hover {
    border-color: rgba(37, 99, 235, 0.30);
    box-shadow: var(--card-hover-shadow);
    transform: translateY(-2px);
}

.article-list li:hover::before {
    opacity: 1;
}

.article-list li a {
    padding: 18px 22px 8px;
    font-size: 1.04rem;
    font-weight: 800;
}

.article-excerpt {
    padding: 0 22px 12px;
}

.article-list .meta {
    padding: 0 22px 16px;
}

.article-list .tag,
.article-meta .tag {
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.10);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.10);
}

.breadcrumb {
    margin-bottom: 26px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.article {
    font-size: 1rem;
    line-height: 1.82;
}

#articleContent.article {
    padding: 2px 2px 0;
}

.article h1 {
    max-width: 840px;
    font-size: 2.18rem;
    line-height: 1.22;
    margin-bottom: 12px;
}

.article-meta {
    margin-bottom: 30px;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}

.article h2 {
    margin-top: 42px;
    padding-left: 18px;
}

.article h2::before {
    width: 5px;
    background: linear-gradient(180deg, var(--primary), var(--accent));
}

.article p {
    margin-bottom: 16px;
}

.article a {
    text-underline-offset: 4px;
}

.article a:hover {
    text-decoration: underline;
}

.article blockquote {
    padding: 16px 20px;
    border-left: 0;
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, rgba(16, 185, 129, 0.11), rgba(37, 99, 235, 0.08));
    box-shadow: inset 3px 0 0 var(--accent);
}

.article pre {
    border-color: rgba(148, 163, 184, 0.28);
    box-shadow: 0 12px 34px rgba(15, 23, 42, 0.08);
}

.article pre code {
    padding: 22px 22px;
}

.article table {
    display: block;
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: separate;
    border-spacing: 0;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.article th {
    background: linear-gradient(180deg, var(--bg-secondary), rgba(226, 232, 240, 0.42));
}

.article img,
.doc-viewer-container,
.profile-container,
.modal,
.user-dropdown {
    border-radius: var(--radius);
}

.pagination button.active,
.btn-submit,
.editor-save-btn,
.btn-back {
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
}

.btn-submit:hover,
.editor-save-btn:hover,
.btn-back:hover {
    filter: brightness(1.03);
    transform: translateY(-1px);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
}

.btn-secondary:hover,
.btn-new-article:hover,
.btn-background:hover,
.theme-toggle:hover,
.menu-toggle:hover,
.user-pill:hover {
    transform: translateY(-1px);
}

.empty-state {
    margin: 24px auto;
    max-width: 520px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--card-shadow);
}

.back-to-top {
    background: var(--surface-strong);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.toc-nav {
    top: calc(50vh + 20px);
    padding-left: 14px;
    border-left-color: rgba(148, 163, 184, 0.34);
}

.toc-item.active {
    color: var(--primary);
}

.site-footer {
    color: var(--text-secondary);
    background: transparent;
    border-top-color: rgba(148, 163, 184, 0.22);
}

.modal-overlay {
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal {
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: var(--surface-strong);
}

.form-group input,
.form-group textarea,
.form-group select,
.profile-field input,
.profile-field textarea,
.cat-edit-form input,
.cat-edit-form textarea,
.cat-edit-form select,
.editor-meta-field input,
.editor-meta-field select {
    border-color: rgba(148, 163, 184, 0.32);
    background: var(--surface-strong);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.profile-field input:focus,
.profile-field textarea:focus,
.cat-edit-form input:focus,
.cat-edit-form textarea:focus,
.cat-edit-form select:focus,
.editor-meta-field input:focus,
.editor-meta-field select:focus {
    box-shadow: var(--focus-ring);
}

.editor-topbar,
.editor-meta-bar {
    border-bottom-color: rgba(148, 163, 184, 0.24);
    background: var(--surface-strong);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] .editor-topbar,
[data-theme="dark"] .editor-meta-bar {
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

.editor-pane-left textarea {
    padding: 24px 28px;
}

.editor-pane-right {
    background:
        linear-gradient(180deg, rgba(37, 99, 235, 0.04), transparent 260px),
        var(--bg-secondary);
}

.editor-preview-content {
    padding: 28px 36px;
}

@media (max-width: 900px) {
    .navbar {
        padding: 0 12px;
        gap: 8px;
    }

    .logo span {
        display: none;
    }

    .user-name {
        display: none;
    }
}

@media (max-width: 768px) {
    .layout {
        padding-top: 58px;
    }

    .sidebar {
        width: min(86vw, 308px);
    }

    .content {
        padding: 30px 16px 68px;
    }

    .home-hero {
        padding: 26px 0 22px;
    }

    .home-hero h1 {
        font-size: 2.2rem;
    }

    .daily-quote {
        padding: 18px 18px;
    }

    .section-header {
        margin-top: 28px;
    }

    .article-list li a {
        padding: 16px 16px 8px;
    }

    .article-excerpt,
    .article-list .meta {
        padding-left: 16px;
        padding-right: 16px;
    }

    .article h1 {
        font-size: 1.64rem;
    }

    .article h2 {
        font-size: 1.22rem;
        margin-top: 34px;
    }

    .editor-preview-content {
        padding: 18px 18px;
    }
}

@media (min-width: 1100px) {
    .content {
        max-width: 1120px;
    }
}

@media (min-width: 1300px) {
    .content {
        max-width: 1240px;
    }

    #articlePage .article-main {
        max-width: 960px;
    }
}

/* ===== Mobile usability layer ===== */
@media (max-width: 768px) {
    html {
        scroll-padding-top: calc(var(--navbar-height) + 10px);
    }

    body.mobile-nav-open {
        overflow: hidden;
        touch-action: none;
    }

    .sidebar {
        z-index: 102;
        overscroll-behavior: contain;
    }

    .main,
    body.sidebar-collapsed .main {
        margin-left: 0;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 58px 0 0;
        z-index: 101;
        display: block;
        width: 100%;
        height: auto;
        padding: 0;
        border: 0;
        background: rgba(15, 23, 42, 0.46);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    .sidebar.open ~ .sidebar-overlay {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .menu-toggle,
    .theme-toggle,
    .btn-new-article,
    .btn-background,
    .user-pill,
    .sidebar-login,
    .sidebar-overview,
    .category-tree a,
    .cat-toggle,
    .btn-add-cat,
    .pagination button,
    .modal-close,
    .profile-avatar-btn,
    .btn-submit,
    .btn-secondary,
    .btn-danger {
        min-height: 44px;
    }

    .content {
        width: 100%;
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: calc(72px + env(safe-area-inset-bottom));
        padding-left: max(16px, env(safe-area-inset-left));
    }

    .breadcrumb {
        gap: 6px;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
    }

    .breadcrumb::-webkit-scrollbar {
        display: none;
    }

    .article,
    .article p,
    .article li,
    .article a,
    .category-intro,
    .article-excerpt {
        overflow-wrap: anywhere;
    }

    .article pre {
        margin-right: -4px;
        margin-left: -4px;
        border-radius: 10px;
    }

    .article pre code {
        padding: 18px 16px;
        font-size: 0.8rem;
        overflow-wrap: normal;
        word-break: normal;
    }

    .article table {
        width: 100%;
        max-width: 100%;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .article th,
    .article td {
        padding: 9px 11px;
    }

    .article img,
    .mermaid,
    .doc-viewer-container {
        height: auto;
        max-width: 100%;
    }

    .child-category-entry {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 5px 10px;
    }

    .child-category-url {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .article-list .tags {
        width: 100%;
        margin-left: 0;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .pagination {
        justify-content: flex-start;
        max-width: 100%;
        padding: 2px 0 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .pagination button {
        flex: 0 0 auto;
        min-width: 44px;
        padding: 0 13px;
    }

    .modal-overlay {
        align-items: flex-end;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .modal {
        width: 100%;
        max-width: none;
        max-height: calc(100dvh - 16px);
        padding: 28px 20px calc(20px + env(safe-area-inset-bottom));
        overflow-y: auto;
        border-radius: 18px 18px 0 0;
        animation-name: modalInMobile;
    }

    @keyframes modalInMobile {
        from { opacity: 0; transform: translateY(24px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .background-preview {
        height: min(150px, 22dvh);
    }

    .form-group input,
    .form-group textarea,
    .form-group select,
    .profile-field input,
    .profile-field textarea,
    .cat-edit-form input,
    .cat-edit-form textarea,
    .cat-edit-form select {
        min-height: 44px;
        font-size: 16px;
    }

    .profile-field {
        flex-basis: 100%;
        min-width: 0;
    }

    .article-admin-actions,
    .profile-actions,
    .form-actions {
        align-items: stretch;
    }

    .article-admin-actions > button,
    .profile-actions > button {
        flex: 1 1 auto;
    }

    .back-to-top {
        width: 44px;
        height: 44px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: max(16px, env(safe-area-inset-right));
    }
}

@media (max-width: 560px) {
    :root {
        --navbar-height: 104px;
    }

    .navbar {
        height: var(--navbar-height);
        padding: max(6px, env(safe-area-inset-top)) 10px 8px;
        gap: 6px;
        flex-wrap: wrap;
        align-content: center;
    }

    .navbar .logo {
        min-width: 0;
        margin-right: auto;
    }

    .navbar .search-box {
        order: 10;
        flex: 1 0 100%;
        width: 100%;
        margin: 0;
    }

    .navbar .search-box input {
        height: 40px;
        font-size: 16px;
    }

    .navbar .user-pill {
        width: 44px;
        padding: 0;
        justify-content: center;
    }

    .navbar .user-pill > svg:last-child {
        display: none;
    }

    .navbar .btn-new-article,
    .navbar .btn-background,
    .navbar .theme-toggle,
    .navbar .menu-toggle {
        width: 44px;
        padding: 0;
        align-items: center;
        justify-content: center;
    }

    .layout {
        padding-top: var(--navbar-height);
    }

    .sidebar {
        top: var(--navbar-height);
        width: min(88vw, 320px);
    }

    .sidebar-overlay {
        inset-block-start: var(--navbar-height);
    }

    .main {
        min-height: calc(100vh - var(--navbar-height));
    }

    .home-hero h1 {
        font-size: clamp(2rem, 10vw, 2.4rem);
    }

    .daily-quote {
        margin-bottom: 26px;
        padding: 17px 16px;
    }

    .section-header h1,
    .section-header h2 {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .article-list li a {
        font-size: 1rem;
    }

    .article h1 {
        font-size: clamp(1.5rem, 8vw, 1.8rem);
    }

    .article h2 {
        padding-left: 14px;
    }

    .article blockquote {
        margin: 18px 0;
        padding: 14px 15px;
    }

    .doc-viewer-container iframe {
        height: min(400px, 56dvh);
    }

    .doc-viewer-toolbar {
        padding: 8px 10px;
    }

    .profile-avatar-row {
        gap: 14px;
    }

    .profile-avatar-box {
        width: 68px;
        height: 68px;
    }

    .site-footer {
        padding-right: 16px;
        padding-left: 16px;
    }
}

/* The standalone editor needs fixed, predictable mobile bar heights. */
@media (max-width: 600px) {
    .editor-topbar {
        height: 92px;
        padding: 6px;
        display: grid;
        grid-template-columns: repeat(5, 32px) minmax(0, 1fr) auto auto;
        grid-template-rows: 36px 36px;
        gap: 4px;
    }

    .editor-back {
        grid-column: 1;
        grid-row: 1;
    }

    .editor-save-status {
        grid-column: 2;
        grid-row: 1;
    }

    .editor-title-input {
        grid-column: 3 / -1;
        grid-row: 1;
        width: 100%;
        height: 34px;
        font-size: 16px;
    }

    #edUploadImg { grid-column: 1; grid-row: 2; }
    #edUploadPdf { grid-column: 2; grid-row: 2; }
    #edUploadWord { grid-column: 3; grid-row: 2; }
    #edUploadMd { grid-column: 4; grid-row: 2; }
    .editor-theme-btn { grid-column: 5; grid-row: 2; }

    .editor-save-btn {
        grid-column: 7;
        grid-row: 2;
        min-width: 52px;
    }

    .editor-delete-btn {
        grid-column: 8;
        grid-row: 2;
        min-width: 52px;
        padding: 0 10px;
    }

    .editor-meta-bar {
        top: 92px;
        height: 130px;
        padding: 7px 10px;
        flex-flow: column nowrap;
        align-items: stretch;
        gap: 5px;
        overflow-y: auto;
    }

    .editor-meta-field {
        display: grid;
        grid-template-columns: 92px minmax(0, 1fr);
        width: 100%;
        gap: 8px;
    }

    .editor-meta-field input,
    .editor-meta-field select {
        width: 100%;
        min-width: 0;
        height: 34px;
        font-size: 16px;
    }

    .editor-main {
        top: 222px;
    }

    .editor-pane-left textarea {
        padding: 14px;
        font-size: 16px;
    }

    .editor-preview-content {
        padding: 16px;
    }
}

@media (max-width: 360px) {
    .navbar .logo {
        display: none;
    }

    .navbar .menu-toggle {
        margin-right: auto;
    }

    .editor-topbar {
        grid-template-columns: repeat(5, 30px) minmax(0, 1fr) auto auto;
        gap: 3px;
    }

    .editor-save-btn,
    .editor-delete-btn {
        min-width: 48px;
        padding: 0 8px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .article-list li:hover,
    .btn-submit:hover,
    .editor-save-btn:hover,
    .btn-back:hover,
    .btn-secondary:hover,
    .btn-new-article:hover,
    .btn-background:hover,
    .theme-toggle:hover,
    .menu-toggle:hover,
    .user-pill:hover {
        transform: none;
    }
}
