/* ========== CSS VARIABLES ========== */
:root {
    --primary: #2eaadc;
    --primary-dark: #2596c4;
    --bg: #ffffff;
    --bg-secondary: #f7f7f7;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border: #e8e8e8;
    --border-light: #f0f0f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --header-h: 56px;
    --nav-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

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

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

body {
    padding-top: calc(var(--header-h) + var(--safe-top));
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

/* ========== HEADER ========== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    gap: 12px;
    z-index: 100;
}

.header-menu-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

.header-menu-btn:active {
    background: var(--bg-secondary);
}

.header-title {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-action {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
}

.header-action:active {
    background: var(--bg-secondary);
}

/* ========== BOTTOM NAVIGATION ========== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s;
    min-width: 56px;
}

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

.nav-item .nav-icon {
    font-size: 22px;
    line-height: 1;
}

.nav-item .nav-label {
    font-size: 10px;
    font-weight: 500;
}

.nav-item .nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    background: #e74c3c;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ========== CONTENT AREA ========== */
.content {
    min-height: calc(100vh - var(--header-h) - var(--nav-h) - var(--safe-top) - var(--safe-bottom));
    padding: 16px;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
}

/* ========== SIDEBAR OFFCANVAS ========== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

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

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: var(--bg);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding-top: calc(var(--safe-top) + 16px);
    padding-bottom: calc(var(--safe-bottom) + 16px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

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

.sidebar-header {
    padding: 8px 20px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}

.sidebar-brand {
    font-size: 17px;
    font-weight: 600;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    font-size: 15px;
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.sidebar-item:active {
    background: var(--bg-secondary);
}

.sidebar-item .si-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.sidebar-item .si-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-item.indent {
    padding-left: 44px;
    font-size: 14px;
    color: var(--text-secondary);
}

.sidebar-section {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 16px 20px 4px;
}

/* ========== PAGE LIST ========== */
.page-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.page-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.page-list-item:active {
    background: var(--bg-secondary);
}

.page-list-item .pli-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.page-list-item .pli-info {
    flex: 1;
    overflow: hidden;
}

.page-list-item .pli-title {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-list-item .pli-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.page-list-item .pli-star {
    font-size: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.page-list-item .pli-star.active {
    color: #f1c40f;
}

/* ========== GALLERY GRID ========== */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.gallery-card {
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s;
}

.gallery-card:active {
    transform: scale(0.97);
}

.gallery-card-cover {
    width: 100%;
    aspect-ratio: 1.2;
    background: var(--bg-secondary);
    object-fit: cover;
}

.gallery-card-body {
    padding: 10px;
}

.gallery-card-title {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-card-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========== BLOCK RENDERING ========== */
.block {
    margin-bottom: 8px;
    line-height: 1.6;
}

.block-heading1 {
    font-size: 24px;
    font-weight: 700;
    margin: 20px 0 8px;
}

.block-heading2 {
    font-size: 20px;
    font-weight: 600;
    margin: 16px 0 6px;
}

.block-heading3 {
    font-size: 17px;
    font-weight: 600;
    margin: 12px 0 4px;
}

.block-text {
    font-size: 15px;
}

.block-bullet {
    padding-left: 20px;
    position: relative;
}

.block-bullet::before {
    content: '\2022';
    position: absolute;
    left: 6px;
    color: var(--text-secondary);
}

.block-numbered {
    padding-left: 24px;
}

.block-todo {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.block-todo input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.block-quote {
    border-left: 3px solid var(--primary);
    padding: 8px 12px;
    margin: 8px 0;
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    font-style: italic;
}

.block-callout {
    display: flex;
    gap: 10px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

.block-callout-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.block-code {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 13px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    word-break: break-all;
}

.block-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.block-image {
    width: 100%;
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

.block-unsupported {
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    border: 1px dashed var(--border);
}

/* ========== SEARCH ========== */
.search-container {
    padding: 0 0 12px;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    background: var(--bg-secondary);
    outline: none;
    -webkit-appearance: none;
}

.search-input:focus {
    border-color: var(--primary);
    background: var(--bg);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--text-muted);
}

/* ========== MODALS ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-sheet {
    width: 100%;
    max-height: 90vh;
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    padding: 8px 20px calc(20px + var(--safe-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.modal-overlay.visible .modal-sheet {
    transform: translateY(0);
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

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

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
    -webkit-appearance: none;
}

.form-input:focus {
    border-color: var(--primary);
}

.form-textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
    resize: vertical;
    font-family: inherit;
    -webkit-appearance: none;
}

.form-textarea:focus {
    border-color: var(--primary);
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.2s;
    min-height: 44px;
}

.btn:active {
    opacity: 0.7;
}

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

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

.btn-block {
    width: 100%;
}

.btn-danger {
    background: #e74c3c;
    color: #fff;
}

/* ========== QUICK ACTIONS ========== */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.quick-action:active {
    background: var(--border);
}

.quick-action .qa-icon {
    font-size: 24px;
}

.quick-action .qa-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ========== SYNC STATUS ========== */
.sync-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
    flex-shrink: 0;
}

.sync-dot.offline {
    background: #e74c3c;
}

.sync-dot.syncing {
    background: #f39c12;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 400;
    transition: transform 0.3s ease;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state .es-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state .es-text {
    font-size: 15px;
}

/* ========== SECTION TITLE ========== */
.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ========== FOLDER ITEM ========== */
.folder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.folder-item:active {
    background: var(--bg-secondary);
}

.folder-item .fi-icon {
    font-size: 20px;
}

.folder-item .fi-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}

.folder-item .fi-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: 10px;
}

.folder-item .fi-arrow {
    color: var(--text-muted);
    font-size: 16px;
}

/* ========== PAGE DETAIL HEADER ========== */
.page-detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.page-detail-icon {
    font-size: 28px;
}

.page-detail-title {
    font-size: 22px;
    font-weight: 700;
    flex: 1;
}

.page-detail-star {
    font-size: 24px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* ========== GALLERY ITEM DETAIL ========== */
.gallery-detail-cover {
    width: 100%;
    max-height: 250px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.gallery-detail-props {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.gallery-prop {
    display: flex;
    gap: 8px;
    font-size: 14px;
}

.gallery-prop-label {
    color: var(--text-muted);
    min-width: 80px;
    font-weight: 500;
}

.gallery-prop-value {
    flex: 1;
    color: var(--text);
}
