:root {
    --bg: #1b1c1d;
    --bg-secondary: #232425;
    --bg-card: #2d2e2f;
    --text: #e0e0e0;
    --text-muted: #909399;
    --accent: #4183c4;
    --border: #3a3b3c;
    --sidebar-width: 280px;
}

body.dark {
    background: var(--bg);
    color: var(--text);
}

/* Wiki sidebar */
.wiki-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
}
.wiki-sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.wiki-sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--header-color, white);
    text-decoration: none;
}
.wiki-sidebar-logo:hover {
    text-decoration: none;
    opacity: 0.85;
}
.wiki-sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.wiki-sidebar-search .ui.input input {
    background: var(--bg) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    border-radius: 4px !important;
}

/* Tree */
.wiki-sidebar-tree {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}
.tree-shelf {
    margin-bottom: 4px;
}
.tree-shelf-name {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}
.tree-shelf-name:hover {
    background: var(--bg-card);
    text-decoration: none;
    color: white;
}
.tree-shelf-name i.icon { font-size: 13px; width: 16px; text-align: center; margin: 0; color: var(--text-muted); }

.tree-book {
    margin-left: 8px;
}
.tree-book-name {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 16px 5px 24px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
}
.tree-book-name:hover {
    background: var(--bg-card);
    text-decoration: none;
    color: var(--text);
}
.tree-book-name i.icon { font-size: 12px; width: 14px; text-align: center; margin: 0; }

.tree-chapter {
    margin-left: 8px;
}
.tree-chapter-name {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px 4px 40px;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.tree-chapter-name i.icon { font-size: 11px; width: 14px; text-align: center; margin: 0; }

.tree-page {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px 4px 48px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
}
.tree-page:hover {
    background: var(--bg-card);
    text-decoration: none;
    color: var(--accent);
}
.tree-page i.icon { font-size: 12px; width: 14px; text-align: center; margin: 0; }

/* Loose pages (no chapter) — less indent */
.tree-book > .tree-page {
    padding-left: 40px;
}

/* Admin link */
.wiki-sidebar-admin {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.wiki-sidebar-admin:hover {
    background: var(--bg-card);
    color: var(--text);
    text-decoration: none;
}
.wiki-sidebar-admin i.icon { margin: 0; }

/* Footer */
.wiki-sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.wiki-sidebar-email {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}
.wiki-sidebar-logout {
    color: var(--text-muted);
    font-size: 12px;
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
}
.wiki-sidebar-logout:hover {
    color: var(--text);
    border-color: var(--text-muted);
    text-decoration: none;
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 32px 48px;
    max-width: 1000px;
    min-height: 100vh;
}

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    cursor: zoom-out;
    align-items: center;
    justify-content: center;
}
.lightbox.active {
    display: flex;
}
.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.5);
}
.page-body img {
    cursor: zoom-in;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active {
    display: flex;
}
.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.modal-close:hover {
    color: var(--text);
}

/* Compact user table */
.user-table {
    font-size: 13px !important;
}
.user-table td, .user-table th {
    padding: 6px 10px !important;
    white-space: nowrap;
}
.user-table td:nth-child(2) {
    color: var(--text-muted);
}
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    font-size: 13px;
    padding: 0;
    vertical-align: middle;
    text-decoration: none;
}
.icon-btn:hover {
    color: var(--text);
    background: var(--bg-card);
    text-decoration: none;
}
.icon-btn i.icon {
    margin: 0 !important;
    font-size: 13px;
}
.icon-btn--on {
    color: #21ba45;
}
.icon-btn--on:hover {
    color: #ff6b6b;
}
.icon-btn--danger:hover {
    color: #ff4444;
}
.group-tag {
    display: inline-block;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
    margin: 1px 2px;
}

/* Login */
.login-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 12px;
    width: 380px;
    max-width: 90vw;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}
.login-card h1 {
    color: white;
    text-align: center;
    margin: 0 0 24px 0;
    font-size: 28px;
}
.login-card .ui.form .field {
    margin-bottom: 16px;
}
.login-card .ui.form .field label {
    color: var(--text-muted) !important;
    margin-bottom: 6px;
}
.login-card .ui.form input[type="email"],
.login-card .ui.form input[type="password"] {
    background: var(--bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    padding: 10px 14px !important;
}
.login-card .ui.form input:focus {
    border-color: var(--accent) !important;
}
.login-card .ui.button {
    margin-top: 8px;
}
.login-card .ui.negative.message {
    background: rgba(219, 40, 40, 0.15) !important;
    color: #ff6b6b !important;
    border: 1px solid rgba(219, 40, 40, 0.3);
    box-shadow: none !important;
}

/* Cards */
.ui.cards .card, .ui.card {
    background: var(--bg-card) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3) !important;
    border: 1px solid var(--border) !important;
}
.ui.card .header, .ui.cards .card .header {
    color: var(--text) !important;
}
.ui.card .meta, .ui.cards .card .meta,
.ui.card .description, .ui.cards .card .description {
    color: var(--text-muted) !important;
}
.ui.card:hover {
    border-color: var(--accent) !important;
    transform: translateY(-1px);
    transition: all 0.15s;
}

/* Page content */
.page-body {
    color: var(--text);
    line-height: 1.7;
}
.page-body h1 { font-size: 1.8em; margin: 0.6em 0 0.3em; color: white; }
.page-body h2 { font-size: 1.4em; margin: 0.6em 0 0.3em; color: #ccc; }
.page-body h3 { font-size: 1.2em; margin: 0.5em 0 0.3em; color: #bbb; }
.page-body a { color: var(--accent); }
.page-body pre {
    background: #161718;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin: 1em 0;
}
.page-body code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.9em;
}
.page-body code:not(pre code) {
    background: #161718;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid var(--border);
}
.page-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}
.page-body th, .page-body td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.page-body th {
    background: var(--bg-secondary);
    color: #ccc;
    font-weight: 600;
}
.page-body blockquote {
    border-left: 4px solid var(--accent);
    padding: 8px 16px;
    margin: 1em 0;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: 0 6px 6px 0;
}
.page-body ul, .page-body ol {
    margin: 0.5em 0;
    padding-left: 2em;
}
.page-body li { margin: 0.3em 0; }
.page-body img { max-width: 100%; border-radius: 6px; }

/* Search */
.search-result {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.search-result:hover {
    background: var(--bg-secondary);
}
.search-result b {
    color: var(--accent);
}
.search-result .meta {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.5;
}

/* Overrides */
.ui.inverted.breadcrumb a {
    color: var(--accent) !important;
}
.ui.inverted.breadcrumb .active.section {
    color: var(--text) !important;
}
.ui.inverted.divider {
    border-color: var(--border) !important;
}
h1, h2, h3 {
    color: var(--header-color, white);
}
.ui.label {
    background: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border) !important;
}

/* Recent list */
.recent-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.recent-item a {
    color: var(--text);
}
.recent-item a:hover {
    color: var(--accent);
}
.recent-item .meta {
    color: var(--text-muted);
    font-size: 12px;
}

/* Admin sidebar */
.admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    z-index: 100;
}
.admin-sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.admin-sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--header-color, white);
    text-decoration: none;
}
.admin-sidebar-logo:hover {
    text-decoration: none;
    opacity: 0.85;
}
.admin-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 3px 7px;
    border-radius: 3px;
    line-height: 1;
}
.admin-nav {
    padding: 8px 0;
}
.admin-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: background 0.1s, color 0.1s;
}
.admin-nav-link:hover {
    background: var(--bg-card);
    color: var(--text);
    text-decoration: none;
}
.admin-nav-link.active {
    background: var(--bg-card);
    color: white;
    border-left-color: var(--accent);
}
.admin-nav-link i.icon {
    width: 18px;
    text-align: center;
    font-size: 14px;
    margin: 0;
}
.admin-sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 20px;
}
.admin-sidebar-footer {
    margin-top: auto;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.admin-sidebar-email {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}
.admin-sidebar-logout {
    color: var(--text-muted);
    font-size: 12px;
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
}
.admin-sidebar-logout:hover {
    color: var(--text);
    border-color: var(--text-muted);
    text-decoration: none;
}

/* Admin content header */
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.admin-header h1 {
    margin: 0;
    font-size: 24px;
}

/* Forms (dark theme) */
.ui.inverted.form input[type="text"],
.ui.inverted.form input[type="email"],
.ui.inverted.form input[type="password"],
.ui.inverted.form textarea,
.ui.inverted.form select {
    background: var(--bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 4px !important;
}
.ui.inverted.form input:focus,
.ui.inverted.form textarea:focus,
.ui.inverted.form select:focus {
    border-color: var(--accent) !important;
}
.ui.inverted.form .field > label {
    color: var(--text-muted) !important;
}
.ui.inverted.form select option {
    background: var(--bg-card);
    color: var(--text);
}
.ui.inverted.form .ui.dropdown {
    background: var(--bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}
.ui.negative.message {
    background: rgba(219, 40, 40, 0.15) !important;
    color: #ff6b6b !important;
    border: 1px solid rgba(219, 40, 40, 0.3) !important;
    box-shadow: none !important;
}

/* Quill editor dark theme */
#quill-editor {
    min-height: 400px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 4px 4px;
    font-size: 15px;
    line-height: 1.7;
}
#quill-editor .ql-editor {
    min-height: 400px;
}
#quill-editor .ql-editor.ql-blank::before {
    color: var(--text-muted);
    font-style: normal;
}
.ql-toolbar.ql-snow {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 4px 4px 0 0;
}
.ql-toolbar .ql-stroke {
    stroke: var(--text-muted) !important;
}
.ql-toolbar .ql-fill {
    fill: var(--text-muted) !important;
}
.ql-toolbar .ql-picker-label {
    color: var(--text-muted) !important;
}
.ql-toolbar button:hover .ql-stroke,
.ql-toolbar .ql-picker-label:hover .ql-stroke {
    stroke: white !important;
}
.ql-toolbar button:hover .ql-fill,
.ql-toolbar .ql-picker-label:hover .ql-fill {
    fill: white !important;
}
.ql-toolbar button.ql-active .ql-stroke {
    stroke: var(--accent) !important;
}
.ql-toolbar button.ql-active .ql-fill {
    fill: var(--accent) !important;
}
.ql-toolbar .ql-picker-options {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
}
.ql-toolbar .ql-picker-item {
    color: var(--text) !important;
}
.ql-toolbar .ql-picker-item:hover {
    color: var(--accent) !important;
}
.ql-snow .ql-editor pre.ql-syntax {
    background: #161718;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.ql-snow .ql-editor blockquote {
    border-left-color: var(--accent);
    color: var(--text-muted);
}
.ql-container.ql-snow {
    border: none !important;
}
