:root {
    --color-primary:     #1f8a70;
    --color-secondary:   #2f4b7c;
    --color-danger:      #c0392b;
    --color-bg:          #f2f5ee;
    --color-surface:     #ffffff;
    --color-text:        #1a2333;
    --color-link:        #0f5f6d;
    --color-sidebar-bg:  #10243f;
    --color-sidebar-text:#d9ecff;
    --color-border:      #c9d8ec;
}
* { box-sizing: border-box; }
.sticky-nav { position: sticky; bottom: 0; margin-top: auto; display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 1rem; background: rgba(242,245,238,0.95); backdrop-filter: blur(4px); border-top: 1px solid rgba(0,0,0,0.08); }
.chapter-nav-prev { margin-right: auto; }
.chapter-nav-next { margin-left: auto; }
.book-tag { display: inline-block; font-size: 0.75rem; background: #e0eef2; color: var(--color-link); border-radius: 3px; padding: 0.1rem 0.4rem; margin-bottom: 0.25rem; }
.tag-input-wrap { position: relative; }
.tag-suggestions { position: absolute; z-index: 100; background: var(--color-surface); border: 1px solid #ccc; border-radius: 4px; margin: 0; padding: 0; list-style: none; min-width: 200px; box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.tag-suggestions li { padding: 0.4rem 0.75rem; cursor: pointer; }
.tag-suggestions li:hover, .tag-suggestions li.active { background: #e8f4f6; }
body { margin: 0; font-family: "Avenir Next", "Segoe UI", sans-serif; background: var(--color-bg); color: var(--color-text); }
a { color: var(--color-link); text-decoration: none; }
hr { border: none; height: 6px; background: linear-gradient(to bottom, rgba(0,0,0,0.08), transparent); border-radius: 3px; margin: 1.5rem 0; }

/* ── Layout ─────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }
.main { flex: 1; min-width: 0; overflow-y: auto; display: flex; flex-direction: column; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    overflow: hidden;
}
.sidebar.collapsed { width: 0; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}
.sidebar-toggle {
    background: none; border: none; color: #8aa3be;
    cursor: pointer; font-size: 1.1rem; padding: 0.2rem 0.4rem;
    border-radius: 0.3rem; flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.08); color: #fff; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.5rem 0.5rem; }
.sidebar-section-label {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: #5f7e9e; padding: 0.6rem 0.5rem 0.3rem; white-space: nowrap;
}
.sidebar-link {
    display: block; padding: 0.45rem 0.75rem; border-radius: 0.4rem;
    color: var(--color-sidebar-text); font-size: 0.9rem; white-space: nowrap;
}
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-admin { color: #f0c75e; margin-bottom: 0.5rem; }

.sidebar-book-item { margin-bottom: 0.15rem; }
.sidebar-book-row { display: flex; align-items: center; gap: 0.2rem; }
.sidebar-book-row form:first-child { flex: 1; min-width: 0; }
.sidebar-submit-btn {
    background: none; border: 1px solid rgba(255,255,255,0.2); color: #8aa3be;
    border-radius: 0.3rem; cursor: pointer; font-size: 1rem; padding: 0.1rem 0.3rem;
    flex-shrink: 0; line-height: 1;
}
.sidebar-submit-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-book-btn {
    width: 100%; text-align: left; background: none; border: none;
    color: var(--color-sidebar-text); padding: 0.45rem 0.75rem; border-radius: 0.4rem;
    cursor: pointer; font-size: 0.9rem; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-book-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-book-btn.active { background: rgba(255,255,255,0.12); color: #fff; font-weight: 600; }

.sidebar-chapters { padding-left: 0.75rem; margin-top: 0.1rem; }
.sidebar-chapter-link {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.3rem 0.5rem; border-radius: 0.35rem;
    color: #8aa3be; font-size: 0.82rem; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.sidebar-chapter-link:hover { background: rgba(255,255,255,0.06); color: var(--color-sidebar-text); }
.sidebar-chapter-new { color: #5f9ea0; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.dot.draft { background: #8aa3be; }
.dot.pending_review { background: #f0c75e; }
.dot.published { background: #5db87a; }
.dot.rejected { background: #e07070; }

/* ── Sidebar footer / user area ──────────────────────────── */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 0.65rem 0.75rem;
    position: relative;
}
.sidebar-user { display: flex; align-items: center; gap: 0.6rem; }
.user-menu-btn {
    background: none; border: none; color: #8aa3be;
    cursor: pointer; font-size: 1.2rem; padding: 0.25rem 0.4rem;
    border-radius: 0.35rem; line-height: 1; flex-shrink: 0;
}
.user-menu-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.user-meta { min-width: 0; }
.user-name { display: block; color: #fff; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; color: #5f7e9e; font-size: 0.72rem; }

/* ── Popup menu ──────────────────────────────────────────── */
.popup-menu {
    position: absolute;
    bottom: calc(100% + 0.4rem);
    left: 0.5rem;
    right: 0.5rem;
    background: #1a3352;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    padding: 0.3rem;
    z-index: 100;
}
.popup-item {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; text-align: left; background: none; border: none;
    color: var(--color-sidebar-text); padding: 0.55rem 0.7rem; border-radius: 0.35rem;
    cursor: pointer; font-size: 0.88rem;
}
.popup-item:hover { background: rgba(255,255,255,0.08); }
.popup-chevron { color: #5f7e9e; font-size: 1rem; }
.popup-lang-list { padding: 0.1rem 0 0.1rem 0.3rem; }
.popup-lang-option {
    display: flex; align-items: center; gap: 0.5rem;
    width: 100%; text-align: left; background: none; border: none;
    color: var(--color-sidebar-text); padding: 0.45rem 0.7rem; border-radius: 0.3rem;
    cursor: pointer; font-size: 0.85rem;
}
.popup-lang-option:hover { background: rgba(255,255,255,0.08); }
.popup-check { width: 1rem; display: inline-block; color: #5db87a; font-weight: 700; }
.popup-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 0.3rem 0; }
.popup-logout { color: #e07070; }
.popup-logout:hover { background: rgba(224,112,112,0.1); }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1rem; background: var(--color-sidebar-bg); color: #fff; flex-shrink: 0;
    position: sticky; top: 0; z-index: 40;
}
.topbar-menu-btn {
    background: none; border: none; color: #8aa3be;
    font-size: 1.2rem; cursor: pointer; padding: 0.2rem 0.4rem;
    border-radius: 0.3rem; display: none;
}
.topbar-menu-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.sidebar.collapsed ~ .main .topbar-menu-btn,
.layout:not(:has(.sidebar)) .topbar-menu-btn { display: inline-block; }
.brand { font-weight: 700; color: #fff; font-size: 1rem; }
.topbar-nav { display: flex; gap: 0.75rem; margin-left: auto; }
.topbar-nav a { color: var(--color-sidebar-text); }
.topbar-nav a:hover { color: #fff; }

/* ── Content area ────────────────────────────────────────── */
.container { max-width: 1000px; margin: 0 auto; padding: 1rem; flex: 1; }
.hero { padding: 2rem 0; }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.btn, button { background: var(--color-primary); color: #fff; border: 0; padding: 0.55rem 0.85rem; border-radius: 0.45rem; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-alt { background: var(--color-secondary); }
.btn-danger { background: var(--color-danger); }
.btn-secondary { background: transparent; color: var(--color-secondary); border: 1px solid var(--color-border); padding: 0.45rem 0.75rem; border-radius: 0.45rem; cursor: pointer; text-decoration: none; display: inline-block; font-size: 0.9rem; }
.btn-secondary:hover { background: #edf0f7; }
.card-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.75rem; flex-wrap: wrap; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 0.6rem; padding: 1rem; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
.stack { display: grid; gap: 0.75rem; max-width: 560px; }
input, select, textarea { width: 100%; padding: 0.55rem; border-radius: 0.45rem; border: 1px solid #b3c2d4; font-family: inherit; font-size: inherit; }
textarea { resize: vertical; }
.notice { background: #fff8e1; border: 1px solid #f0c75e; border-radius: 0.5rem; padding: 0.85rem 1rem; margin-bottom: 1rem; }
.writer-cta { background: #f0f4ff; border: 1px solid #c0cfe8; border-radius: 0.6rem; padding: 1rem 1.25rem; margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.writer-cta p { margin: 0; flex: 1; min-width: 200px; color: var(--color-secondary); }
.form-error { color: var(--color-danger); background: #fdecea; border: 1px solid #f5c6cb; border-radius: 0.4rem; padding: 0.6rem 0.9rem; margin-bottom: 0.75rem; }
.book-type-badge { display: inline-block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.15rem 0.5rem; border-radius: 999px; margin-bottom: 0.4rem; }
.book-type-badge.open { background: #e0f7e9; color: #1a6b3a; }
.book-type-badge.closed { background: #e8edf6; color: #2a4080; }
.pin-count { font-size: 0.85rem; color: #666; margin: 0.3rem 0 0; }
.form-hint { font-size: 0.9rem; color: #666; margin-top: 0.5rem; }
.notice p { margin: 0 0 0.5rem; }
.notice details summary { cursor: pointer; font-weight: 600; }
.notice ol { margin: 0.5rem 0 0 1.2rem; padding: 0; }
.preview-widget { margin-top: 1rem; }
#preview-area, .preview-area { margin-top: 0.75rem; border: 1px solid #b9c8da; background: var(--color-surface); border-radius: 0.5rem; padding: 0.8rem; min-height: 90px; }
.status { font-size: 0.8rem; padding: 0.2rem 0.5rem; border-radius: 999px; }
.status.draft { background: #e8edf6; }
.status.pending_review { background: #ffe8b8; }
.status.published { background: #cdeed8; }
.status.rejected { background: #ffd1d1; }
.like-btn { margin-top: 0.8rem; }
.share { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.8rem; }
.markdown img { max-width: 100%; }
table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
th, td { border: 1px solid #c7d7eb; padding: 0.45rem; vertical-align: top; }
.footer { text-align: center; padding: 1rem; color: #53657c; }
.badge { background: #f0c75e; color: #2b1f00; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.8rem; }
.inline { display: inline; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 680px) {
    .sidebar { position: fixed; top: 0; left: 0; height: 100vh; z-index: 200; }
    .sidebar.collapsed { width: 0; }
    .topbar-menu-btn { display: inline-block !important; }
    .container { padding: 0.75rem; }
}
