/* Ray Peat Wiki 阅读器样式 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    display: flex;
    height: 100vh;
}

/* 左侧侧栏 */
.sidebar {
    width: 280px;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.annotation-count {
    font-size: 12px;
    color: #666;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 10px;
}

.annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.annotation-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.annotation-item.pending {
    background: #fff3cd;
    border-left: 3px solid #ffc107;
}

.annotation-item.processed {
    background: #d4edda;
    border-left: 3px solid #28a745;
}

.annotation-item:hover {
    background: #e8e8e8;
}

.annotation-text {
    font-size: 13px;
    color: #333;
    margin-bottom: 6px;
    /* 显示前 50 字 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.annotation-comment {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.annotation-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.tag {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e0e0e0;
}

.tag.concept { background: #e3f2fd; color: #1976d2; }
.tag.substance { background: #fce4ec; color: #c2185b; }
.tag.condition { background: #f3e5f5; color: #7b1fa2; }
.tag.quote { background: #fff8e1; color: #f57f17; }
.tag.live-topic { background: #e8f5e9; color: #388e3c; }
.tag.video-topic { background: #ffebee; color: #d32f2f; }

.annotation-time {
    font-size: 11px;
    color: #999;
}

.annotation-delete {
    font-size: 11px;
    color: #d32f2f;
    cursor: pointer;
    margin-top: 4px;
}

.annotation-delete:hover {
    text-decoration: underline;
}

.empty-hint {
    text-align: center;
    color: #999;
    padding: 20px;
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.file-selector {
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-selector label {
    font-size: 14px;
    color: #666;
}

.file-selector select {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    min-width: 300px;
}

.btn-secondary {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
}

.btn-secondary:hover {
    background: #f0f0f0;
}

.btn-primary {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    background: #1976d2;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
}

.btn-primary:hover {
    background: #1565c0;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #fff;
}

.loading-hint {
    text-align: center;
    color: #999;
    padding: 40px;
}

/* Markdown 渲染样式 */
.markdown-body {
    max-width: 800px;
    font-size: 16px;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
}

.markdown-body h1 { font-size: 28px; }
.markdown-body h2 { font-size: 24px; }
.markdown-body h3 { font-size: 20px; }

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
}

.markdown-body pre {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
}

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 16px;
}

.markdown-body th, .markdown-body td {
    border: 1px solid #ddd;
    padding: 8px;
}

.markdown-body th {
    background: #f5f5f5;
}

/* 高亮选中文字 */
.highlight {
    background: #fff3cd;
    border-radius: 2px;
    cursor: pointer;
}

.highlight:hover {
    background: #ffe066;
}

.highlight.processed {
    background: #d4edda;
}

.highlight.basket {
    background: #ffd699;
    border-bottom: 2px solid #ff9800;
}

/* 摘录篮悬浮按钮 */
.basket-floating {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
}

.basket-btn {
    background: #ff9800;
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
    transition: transform 0.2s;
}

.basket-btn:hover {
    transform: scale(1.05);
}

.basket-icon {
    font-size: 18px;
}

.basket-count {
    background: #fff;
    color: #ff9800;
    border-radius: 12px;
    padding: 2px 8px;
    font-weight: bold;
    font-size: 13px;
}

/* 弹窗动作行 */
.modal-actions-row {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* 大弹窗（摘录篮汇总） */
.modal-content-large {
    width: 700px;
    max-width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.basket-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 16px;
    max-height: 400px;
}

.basket-item {
    background: #fff8e1;
    border-left: 3px solid #ff9800;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 10px;
    position: relative;
}

.basket-item-number {
    display: inline-block;
    background: #ff9800;
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    text-align: center;
    line-height: 22px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 8px;
}

.basket-item-text {
    font-size: 14px;
    color: #333;
    line-height: 1.5;
    display: inline;
}

.basket-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: #d32f2f;
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
}

.basket-item-delete:hover {
    background: rgba(211, 47, 47, 0.1);
    border-radius: 4px;
}

#basket-comment {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    font-size: 14px;
    resize: none;
    margin-bottom: 16px;
}

/* 标注弹窗 */
.annotation-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.annotation-modal.show {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 500px;
    max-width: 90%;
    padding: 20px;
}

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

.modal-header h4 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.selected-text-preview {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #333;
    max-height: 150px;
    overflow-y: auto;
}

#user-comment {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    font-size: 14px;
    resize: none;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}
/* ==================== 移动端响应式 ==================== */
@media (max-width: 768px) {
    /* 整体布局：侧栏改抽屉 */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        left: 0;
    }

    /* 抽屉切换按钮 */
    .sidebar-toggle {
        display: flex !important;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 101;
        background: #fff;
        border: 1px solid #ddd;
        border-radius: 6px;
        width: 40px;
        height: 40px;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .sidebar-toggle::before {
        content: "☰";
        font-size: 20px;
    }

    /* 主内容区调整 */
    .main-content {
        width: 100%;
    }

    /* 文件选择器：紧凑 */
    .file-selector {
        padding: 12px;
        padding-left: 60px; /* 给抽屉按钮留位置 */
        flex-wrap: wrap;
        gap: 8px;
    }

    .file-selector label {
        display: none; /* 移动端隐藏 label，节省空间 */
    }

    .file-selector select {
        flex: 1;
        min-width: 0;
        font-size: 16px; /* iOS 防止自动放大 */
        padding: 8px 12px;
    }

    /* 内容区：增加内边距和字号 */
    .content-area {
        padding: 16px;
        -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
    }

    .markdown-body {
        font-size: 17px; /* 比桌面大一号 */
        line-height: 1.7;
    }

    .markdown-body h1 { font-size: 24px; }
    .markdown-body h2 { font-size: 20px; }
    .markdown-body h3 { font-size: 18px; }

    /* 弹窗：占满宽度 */
    .modal-content {
        width: calc(100% - 24px);
        margin: 12px;
        padding: 16px;
        max-height: calc(100vh - 24px);
        overflow-y: auto;
    }

    .modal-content-large {
        width: calc(100% - 24px);
        max-height: calc(100vh - 24px);
    }

    /* 弹窗按钮：加大点击区域 */
    .btn-primary, .btn-secondary {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px; /* iOS 推荐最小点击区域 */
    }

    .modal-actions, .modal-actions-row {
        flex-direction: column;
        gap: 8px;
    }

    .modal-actions button, .modal-actions-row button {
        width: 100%;
    }

    /* 文本输入框 */
    #user-comment, #basket-comment {
        font-size: 16px; /* iOS 防自动放大 */
        padding: 12px;
        min-height: 100px;
    }

    /* 选中预览框 */
    .selected-text-preview {
        font-size: 14px;
        max-height: 120px;
    }

    /* 摘录篮悬浮按钮：贴底部 */
    .basket-floating {
        bottom: 16px;
        right: 16px;
    }

    .basket-btn {
        padding: 14px 22px;
        font-size: 15px;
        box-shadow: 0 6px 16px rgba(255, 152, 0, 0.5);
    }

    /* 摘录篮列表项 */
    .basket-item {
        padding: 10px;
    }

    .basket-item-text {
        font-size: 15px;
    }

    /* 标注列表项 */
    .annotation-item {
        padding: 14px;
    }

    .annotation-text {
        white-space: normal;
        font-size: 14px;
    }

    /* 抽屉打开时的遮罩 */
    .sidebar-mask {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
    }

    .sidebar-mask.show {
        display: block;
    }
}

/* 桌面端默认隐藏抽屉切换按钮 */
.sidebar-toggle {
    display: none;
}

/* iOS Safari 选中文字时禁用默认菜单（改为我们自己的弹窗） */
.markdown-body {
    -webkit-touch-callout: none;
    -webkit-user-select: text;
    user-select: text;
}

/* ==================== 浮动标注按钮（选中文字后出现） ==================== */
.floating-annotate-btn {
    display: none;
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    background: #1976d2;
    color: #fff;
    padding: 10px 22px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(25, 118, 210, 0.5);
    user-select: none;
    -webkit-user-select: none;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.floating-annotate-btn.show {
    display: inline-flex;
}

.floating-annotate-btn:active {
    transform: translateX(-50%) scale(0.95);
}

.floating-annotate-btn .floating-icon {
    font-size: 16px;
}

/* 移动端按钮加大 */
@media (max-width: 768px) {
    .floating-annotate-btn {
        top: 70px;
        padding: 14px 28px;
        font-size: 16px;
        border-radius: 28px;
        box-shadow: 0 6px 20px rgba(25, 118, 210, 0.55);
    }

    .floating-annotate-btn .floating-icon {
        font-size: 18px;
    }
}

/* ==================== 段落整段加入按钮 ==================== */
.markdown-body p,
.markdown-body li,
.markdown-body blockquote {
    position: relative;
}

.paragraph-add-btn {
    position: absolute;
    top: 4px;
    right: -4px;
    width: 28px;
    height: 28px;
    border-radius: 14px;
    background: rgba(255, 152, 0, 0.92);
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    line-height: 28px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 30;
}

.paragraph-add-btn:hover {
    transform: scale(1.1);
}

.paragraph-add-btn:active {
    transform: scale(0.92);
}

/* 桌面端：hover 段落显示 */
@media (min-width: 769px) {
    .markdown-body p:hover .paragraph-add-btn,
    .markdown-body li:hover .paragraph-add-btn,
    .markdown-body blockquote:hover .paragraph-add-btn {
        opacity: 1;
    }
}

/* 移动端：始终半透明显示 */
@media (max-width: 768px) {
    .paragraph-add-btn {
        opacity: 0.55;
        width: 32px;
        height: 32px;
        border-radius: 16px;
        line-height: 32px;
        font-size: 20px;
        top: 2px;
        right: 0;
    }

    .paragraph-add-btn:active {
        opacity: 1;
    }
}
