:root {
    --color-primary: #3B82F6;
    --color-primary-hover: #2563EB;
    --color-primary-light: #EFF6FF;
    --color-secondary: #64748B;
    --color-secondary-hover: #475569;
    --color-accent: #F59E0B;
    --color-accent-hover: #D97706;
    --color-success: #10B981;
    --color-danger: #EF4444;
    --color-danger-hover: #DC2626;

    --color-bg: #F8FAFC;
    --color-bg-secondary: #F1F5F9;
    --color-card: #FFFFFF;
    --color-border: #E2E8F0;
    --color-border-light: #F1F5F9;

    --color-text: #1E293B;
    --color-text-secondary: #64748B;
    --color-text-muted: #94A3B8;
    --color-text-inverse: #FFFFFF;

    --font-sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Monaco, monospace;

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 14.7px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 10px 25px rgba(0, 0, 0, 0.2);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    --header-height: 40px;
    --tabs-height: 32px;
    --notes-width: 320px;
}

/* 深色模式变量覆盖 */
body.dark-mode {
    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-card: #1e293b;
    --color-border: #334155;
    --color-border-light: #1e293b;
    --color-text: #f8fafc;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #64748b;
}

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

html, body {
    height: 100%;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: #2c3e50; /* 默认背景色，防止图片加载慢时白屏 */
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

body.has-bg {
    /* 通过 JS 动态添加背景图 */
}

/* 加载动画 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s, visibility 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3B82F6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

#app {
    display: block;
    min-height: 100vh;
}

.header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    width: 100%;
    background-color: transparent;
    z-index: 1000; /* 提高层级 */
    position: sticky; /* 实现吸顶 */
    top: 0;
    transition: background-color 0.3s, backdrop-filter 0.3s, box-shadow 0.3s;
}

/* 滚动时的深色背景状态 */
body.is-scrolled .header {
    background-color: rgba(30, 41, 59, 0.95); /* 深蓝色背景 */
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 48px; /* 进一步压缩高度 */
    padding: 0 16px;
    margin-bottom: 0; /* 移除边距，使布局更紧凑 */
}

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

.btn-icon.pulse {
    animation: pulse 2s infinite;
    color: var(--color-primary);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* 拖拽状态样式 */
.dragging {
    opacity: 0.5;
    cursor: move;
}

.drag-over {
    background-color: rgba(59, 130, 246, 0.1) !important;
    outline: 2px dashed #3B82F6 !important;
    outline-offset: -2px;
}

/* 拖拽时的书签卡片预览 */
.bookmark-card.dragging {
    transform: scale(0.95);
    box-shadow: none;
}

/* 页面整体在拖拽时的反馈 */
body.is-dragging .group-content {
    min-height: 40px; /* 确保空分组也能拖入 */
    background-color: rgba(0, 0, 0, 0.02);
    border-radius: 4px;
}

body.is-scrolled .logo, 
body.is-scrolled .tab-item, 
body.is-scrolled .btn-icon, 
body.is-scrolled .toolbar-btn {
    text-shadow: none; /* 滚动到深色背景后不需要阴影 */
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1; /* 占据剩余空间 */
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 4px; /* 按钮间距更紧凑 */
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.search-box {
    position: relative;
    width: 500px; /* 稍微缩小宽度 */
    margin: 8px auto 12px; /* 进一步减少间距 */
    display: flex;
    align-items: center;
    background-color: #fff;
    border-radius: 28px;
    padding: 0 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    height: 42px; /* 缩小高度 */
    transition: transform 0.3s, opacity 0.3s, margin 0.3s, height 0.3s;
}

/* 滚动时隐藏大搜索框，或者缩小它 */
body.is-scrolled .search-box {
    transform: translateY(-20px);
    opacity: 0;
    pointer-events: none;
    margin: 0;
    height: 0;
}

.search-box input {
    flex: 1;
    height: 100%;
    padding: 0 12px;
    font-size: 16px;
    color: #333; /* 改为深色文字 */
    background: transparent;
    border: none;
    outline: none;
    text-align: left;
}

.search-engine-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    cursor: pointer;
    border-right: 1px solid #eee;
    height: 24px;
    position: relative;
}

.search-engine-selector .current-engine-icon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.search-engine-selector svg {
    color: #999;
    transition: transform 0.2s;
}

.search-engine-selector:hover svg {
    color: #666;
}

.search-engine-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    width: 200px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    padding: 8px 0;
    z-index: 1000;
}

.search-engine-dropdown.active {
    display: flex;
}

.engine-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    color: #333;
}

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

.engine-item img {
    width: 18px;
    height: 18px;
    border-radius: 3px;
}

.search-icon-right {
    display: flex;
    align-items: center;
    color: #999;
}

.search-box input::placeholder {
    color: #999;
}

.search-box-mini {
    position: relative;
    display: flex;
    align-items: center;
    margin-right: 8px;
}

.search-box-mini input {
    width: 120px;
    height: 28px;
    padding: 0 10px 0 28px;
    font-size: 13px;
    color: #fff;
    background-color: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    outline: none;
    transition: var(--transition-fast);
}

.search-box-mini input:focus {
    width: 180px;
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.search-box-mini svg {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.6);
    pointer-events: none;
}

.search-box-mini .search-results {
    margin-top: 4px;
    width: 240px;
    right: 0;
    left: auto;
}

.search-box input::placeholder {
    color: rgba(255, 255, 255, 0.8);
}

.toolbar {
    display: none;
}

.toolbar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 1400px;
    padding: 0 16px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.toolbar-btn.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    color: rgba(255, 255, 255, 0.8);
    background-color: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-icon:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.2);
}

.btn-icon:active {
    transform: scale(0.95);
}

.user-btn {
    margin-left: var(--spacing-sm);
}

.page-tabs {
    display: flex;
    align-items: center;
    gap: 4px; /* 减少间距 */
    overflow: hidden;
}

.tabs-list {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    overflow-x: auto;
}

.tabs-list::-webkit-scrollbar {
    display: none;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.tab-item:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.15);
}

.tab-item.active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.25);
    box-shadow: none;
    font-weight: 500;
}

.tab-item .tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    color: var(--color-text-muted);
    background-color: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: var(--transition-fast);
}

.tab-item:hover .tab-close {
    opacity: 1;
}

.tab-item .tab-close:hover {
    color: var(--color-danger);
    background-color: var(--color-bg-secondary);
}

.add-page-btn {
    margin-left: var(--spacing-sm);
}

.main-content {
    display: block;
    padding: 24px 14.7px 64px;
}

.groups-container {
    display: flex;
    gap: 14.7px;
    align-content: flex-start;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* 4列布局支持 */
.groups-column {
    flex: 1 1 0;
    min-width: 0;
}

.notes-panel {
    display: none;
}

.notes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}

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

.notes-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-secondary);
}

@media (max-width: 1024px) {
    .notes-panel {
        display: none;
    }

    .search-box {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .groups-container {
        grid-template-columns: 1fr;
    }

    .search-box {
        width: 200px;
    }
}
