/* =========================================
   全局变量与重置
   ========================================= */
:root {
    --bg-color: #090a0f;
    --panel-bg-color: rgba(26, 26, 26, 0.6);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --accent-color: #00aaff;
    --danger-color: #f92672;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --border-radius: 16px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --body-padding: 1rem;
    
    /* 动态渐变色变量 (默认值，会被 PHP 覆盖) */
    --grad-start: #66d9ff;
    --grad-end: #66ffc2;
}

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

html, body {
    font-family: var(--font-family);
    color: var(--text-primary);
}

/* 滚动条样式 */
body::-webkit-scrollbar { width: 12px; background-color: var(--bg-color); }
body::-webkit-scrollbar-thumb { background-color: #4a4a4a; border-radius: 6px; border: 3px solid var(--bg-color); }
body::-webkit-scrollbar-thumb:hover { background-color: #5a5a5a; }

/* =========================================
   1. Shell (主界面) 样式
   ========================================= */
body.page-shell {
    min-height: 100vh; /* Changed: 确保最小高度充满视口 */
    overflow-x: hidden;
    padding: var(--body-padding);
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 50% 0%, rgba(120, 120, 180, 0.08) 0%, transparent 50%);
    display: flex;
    flex-direction: column;
}

.portal-wrapper { 
    width: 100%; 
    flex: 1; /* Changed: 自动填充剩余高度 */
    display: flex; 
    flex-direction: column; 
    gap: 1rem; 
    z-index: 1; 
}
.portal-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 1rem; border-bottom: 1px solid var(--border-color); flex-shrink: 0; animation: fadeIn 0.5s ease-out forwards; }

.portal-header h1 { 
    font-size: 1.6rem; font-weight: 700; letter-spacing: -1px;
    /* 使用 CSS 变量来接收 PHP 的随机颜色 */
    background: linear-gradient(90deg, var(--grad-start), var(--grad-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-fill-color: transparent;
    display: inline-block;
}
.portal-header h1 a { color: inherit; text-decoration: none; }

.dashboard-layout { 
    display: flex; 
    gap: 1rem; 
    flex: 1; /* Changed: 自动填充剩余高度 */
    align-items: stretch; /* Ensure panels stretch to same height */
}
.sidebar-panel { flex: 0 0 300px; background-color: var(--panel-bg-color); border: 1px solid var(--border-color); border-radius: var(--border-radius); box-shadow: var(--shadow); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); padding: 1rem; animation: fadeInUp 0.6s ease-out forwards; opacity: 0; position: sticky; top: var(--body-padding); }
.content-panel { 
    flex-grow: 1; 
    background-color: var(--panel-bg-color); 
    border: 1px solid var(--border-color); 
    border-radius: var(--border-radius); 
    box-shadow: var(--shadow); 
    overflow: hidden; 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px); 
    position: relative; 
    animation: fadeInUp 0.7s ease-out forwards; 
    opacity: 0; 
    display: flex; /* Changed: Flex 布局 */
    flex-direction: column;
}
.content-panel::after, .sidebar-panel::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent); }
iframe { width: 100%; flex: 1; border: none; display: block; } /* Changed: flex: 1 */

/* 目录树样式 */
.node-tree { list-style-type: none; padding-left: 0; }
.node-tree ul { list-style-type: none; padding-left: 0; }
.node-tree li > ul { padding-left: 20px; margin-left: 1rem; border-left: 1px solid var(--border-color); display: none; }
.node-tree a.node-link { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; color: var(--text-secondary); text-decoration: none; border-radius: 12px; border: 1px solid transparent; transition: all 0.2s ease; position: relative; user-select: none; }
.node-tree a:hover { color: var(--text-primary); background: rgba(255,255,255,0.04); }
.node-tree a.active { color: var(--text-primary); background: rgba(0,170,255,0.15); font-weight: 600; border-color: transparent; }
.node-tree a.active::before { content: ''; position: absolute; left: -1rem; top: 50%; transform: translateY(-50%); width: 4px; height: 60%; background: var(--accent-color); border-radius: 0 4px 4px 0; box-shadow: 0 0 8px var(--accent-color); }
.node-tree a.active:hover { background: rgba(0, 170, 255, 0.2); }
.node-tree a svg:not(.chevron) { flex-shrink: 0; width: 20px; height: 20px; transition: color 0.2s ease; }
.node-tree a:hover svg:not(.chevron) { filter: brightness(1.2); }
.node-tree a.active svg:not(.chevron) { color: var(--accent-color) !important; }
.node-tree a .chevron { margin-left: auto; transition: transform 0.3s ease; color: var(--text-secondary); }
.node-tree li.open > a .chevron { transform: rotate(90deg); }

/* Context Menu & Modals */
#context-menu { position: fixed; z-index: 1000; display: none; background-color: var(--panel-bg-color); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--border-color); border-radius: 12px; box-shadow: var(--shadow); padding: 0.5rem; min-width: 180px; animation: fadeIn 0.1s ease-out; }
.context-menu-item { display: block; padding: 0.6rem 1rem; border-radius: 8px; color: var(--text-secondary); cursor: pointer; user-select: none; }
.context-menu-item:hover { background-color: rgba(255,255,255,0.08); color: var(--text-primary); }
.context-menu-item.danger { color: var(--danger-color); }
.context-menu-separator { height: 1px; background-color: var(--border-color); margin: 0.5rem 0; }
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(10px); z-index: 2000; display: none; align-items: center; justify-content: center; animation: fadeIn 0.2s ease; }
.modal-dialog { background-color: #1a1c23; border: 1px solid var(--border-color); border-radius: var(--border-radius); box-shadow: var(--shadow); padding: 1.5rem; width: 90%; max-width: 400px; animation: fadeInUp 0.3s ease-out; }
.modal-dialog h3 { margin-bottom: 1rem; }
.modal-dialog p { margin-bottom: 1.5rem; color: var(--text-secondary); }
.modal-input { width: 100%; background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); border-radius: 8px; padding: .6rem .8rem; margin-bottom: 1.5rem; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 0.75rem; }
.modal-button { border: 1px solid var(--border-color); background: rgba(255,255,255,0.05); color: var(--text-primary); border-radius: 10px; padding: .5rem 1rem; cursor: pointer; }
.modal-button.primary { border-color: rgba(0,170,255,.5); background: rgba(0,170,255,.15); }
.modal-button.danger { border-color: rgba(249, 38, 114, .5); background: rgba(249, 38, 114, .15); }

/* 响应式 */
@media (max-width: 1024px) { 
    body.page-shell { padding: 1rem; --body-padding: 1rem; } 
    .dashboard-layout { flex-direction: column; } 
    .sidebar-panel { position: static; flex-basis: auto; } 
    .content-panel { height: 80vh; min-height: 500px; } 
    iframe { height: 100%; min-height: 0; } 
}

/* =========================================
   2. Sub-Pages (iframe 通用)
   ========================================= */
body.page-sub { background: transparent; margin: 0; font: 14px/1.5 var(--font-family); }
.content-wrapper { padding: 1.5rem; }
.dir-header { margin-bottom: 1.5rem; display: flex; align-items: center; gap: .75rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; }
.dir-header svg { color: var(--accent-color); width: 22px; height: 22px; }
.dir-header h1 { font-size: 1.1rem; font-weight: 500; margin: 0; }

/* 列表网格系统 */
.item-grid { display: flex; flex-direction: column; }
.grid-header, .grid-row { display: grid; grid-template-columns: 1fr 2fr 14fr 3fr; gap: 1rem; align-items: center; border-bottom: 1px solid var(--border-color); padding: 0.75rem 1rem; }
.grid-header { color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.grid-row { transition: background-color .2s ease; text-decoration: none; color: var(--text-secondary); }
.grid-row:hover { background-color: rgba(255,255,255,0.04); }
.grid-row:last-child { border-bottom: none; }
.node-name { display: flex; align-items: center; gap: .75rem; color: var(--text-primary); font-weight: 500; text-decoration: none; min-width: 0; }
.node-name:hover { text-decoration: none; }
.node-name svg { width: 18px; height: 18px; flex-shrink: 0; }
.node-name span { white-space: normal; word-break: break-all; }
.timestamp { font-size: 13px; font-family: ui-monospace, mono; text-align: right; }
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--text-secondary); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; opacity: .5; }
mark { background-color: #fce08b; color: #333; padding: 2px 3px; border-radius: 3px; }

/* 代码预览框 (共用于 Dir Content 和 Dashboard) */
.code-content {
    font-family: ui-monospace, mono; font-size: 13px;
    white-space: pre-wrap; word-break: break-all;
    overflow-y: auto; overflow-x: hidden;
    max-height: 126px; padding: 0.5rem; border-radius: 8px;
    line-height: 1.4; cursor: pointer; user-select: none;
}
.code-content.highlighted { background-color: rgba(0, 170, 255, 0.2); }
.code-content:empty::after { content: '—'; color: var(--text-secondary); }
.code-content::-webkit-scrollbar { width: 8px; }
.code-content::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); border-radius: 4px; }
.code-content::-webkit-scrollbar-thumb { background-color: #4a4a4a; border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
.code-content::-webkit-scrollbar-thumb:hover { background-color: var(--accent-color); }

/* =========================================
   3. File Editor (编辑器) 样式
   ========================================= */
body.page-editor { background-color: #0b0d12 !important; height: 100%; margin: 0; }
body.page-editor textarea#code { background-color: #212121; }

.editor-wrapper { position: relative; padding: 1.5rem; display: flex; flex-direction: column; height: 100%; box-sizing: border-box; }
.editor-form { display: flex; flex-direction: column; gap: 1rem; flex-grow: 1; }
.filename-input { width: 100%; background: var(--panel-bg-color); border: 1px solid var(--border-color); color: var(--text-primary); border-radius: 8px; padding: .6rem .8rem; font-size: 1rem; box-sizing: border-box; }
.CodeMirror { flex-grow: 1; border: 1px solid var(--border-color); border-radius: var(--border-radius); font-family: ui-monospace, Consolas, Menlo, monospace; font-size: 14px; height: auto; }
.CodeMirror-gutters { background: #212121 !important; }
.CodeMirror-vscrollbar::-webkit-scrollbar, .CodeMirror-hscrollbar::-webkit-scrollbar { width: 12px; height: 12px; }
.CodeMirror-vscrollbar::-webkit-scrollbar-track, .CodeMirror-hscrollbar::-webkit-scrollbar-track { background: #212121; }
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb, .CodeMirror-hscrollbar::-webkit-scrollbar-thumb { background: #4a4a4a; border-radius: 6px; border: 3px solid #212121; }
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover, .CodeMirror-hscrollbar::-webkit-scrollbar-thumb:hover { background: #5a5a5a; }
.actions-bar { padding-top: 1rem; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; height: 30px; }
.meta-info { color: var(--text-secondary); font-size: 12px; }
.save-status { color: var(--text-secondary); font-size: 12px; transition: opacity 0.3s ease; }
.close-button { position: absolute; top: 1rem; right: 1rem; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 24px; font-weight: 300; text-decoration: none; border-radius: 50%; transition: all 0.2s ease; z-index: 10; line-height: 1; }
.close-button:hover { background-color: rgba(255,255,255,0.1); color: var(--text-primary); transform: rotate(90deg); }

/* =========================================
   4. Dashboard (仪表盘) 样式
   ========================================= */
body.page-dashboard { background: transparent; margin: 0; }
.dashboard-wrapper { padding: 1rem; }
.dashboard-header { margin-bottom: 2rem; display: flex; align-items: center; gap: .75rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; }
.dashboard-header svg { color: var(--accent-color); width: 28px; height: 28px; }
.dashboard-header h1 { font-size: 1.5rem; font-weight: 600; margin: 0; }
.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.card { background: var(--panel-bg-color); border: 1px solid var(--border-color); border-radius: 12px; padding: 1rem; }
.card h3 { margin: 0 0 0.5rem 0; color: var(--text-secondary); font-size: 0.9rem; font-weight: 500; text-transform: uppercase; letter-spacing: .5px;}
.card p { margin: 0; color: var(--text-primary); font-size: 2rem; font-weight: 600; }
.table-container { background: var(--panel-bg-color); border: 1px solid var(--border-color); border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem 1.5rem; text-align: left; border-bottom: 1px solid var(--border-color); }
th { color: var(--text-secondary); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
td { color: var(--text-primary); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background-color: rgba(255, 255, 255, 0.04); }
.mono { font-family: ui-monospace, mono; font-size: 13px; }

/* Dashboard 搜索框 */
.search-container { margin-bottom: 1rem; }
.search-form { display: flex; gap: 1rem; }
.search-input { flex-grow: 1; background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); color: var(--text-primary); border-radius: 8px; padding: .8rem 1rem; font-size: 1rem; }
.search-button { border: 1px solid var(--border-color); background: rgba(255,255,255,0.05); color: var(--text-primary); border-radius: 10px; padding: .5rem 1.5rem; cursor: pointer; font-weight: 500; font-size: 1rem; }
.search-button:hover { border-color: var(--accent-color); }

/* Dashboard 最近文件列表定制覆盖 */
.page-dashboard .item-grid .grid-header, 
.page-dashboard .item-grid .grid-row { grid-template-columns: 0.5fr 5fr 11fr 3fr; padding: 0.75rem 1.5rem; }
.page-dashboard .grid-header { background: transparent; }
.page-dashboard .code-content { max-height: 84px; }
.page-dashboard .timestamp { text-align: left; }

/* 文件路径彩色高亮 */
.file-path { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; font-size: .95em; word-break: break-all; }
.file-path a { text-decoration: none; }
.file-path .repo { color: #66d9ff; }
.file-path .proj { color: #a6e22e; }
.file-path .comp { color: #ff79c6; }
.file-path .name { color: var(--text-primary); font-weight: 500; }
.file-path .sep { color: var(--text-secondary); margin: 0 2px; }

/* 动画定义 */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
