:root {
    --primary-color: #273240;
    --primary-hover: #2563eb;
    --bg-color: #f3f4f6;
    --sidebar-bg: #ffffff;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --sidebar-width: 240px;
    --header-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.sidebar-nav ul li a {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--text-color);
    transition: background-color 0.2s;
    gap: 10px;
}

.sidebar-nav ul li a:hover,
.sidebar-nav ul li a.active {
    background-color: #f9fafb;
    color: var(--primary-color);
}

.menu-label {
    padding: 10px 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 10px;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.user-profile-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.user-profile-toggle:hover {
    background-color: #f9fafb;
}

.user-profile-toggle i {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.user-dropdown {
    position: absolute;
    bottom: 70px;
    left: 20px;
    right: 20px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: none;
    z-index: 1000;
    overflow: hidden;
}

.user-dropdown.show {
    display: block;
    animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.user-dropdown ul {
    padding: 8px 0;
}

.user-dropdown ul li a {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-color);
    transition: background-color 0.2s;
}

.user-dropdown ul li a:hover {
    background-color: #f9fafb;
    color: var(--primary-color);
}

.user-dropdown hr {
    margin: 8px 0;
    border: 0;
    border-top: 1px solid var(--border-color);
}

.user-dropdown .logout-link {
    color: var(--error-color);
}

.user-dropdown .logout-link:hover {
    background-color: #fef2f2;
    color: var(--error-color);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

.topbar {
    height: var(--header-height);
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
}

#sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-muted);
    display: none;
    /* Hidden on desktop by default */
}

.content-wrapper {
    padding: 20px;
    flex: 1;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .layout.sidebar-collapsed .sidebar {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    #sidebar-toggle {
        display: block;
    }
}

/* Utilities */
.alert {
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
}

.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s;
}

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

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

.form-group {
    margin-bottom: 15px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Tree View Styles */
.book-item {
    border-bottom: 1px solid var(--border-color);
}

.book-link {
    font-weight: 600;
    /* background-color: #f9fafb; */
}

.book-tree {
    padding: 5px 0;
    background-color: #fff;
}

ul.navigation {
    list-style: none;
    padding-left: 0;
}

ul.navigation ul {
    padding-left: 15px;
    border-left: 1px solid #e5e7eb;
    margin-left: 10px;
}

ul.navigation li {
    padding: 4px 20px;
    font-size: 0.9rem;
    line-height: 1.4;
}

ul.navigation li a {
    color: var(--text-color);
    display: block;
    padding: 2px 0;
    text-decoration: none;
}

ul.navigation li a:hover {
    color: var(--primary-color);
}

ul.navigation li.current>strong {
    color: var(--primary-color);
    font-weight: 600;
    display: block;
    padding: 2px 0;
}

ul.navigation li.space>a::before {
    content: "\f07b";
    /* fa-folder */
    font-family: "Font Awesome 6 Free";
    font-weight: 400;
    /* Regular */
    margin-right: 8px;
    color: var(--text-muted);
}

ul.navigation li.page>a::before {
    content: "\f15b";
    /* fa-file-alt */
    font-family: "Font Awesome 6 Free";
    font-weight: 400;
    /* Regular */
    margin-right: 8px;
    color: var(--text-muted);
}

ul.navigation li.add>a {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 5px;
    display: inline-block;
}

ul.navigation li.add>a::before {
    content: "\f067";
    /* fa-plus */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    /* Solid */
    margin-right: 5px;
}

ul.navigation hr {
    border: 0;
    border-top: 1px solid #e5e7eb;
    margin: 10px 20px;
}

/* Back Button */
ul.navigation li.back-button a {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.2s;
}

ul.navigation li.back-button a:hover {
    color: var(--primary-color);
}

ul.navigation li.back-button a i {
    font-size: 0.8rem;
}

/* Current Space Header */
ul.navigation li.current-space-header {
    padding: 8px 20px;
    margin: 5px 0;
}

ul.navigation li.current-space-header strong {
    color: var(--primary-color);
    font-size: 1.05rem;
    font-weight: 700;
    display: block;
}


/* Content Body Fixes */
.content-body {
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
    max-width: 720px;
}

.content-body p {
    margin-bottom: 0.8em;
}

.content-body h1,
.content-body h2,
.content-body h3,
.content-body h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    color: #111827;
    line-height: 1.25;
}

.content-body h1 {
    font-size: 1.6rem;
}

.content-body h2 {
    font-size: 1.3rem;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.3em;
}

.content-body h3 {
    font-size: 1.15rem;
}

.content-body h4 {
    font-size: 1rem;
}

.content-body ul,
.content-body ol {
    list-style: revert;
    margin-left: 20px;
    margin-bottom: 0.8em;
}

.content-body ul li,
.content-body ol li {
    margin-bottom: 0.2em;
}

.content-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.content-body blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1em;
    margin-left: 0;
    margin-bottom: 0.8em;
    color: #4b5563;
    font-style: italic;
    background: #f9fafb;
    padding: 0.8em;
    border-radius: 0 8px 8px 0;
}

.content-body pre {
    background: #1f2937;
    color: #f3f4f6;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 0.8em;
}

.content-body code {
    background: #f3f4f6;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    color: #ef4444;
}

.content-body pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

/* Enhanced Link Styling */
.content-body a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
    font-weight: 500;
}

.content-body a:hover {
    color: var(--primary-hover);
    border-bottom-color: var(--primary-color);
}

.content-body a:visited {
    color: #7c3aed;
}

/* Enhanced Table Styling */
.content-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.content-body table thead {
    background: #f9fafb;
}

.content-body table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9em;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e5e7eb;
}

.content-body table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f3f4f6;
    color: #4b5563;
}

.content-body table tbody tr:hover {
    background: #f9fafb;
}

.content-body table tbody tr:last-child td {
    border-bottom: none;
}

/* Striped table rows for better readability */
.content-body table tbody tr:nth-child(even) {
    background: #fafafa;
}

.content-body table tbody tr:nth-child(even):hover {
    background: #f3f4f6;
}


/* Page Header */
.page-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 5px;
    line-height: 1.2;
}

.page-header .meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Table of Contents */
.page-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.page-body {
    flex: 1;
    min-width: 0;
    /* Prevent overflow */
}

.toc-container {
    width: 220px;
    position: sticky;
    top: 20px;
    background: #f9fafb;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.toc-title {
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 1rem;
}

.toc-list ul {
    list-style: none;
    padding-left: 0;
}

.toc-list li {
    margin-bottom: 5px;
}

.toc-list a {
    color: var(--text-muted);
    text-decoration: none;
}

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

/* Mobile TOC */
@media (max-width: 1024px) {
    .page-layout {
        flex-direction: column-reverse;
        /* TOC on top */
    }

    .toc-container {
        width: 100%;
        position: static;
        margin-bottom: 20px;
    }
}

/* Edit Page UI */
.edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.edit-actions {
    display: flex;
    gap: 10px;
}

.edit-title-input {
    font-size: 1.5rem;
    font-weight: 700;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 20px;
}

.horizontal-form {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-bottom: 20px;
}

.horizontal-form .form-group {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.horizontal-form label {
    margin-bottom: 0;
    font-weight: normal;
}

/* Interaction Buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--text-color);
}

.btn-icon.active {
    color: #f59e0b;
    /* Star color */
}

.btn-icon.active .fa-eye {
    color: #3b82f6;
    /* Eye color */
}

/* Page/Space Footer */
.page-footer,
.space-footer {
    margin-top: 30px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.watchers-info {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.2s;
}

.watchers-info:hover {
    color: var(--primary-color);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background-color: #fff;
    margin: 10% auto;
    padding: 0;
    border-radius: 12px;
    width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-header .close {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.watcher-list {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.watcher-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
}

.watcher-list li:last-child {
    border-bottom: none;
}

.watcher-list li img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.watcher-list li span {
    font-weight: 500;
}

/* Space View Specifics */
.space-header {
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
}

.description {
    margin-bottom: 30px;
    font-size: 1.1rem;
    color: #4b5563;
}

.btn-outline-primary {
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    background: none;
    padding: 4px 8px;
    font-size: 0.8rem;
    border-radius: 4px;
    transition: all 0.2s;
}

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

.list-item {
    padding: 10px 0;
}

.list-item a {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mt-4 {
    margin-top: 1.5rem;
}

.row {
    display: flex;
    gap: 20px;
}

.col-md-6 {
    flex: 1;
}

.list-group {
    list-style: none;
    padding: 0;
}