:root {
    --bg: #ffffff; --text: #1a1a1a; --sidebar-bg: #f8f8f8; --border: #eeeeee;
    --item-hover: #efefef; --item-active: #ffffff; --highlight: #ffff00; --status-text: #cccccc;
}
[data-theme="dark"] {
    --bg: #121212; --text: #e0e0e0; --sidebar-bg: #181818; --border: #2a2a2a;
    --item-hover: #222222; --item-active: #282828; --highlight: #7c7c00; --status-text: #555555;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; height: 100vh; background: var(--bg); color: var(--text); overflow: hidden; }

/* 登录遮罩 */
#auth-overlay { position: fixed; inset: 0; background: #ffffff; z-index: 9999; display: flex; align-items: center; justify-content: center; flex-direction: column; transition: 0.5s ease; }
#auth-overlay.hidden { opacity: 0; pointer-events: none; }
#auth-input { background: none; border: none; border-bottom: 2px solid #eee; color: #1a1a1a; font-size: 32px; text-align: center; outline: none; padding: 10px; letter-spacing: 12px; width: 260px; margin-bottom: 20px; }
.auth-hint { font-size: 10px; color: #bbb; letter-spacing: 3px; font-weight: bold; }

.app-wrapper { display: flex; height: 100%; width: 100vw; position: relative; }

/* 侧边栏及拉环 */
.sidebar { 
    width: 240px; min-width: 240px; background: var(--sidebar-bg); border-right: 1px solid var(--border); 
    position: relative; transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; flex-direction: column; z-index: 100;
}
.sidebar.collapsed { margin-left: -240px; }

#toggle-sidebar {
    position: absolute; right: -12px; top: 50%; transform: translateY(-50%);
    width: 24px; height: 24px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 50%; z-index: 110; cursor: pointer; color: var(--text);
    display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1); transition: 0.2s;
}
.sidebar.collapsed #toggle-sidebar { transform: translateY(-50%) rotate(180deg); right: -32px; }

.sidebar-header { padding: 25px 20px 15px; display: flex; justify-content: space-between; align-items: center; }
.logo { font-weight: 800; font-size: 18px; letter-spacing: 1px; }
#add-note-btn { background: var(--text); color: var(--bg); border: none; width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 22px; display: flex; align-items: center; justify-content: center; }

.search-wrap { padding: 0 15px 15px; }
#search-input { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px; outline: none; }

.note-list { flex: 1; overflow-y: auto; padding: 0 10px; }
.note-item { padding: 16px; border-radius: 12px; cursor: pointer; margin-bottom: 8px; border: 1px solid transparent; position: relative; }
.note-item.active { background: var(--item-active); border-left: 4px solid var(--text); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.nt { font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-time { font-size: 10px; color: var(--status-text); }
.pin-btn { position: absolute; right: 12px; top: 20px; font-size: 12px; color: var(--status-text); opacity: 0; }
.note-item:hover .pin-btn, .note-item.pinned .pin-btn { opacity: 1; }
.note-item.pinned .pin-btn { color: var(--text); font-weight: bold; }

/* 顶栏美化 */
header { height: 70px; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 30px; justify-content: space-between; }
.header-left { display: flex; align-items: center; gap: 18px; flex: 1; overflow: hidden; }
.header-right { display: flex; align-items: center; gap: 20px; }
.group { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 5px; flex-shrink: 0; }
header button { background: none; border: none; padding: 8px 10px; cursor: pointer; color: var(--text); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.btn-highlight { background: var(--highlight) !important; color: #000 !important; font-weight: bold; }

/* 颜色弹窗 */
.color-popup { position: absolute; top: 48px; left: 0; background: var(--bg); border: 1px solid var(--border); padding: 12px; border-radius: 12px; display: none; gap: 10px; box-shadow: 0 8px 25px rgba(0,0,0,0.12); z-index: 200; }
.color-dot { width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 1px solid rgba(0,0,0,0.1); }

#save-status { font-size: 11px; color: var(--status-text); font-style: italic; white-space: nowrap; }
.btn-reset { color: var(--status-text) !important; padding: 8px !important; }

/* 编辑器区域 */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
main { flex: 1; padding: 40px 20px; overflow-y: auto; display: flex; justify-content: center; }
#editor { width: 100%; max-width: 800px; outline: none; font-size: 18px; line-height: 1.6; color: var(--text); min-height: 100%; }

.sidebar-footer { padding: 20px; border-top: 1px solid var(--border); }
.footer-btn { width: 100%; padding: 10px; background: none; border: 1px solid var(--border); border-radius: 8px; color: var(--text); cursor: pointer; font-size: 11px; margin-bottom: 10px; }
.del-btn { width: 100%; padding: 8px; color: var(--status-text); border: none; background: none; cursor: pointer; font-size: 11px; }

/* ================= 手机端适配优化 ================= */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100%;
        left: 0;
        top: 0;
        z-index: 1000;
        box-shadow: 10px 0 30px rgba(0,0,0,0.2);
    }
    
    /* 将拉环移至底部，防止挡住正文视野 */
    #toggle-sidebar {
        top: auto;
        bottom: 30px; /* 距离底部 30px */
        transform: none;
        right: -25px;
        width: 32px;
        height: 32px;
        border-radius: 0 8px 8px 0;
        opacity: 0.9;
        font-size: 18px;
    }
    .sidebar.collapsed #toggle-sidebar {
        transform: rotate(180deg);
        right: -32px;
    }

    header {
        padding: 0 15px;
        flex-direction: column;
        height: auto;
        align-items: flex-start;
        padding-top: 10px;
    }
    .header-left {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 10px;
    }
    .header-right {
        width: 100%;
        justify-content: space-between;
        padding: 8px 0;
        border-top: 1px solid var(--border);
    }
    main { padding: 20px 15px; }
    #editor { font-size: 17px; }
}
