:root {
    --sidebar-width: 260px;
    --bg-outer: #f0f2f5;
    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --border: #e2e8f0;
    --th-bg: #f1f5f9;
    --summary-bg: #f0fdf4;
    --summary-text: #166534;
    --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
    --bg-outer: #0a0e17;
    --bg-primary: #121826;
    --bg-card: #1a2233;
    --text-main: #d1d5db;
    --text-muted: #9ca3af;
    --border: #2e374a;
    --th-bg: #1e293b;
    --summary-bg: #064e3b;
    --summary-text: #4ade80;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-outer);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background 0.3s;
    overflow: hidden;
}

#loginOverlay {
    position: fixed;
    inset: 0;
    background: var(--bg-outer);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}
.login-box {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--border);
}
.login-box h2 { margin-bottom: 24px; color: var(--text-main); }
.login-input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-main);
    font-size: 16px;
    margin-bottom: 20px;
    outline: none;
    text-align: center;
    letter-spacing: 4px;
}
.login-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1); }

.app-wrapper {
    width: 100%;
    max-width: 1280px;
    height: 100%;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    display: flex;
    overflow: hidden;
    border: 1px solid var(--border);
    position: relative;
    visibility: hidden;
}

.sidebar-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

aside {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.logo { font-size: 1.25rem; font-weight: 800; color: var(--accent); display: flex; align-items: center; gap: 12px; }

.file-list { flex: 1; overflow-y: auto; padding: 10px; }
.file-item {
    padding: 10px 16px; border-radius: 10px; cursor: pointer; margin-bottom: 4px;
    display: flex; align-items: center; gap: 12px; transition: all 0.2s;
    color: var(--text-muted); border: 1px solid transparent;
    font-size: 0.9rem;
}
.file-item:hover { background: var(--bg-card); color: var(--accent); border-color: var(--border); }
.file-item.active { background: var(--bg-card); color: var(--accent); border-color: var(--accent); font-weight: 600; }

.sidebar-footer { padding: 15px; border-top: 1px solid var(--border); }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-card); }
header {
    height: 60px; padding: 0 24px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.menu-toggle { display: none; }

#currentFileName { font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

/* 核心：粘性工具组布局 */
.sticky-tools { 
    display: flex; 
    flex-direction: column;
    background: var(--bg-card); 
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; 
}
.tools-main-row { display: flex; align-items: stretch; height: 50px; }

/* 统计区域：新的一体化设计 */
.stats-container { 
    display: flex; 
    background: var(--bg-primary); 
    padding: 8px 12px;
    align-items: center;
    min-width: 240px;
    border-right: 1px solid var(--border);
}
.stat-card {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
}
.stat-label { font-size: 1rem; opacity: 0.8; }
.stat-value { 
    font-size: 1.05rem; 
    font-weight: 700; 
    color: var(--text-main);
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-variant-numeric: tabular-nums;
}

/* 工具栏区域 */
.toolbar {
    padding: 0 15px; background: var(--bg-card); display: flex; gap: 10px;
    align-items: center; flex: 1;
}
.pc-tools { display: flex; align-items: center; gap: 10px; flex: 1; }
.mobile-action-btns { display: none; }

.filter-select { 
    padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); 
    background: var(--bg-primary); color: var(--text-main); min-width: 110px; outline: none; font-size: 13px;
}

.search-wrapper { position: relative; flex: 1; }
.search-input {
    width: 100%; padding: 7px 12px 7px 36px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--bg-primary); color: var(--text-main); outline: none;
    font-size: 13px;
}
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.8rem; }

/* 展开行样式 */
.expand-row {
    display: none;
    padding: 10px 15px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    animation: slideDown 0.2s ease-out;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.pill-container {
    display: flex; gap: 8px; overflow-x: auto; white-space: nowrap; padding: 2px 0; -webkit-overflow-scrolling: touch;
}
.pill-container::-webkit-scrollbar { display: none; }
.pill-item {
    padding: 6px 14px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 18px; font-size: 13px; color: var(--text-muted); cursor: pointer; flex-shrink: 0;
}
.pill-item.active {
    background: var(--accent); color: white; border-color: var(--accent); font-weight: 600;
}

.table-area { flex: 1; display: flex; flex-direction: column; padding: 0 24px 20px 24px; background: var(--bg-primary); min-height: 0; }
.table-wrapper { 
    flex: 1; background: var(--bg-card); border-radius: 12px; 
    border: 1px solid var(--border); overflow: auto; 
    position: relative;
}

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.85rem; }
th {
    background: var(--th-bg); padding: 12px 10px; text-align: center;
    font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
td { 
    padding: 10px 8px; border-bottom: 1px solid var(--border); 
    color: var(--text-main); text-align: center; background: var(--bg-card); white-space: nowrap;
}
tr:nth-child(even) td { background: var(--bg-primary); }
tr:hover td { background: rgba(99, 102, 241, 0.08) !important; }
.summary-row td { background: var(--summary-bg) !important; color: var(--summary-text) !important; font-weight: 700; }
.num-font { font-family: 'JetBrains Mono', 'Consolas', monospace; font-variant-numeric: tabular-nums; }

.btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; transition: all 0.2s; font-size: 13px; }
.btn-primary { background: var(--accent); color: white; }
.btn-icon { width: 34px; height: 34px; justify-content: center; background: var(--bg-primary); color: var(--text-muted); padding: 0; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); padding: 20px; text-align: center; }

/* 加载遮罩样式 */
.loading-overlay {
    position: absolute; inset: 0; background: rgba(255,255,255,0.7);
    z-index: 2000; display: none; flex-direction: column;
    justify-content: center; align-items: center; backdrop-filter: blur(4px);
}
[data-theme="dark"] .loading-overlay { background: rgba(10,14,23,0.7); }

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

@media (max-width: 768px) {
    body { padding: 0; height: 100dvh; overflow: hidden; }
    .app-wrapper { border-radius: 0; border: none; height: 100dvh; visibility: visible; }
    aside { position: absolute; left: 0; top: 0; bottom: 0; transform: translateX(-100%); height: 100dvh; z-index: 1000; }
    .sidebar-open aside { transform: translateX(0); }
    .sidebar-open .sidebar-overlay { display: block; position: fixed; z-index: 900; }
    .menu-toggle { display: flex; }
    
    header { height: auto; padding: 8px 15px; }
    .header-left div { display: flex; flex-direction: column !important; gap: 0 !important; }
    #currentFileName { font-size: 0.7rem; color: var(--text-muted); order: 2; }
    #fileDescription { font-size: 0.95rem !important; color: var(--text-main) !important; font-weight: 600 !important; order: 1; }

    .tools-main-row { height: 44px; }
    .stats-container { padding: 0 10px; min-width: 120px; flex: 1; }
    .stat-card { gap: 4px; }
    .stat-label { font-size: 0.9rem; }
    .stat-value { font-size: 0.9rem; }
    
    .toolbar { padding: 0 8px; flex: 1.5; }
    .pc-tools { display: none; }
    .mobile-action-btns { display: flex; gap: 4px; width: 100%; }
    .action-btn { 
        flex: 1; padding: 6px 2px; border-radius: 6px; border: 1px solid var(--border);
        background: var(--bg-primary); color: var(--text-main); font-size: 11px; font-weight: 600;
    }
    .action-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

    .table-area { padding: 0 8px 15px 8px; }
    table { font-size: 0.9rem; }
    th, td { padding: 10px 4px; }
}
