/* 学习笔记侧边栏 - Markdown */
#study-notes-fab {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: 10002;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #4db8a4, #62c9b8);
    color: #fff;
    -webkit-appearance: none;
    appearance: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(77, 184, 164, 0.45);
    transition: transform 0.2s, box-shadow 0.2s;
}
#study-notes-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(77, 184, 164, 0.55);
}
#study-notes-fab.hidden { display: none; }

/* 遮罩：全屏透明层，点击左侧正文区域关闭 */
#study-notes-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10049;
    background: rgba(15, 23, 42, 0.28);
    cursor: pointer;
    pointer-events: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
#study-notes-backdrop.visible {
    display: block;
    pointer-events: auto;
}

#study-notes-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 10050;
    width: 400px;
    max-width: 92vw;
    height: 100vh;
    height: 100dvh;
    background: #fff;
    border-left: 1px solid #e5e7eb;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.28s ease;
    pointer-events: auto;
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
#study-notes-panel.open { transform: translateX(0); }

/* 避开全站顶栏，确保关闭按钮可见 */
body.site-has-nav #study-notes-panel {
    top: calc(var(--site-nav-h, 44px) + env(safe-area-inset-top, 0px));
    height: calc(100vh - var(--site-nav-h, 44px) - env(safe-area-inset-top, 0px));
    height: calc(100dvh - var(--site-nav-h, 44px) - env(safe-area-inset-top, 0px));
}

.notes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #4db8a4, #62c9b8);
    color: #fff;
    flex-shrink: 0;
}
.notes-header-title {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
}
.notes-header-close {
    flex-shrink: 0;
    display: -webkit-flex;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.45);
    color: #fff;
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.notes-header-close:hover,
.notes-header-close:active {
    background: rgba(255, 255, 255, 0.4);
}

.notes-toolbar {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
    flex-wrap: wrap;
    align-items: center;
}
.notes-tab {
    padding: 8px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    min-height: 36px;
}
.notes-tab:hover { border-color: #4db8a4; color: #2a7d6e; }
.notes-tab.active {
    background: #4db8a4;
    border-color: #4db8a4;
    color: #fff;
}
.notes-tab-dl { margin-left: auto; }
.notes-tab-close {
    margin-left: auto;
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}
.notes-tab-close:hover {
    background: #fee2e2;
    border-color: #f87171;
    color: #b91c1c;
}

.notes-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#notes-content {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
    color: #1f2937;
    background: #fafbfc;
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    -webkit-appearance: none;
}
#notes-content.hidden { display: none; }
#notes-content::placeholder { color: #9ca3af; font-family: inherit; }

.notes-preview {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 18px;
    font-size: 14px;
    line-height: 1.75;
    color: #1f2937;
    background: #fff;
}
.notes-preview.hidden { display: none; }
.notes-preview-empty { color: #9ca3af; font-style: italic; }
.notes-preview-raw {
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 13px;
    background: #f9fafb;
    padding: 12px;
    border-radius: 8px;
}

/* Markdown 预览样式 */
.notes-preview h1 { font-size: 1.4em; margin: 0.6em 0 0.4em; color: #1f2937; border-bottom: 2px solid #4db8a4; padding-bottom: 4px; }
.notes-preview h2 { font-size: 1.2em; margin: 0.8em 0 0.4em; color: #2a7d6e; }
.notes-preview h3 { font-size: 1.05em; margin: 0.6em 0 0.3em; color: #374151; }
.notes-preview p { margin: 0.5em 0; }
.notes-preview ul, .notes-preview ol { margin: 0.4em 0; padding-left: 1.5em; }
.notes-preview li { margin: 0.2em 0; }
.notes-preview code {
    background: #edf9f5;
    color: #2a7d6e;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'JetBrains Mono', Consolas, monospace;
}
.notes-preview pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.6em 0;
    font-size: 12px;
    line-height: 1.5;
}
.notes-preview pre code { background: none; color: inherit; padding: 0; }
.notes-preview blockquote {
    border-left: 3px solid #4db8a4;
    margin: 0.6em 0;
    padding: 4px 12px;
    color: #4b5563;
    background: #f0faf7;
    border-radius: 0 6px 6px 0;
}
.notes-preview table { border-collapse: collapse; width: 100%; margin: 0.6em 0; font-size: 13px; }
.notes-preview th, .notes-preview td { border: 1px solid #e5e7eb; padding: 6px 10px; }
.notes-preview th { background: #f3f4f6; }
.notes-preview a { color: #3a9e8c; }
.notes-preview hr { border: none; border-top: 1px solid #e5e7eb; margin: 1em 0; }

.notes-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}
#notes-status { font-size: 12px; color: #9ca3af; flex: 1; min-width: 0; }
#notes-status.saved { color: #4db8a4; }
#notes-status.error { color: #ef4444; }
#notes-save-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    background: #4db8a4;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    min-height: 36px;
    touch-action: manipulation;
}
#notes-save-btn:hover { background: #3a9e8c; }
#notes-save-btn:disabled { background: #d1d5db; cursor: not-allowed; }

body.notes-panel-open {
    overflow: hidden;
}

@media (max-width: 1024px) {
    body.notes-panel-open {
        overflow: hidden;
    }

    #study-notes-panel {
        width: min(400px, 92vw);
        max-width: 92vw;
    }
}

@media (max-width: 768px) {
    #study-notes-backdrop.visible {
        background: rgba(15, 23, 42, 0.4);
    }

    #study-notes-panel {
        width: 100vw;
        max-width: 100vw;
    }

    #study-notes-fab {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}
