/* -------------------------
 * 1. 基本设置 & 移动端优先
 * ------------------------- */
html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f0f2f5;
    overflow: hidden;
}

body {
    display: flex;
    position: relative;
}

/* --- 侧边栏 & 遮罩 --- */
.mobile-sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100vh;
    background-color: #ffffff;
    border-right: 1px solid #dcdcdc;
    z-index: 1000;
    transition: left 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.mobile-sidebar.open {
    left: 0;
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
}

.overlay.open {
    display: block;
}

.main-content-wrapper {
    flex-grow: 1;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* -------------------------
 * 2. 顶部栏
 * ------------------------- */
.top-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 8px 10px;
    background-color: #ffffff;
    border-bottom: 1px solid #dcdcdc;
    min-height: 40px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.menu-button {
    display: block;
    font-size: 24px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 10px;
    color: #333;
}

.sections-container {
    display: flex;
    flex-grow: 1;
    align-items: center;
    min-width: 0;
    overflow: hidden;
}

.sections-list {
    display: flex;
    flex-grow: 1;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    align-items: center;
    min-height: 40px;
    min-width: 0;
    padding-right: 10px;
}

.sections-list::-webkit-scrollbar {
    height: 4px;
    background: transparent;
}

.sections-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.section-item {
    position: relative;
    display: flex;
    align-items: center;
    padding: 8px 28px 8px 12px;
    margin-right: 8px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    font-weight: 500;
    font-size: 14px;
    user-select: none;
}

.section-item.active {
    border-color: #007aff;
}

.sync-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
    margin-left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.sync-btn.spinning {
    animation: spin 1s linear infinite;
}

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

.page-count-badge {
    background-color: rgba(0, 0, 0, 0.1);
    color: #555;
    font-size: 0.85em;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 600;
}

/* -------------------------
 * 3. 侧边栏内容
 * ------------------------- */
.collection-controls,
.page-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 12px;
    border-bottom: 1px solid #eee;
}

.page-controls {
    justify-content: space-between;
}

#collectionSelector {
    flex-grow: 1;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.pages-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}

.page-item {
    position: relative;
    display: flex;
    align-items: center;
    padding: 10px 30px 10px 12px;
    margin-bottom: 4px;
    border-radius: 4px;
    cursor: pointer;
    overflow: hidden;
    user-select: none;
}

.page-item:hover {
    background-color: #f5f5f5;
}

.page-item.active {
    background-color: #e3f2fd;
    font-weight: 600;
}

.btn-add-list,
.btn-delete-list {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.btn-add-list {
    color: green;
    border-color: green;
}

.btn-delete-list {
    color: red;
    border-color: red;
}

.btn-toggle-public {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
    padding: 0;
}

.btn-toggle-public:hover {
    background-color: #f0f0f0;
}

.btn-delete-item {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 0, 0, 0.1);
    color: red;
    cursor: pointer;
    display: none;
}

.page-item:hover .btn-delete-item,
.section-item:hover .btn-delete-item {
    display: block;
}

.item-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* -------------------------
 * 4. 编辑器 & Lightbox & Table
 * ------------------------- */
.main-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}

#editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20px 30px;
    outline: none;
    font-size: 16px;
    line-height: 1.6;
    overflow: auto;
    background: #fff;
    box-sizing: border-box;
    white-space: normal;
}

#editor img {
    display: block;
    height: 30vh;
    width: auto;
    max-width: 100%;
    margin: 10px 0;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: zoom-in;
    object-fit: contain;
}

#editor img.loading {
    opacity: 0.5;
    filter: grayscale(100%);
}

.just-table {
    border-collapse: collapse;
    min-width: 100%;
    width: auto;
    margin: 1em 0;
    border: 1px solid #ccc;
    table-layout: auto;
}

.just-table td,
.just-table th {
    border: 1px solid #ccc;
    padding: 8px;
    min-width: 120px;
    vertical-align: top;
    white-space: pre-wrap;
}

.just-table th {
    background-color: #f8f9fa;
    font-weight: 600;
}

/* ✨✨✨ 表格行 Header 样式 (Ctrl+Y Ctrl+B) ✨✨✨ */
/* 当 TR 拥有 .row-header 类时，其内部的所有 TD 都变成粗体+深色背景 */
.just-table tr.row-header td,
.just-table tr.row-header th {
    background-color: #e2e6ea;
    /* 比默认表头稍深 */
    font-weight: 700;
    color: #222;
}

/* 普通文本块 Header 样式 */
.custom-header {
    font-weight: 700;
    font-size: 1.1em;
    background-color: #e9ecef;
    padding: 6px 10px;
    border-radius: 4px;
    border-left: 4px solid #007aff;
    display: block;
    margin: 10px 0;
    line-height: 1.4;
}

.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

.lightbox.open {
    display: flex;
}

.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    border-radius: 2px;
    object-fit: contain;
}

/* -------------------------
 * 5. 设置 & 模态框
 * ------------------------- */
.settings-trigger-wrapper {
    padding: 15px;
    border-top: 1px solid #eee;
    margin-top: auto;
}

.btn-settings {
    width: 100%;
    padding: 10px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
}

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-content {
    background: #fff;
    width: 90%;
    max-width: 400px;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.close-modal {
    font-size: 24px;
    cursor: pointer;
    color: #aaa;
}

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

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #333;
}

.input-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

.input-group small {
    font-size: 11px;
    color: #666;
}

.btn-primary {
    background: #007aff;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
}

.btn-sync {
    background: #34c759;
    color: #fff;
    border: none;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-weight: bold;
    margin-top: 10px;
}

.btn-danger {
    width: 100%;
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 20px;
    font-weight: bold;
    border: 1px solid #bd2130;
}

.btn-danger:hover {
    background-color: #c82333;
}

#syncStatus {
    text-align: center;
    font-size: 12px;
    color: #555;
    margin-top: 15px;
    margin-bottom: 5px;
}

@media (min-width: 769px) {

    .menu-button,
    .overlay {
        display: none !important;
    }

    .mobile-sidebar {
        position: relative;
        left: 0 !important;
        width: 250px;
        flex-shrink: 0;
        transition: none;
    }

    .top-bar {
        padding: 8px 15px;
    }

    .sections-container {
        border-left: 1px solid #eee;
        padding-left: 15px;
    }
}