/* ============================================================
 * 深色模式（全站通用）
 * 由 <html data-theme="dark"> 属性触发，theme.js 负责切换。
 * 仅需在每页 <head> 末尾引入本样式（位于页面自有样式之后）。
 * ============================================================ */

/* ---- 浅色默认变量补充（供内联样式使用 var(--input-bg) 自适应） ---- */
:root {
    --input-bg: #fafbfc;
    --hover-bg: #f8f9fa;
}

/* ============================================================
 * 一、变量覆盖
 * ============================================================ */
[data-theme="dark"] {
    /* 通用（主页 / 烧录 / 激活 / 工具 / OTA / 服务器） */
    --primary: #4db6e0;
    --primary-dark: #3aa0cf;
    --primary-light: #74c9ef;
    --secondary: #f6b428;
    --secondary-light: #f8c850;
    --bg: #0e1420;
    --card-bg: #171f2e;
    --text: #e6ecf4;
    --text-secondary: #93a3b8;
    --border: #2b3648;
    --danger: #f0716b;
    --warning: #f5b450;
    --success: #57c784;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --input-bg: #131c2c;
    --hover-bg: #1a2436;

    /* AI 网关 */
    --ai-primary: #9683ff;
    --ai-primary-2: #6cd4fa;
    --ai-primary-grad: linear-gradient(135deg, #7c5cff 0%, #6cb4f0 100%);
    --ai-accent: #ff9d74;
    --ai-accent-grad: linear-gradient(135deg, #ff8a65 0%, #ffb74d 100%);
    --ai-green: #7ed48b;
    --ai-red: #ff7875;
    --ai-bg: linear-gradient(160deg, #141220 0%, #0f1826 50%, #1d1410 100%);
    --ai-card: rgba(26, 30, 44, 0.88);
    --ai-card-solid: #1a1e2c;
    --ai-text: #eae8f7;
    --ai-text-2: #9d99b5;
    --ai-border: #302c48;
    --ai-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
    --ai-shadow-hover: 0 16px 44px rgba(0, 0, 0, 0.6);
}

/* ============================================================
 * 二、全局基础元素
 * ============================================================ */

/* 滚动条 */
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #3a475c; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #4a5870; }

/* 输入框 / 下拉框 / 文本域（排除 range 滑块，保留其自身渐变/主题色）
   background 用 !important：可覆盖各工具 JS 注入的内联 background（如 #fafbfc） */
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--input-bg) !important;
    color: var(--text);
}
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
    background: #1a2436 !important;
}
/* 下拉选项列表 */
[data-theme="dark"] select option {
    background: var(--card-bg) !important;
    color: var(--text) !important;
}
/* 主站烧录弹窗输入框保持原有深色 */
[data-theme="dark"] .flash-form-group select,
[data-theme="dark"] .flash-form-group input {
    background: #0d1b2a !important;
}

/* 主题切换按钮（各页导航中的 .nav-btn 样式已统一，这里兜底） */
[data-theme="dark"] .theme-toggle { color: var(--text-secondary); }

/* ============================================================
 * 三、导航栏 / 下拉菜单 / 页脚
 * ============================================================ */
[data-theme="dark"] .navbar,
[data-theme="dark"] .flasher-nav,
[data-theme="dark"] .tools-nav,
[data-theme="dark"] .ota-nav,
[data-theme="dark"] .server-nav {
    background: rgba(13, 18, 30, 0.88);
}

/* 主站导航（首页） */
[data-theme="dark"] .navbar { border-bottom-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .nav-dropdown-menu,
[data-theme="dark"] .nav-links.open {
    background: rgba(23, 31, 46, 0.98);
}
[data-theme="dark"] .footer {
    background: rgba(14, 20, 32, 0.9);
    border-top-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .services-divider::after {
    border-bottom-color: rgba(255, 255, 255, 0.25);
}

/* 域名迁移提示条（内联在 index.html 的 <style> 中，需更高优先级覆盖） */
[data-theme="dark"] #domain-notice {
    background: #1a2233;
    color: #c9d4e3;
}
[data-theme="dark"] #domain-notice-close:hover { color: #fff; }

/* ============================================================
 * 四、登录页（flasher / tools / ota / server / activate）
 * ============================================================ */
[data-theme="dark"] .login-overlay {
    background: linear-gradient(135deg, #0e1420 0%, #131a28 100%);
}

/* ============================================================
 * 五、通用浅色表面组件（各页面复用）
 * ============================================================ */
[data-theme="dark"] .custom-file-card,
[data-theme="dark"] .form-card,
[data-theme="dark"] .version-info,
[data-theme="dark"] .ver-public-switch,
[data-theme="dark"] .intro-image,
[data-theme="dark"] .flash-mode-option,
[data-theme="dark"] .changelog-box,
[data-theme="dark"] .convert-result,
[data-theme="dark"] .feature-item,
[data-theme="dark"] .project-note,
[data-theme="dark"] .placeholder-card,
[data-theme="dark"] .qf-heye-shot-item,
[data-theme="dark"] .qf-heye-empty,
[data-theme="dark"] .activate-result-card,
[data-theme="dark"] .activate-config-control,
[data-theme="dark"] .activate-admin-stat-card,
[data-theme="dark"] .device-item,
[data-theme="dark"] .ip-stat-item,
[data-theme="dark"] .whitelist-item,
[data-theme="dark"] .port-request-btn,
[data-theme="dark"] .admin-info-card,
[data-theme="dark"] .upload-area,
[data-theme="dark"] .font-item {
    background: var(--input-bg);
}

/* 工具页面 JS 注入组件的浅色表面 */
[data-theme="dark"] .lvl-file-drop,
[data-theme="dark"] .lvl-paste-zone,
[data-theme="dark"] .lvl-name-clear-btn,
[data-theme="dark"] .lvl-custom-select-trigger,
[data-theme="dark"] .pid-param-row {
    background: var(--input-bg);
}
[data-theme="dark"] .pid-port-modal-btn-cancel:hover { background: rgba(255, 255, 255, 0.08); }

/* 端口列表分割线 / 悬浮反馈 */
[data-theme="dark"] .port-modal-item { border-bottom-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .port-modal-close:hover,
[data-theme="dark"] .port-modal-btn-cancel:hover,
[data-theme="dark"] .modal-btn-cancel:hover,
[data-theme="dark"] .modal-close:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* 禁用按钮 */
[data-theme="dark"] .qf-heye-tool .convert-btn:disabled,
[data-theme="dark"] .qf-heye-tool .convert-btn:disabled:hover,
[data-theme="dark"] .modal-btn-ok:disabled,
[data-theme="dark"] .modal-btn-ok:disabled:hover {
    background: #2b3648;
    border-color: #2b3648;
    color: #7a8798;
}

/* 图片透明度棋盘格 */
[data-theme="dark"] .qf-heye-preview-stage {
    background: repeating-conic-gradient(#232b3b 0% 25%, #1c2434 0% 50%) 50% / 18px 18px;
}

/* OTA 开关滑块 */
[data-theme="dark"] .slider { background: #3a475c; }

/* 调色板 ARGB 滑块：深色下加深色棋盘格 + 轮廓边框 */
[data-theme="dark"] .cp-a-track {
    background: repeating-conic-gradient(#3a475c 0% 25%, #232b3b 0% 50%) 0 0 / 8px 8px;
}
[data-theme="dark"] .cp-slider-wrap,
[data-theme="dark"] .cp-lightness-wrap {
    border: 1px solid #3a475c;
}
[data-theme="dark"] .cp-fmt-btn {
    background: var(--card-bg);
}

/* PID 调参：禁用按钮深色化（未连接时不再灰白刺眼） */
[data-theme="dark"] .pid-param-row button:disabled,
[data-theme="dark"] .pid-action-btn:disabled,
[data-theme="dark"] .pid-action-btn-tune:disabled {
    background: #2b3648 !important;
    color: #7a8798 !important;
}
/* PID 曲线图 canvas 底色（绘制时会按主题填充，这里兜底） */
[data-theme="dark"] #pid-chart-canvas {
    background: #121a28;
}
/* PID 弹窗列表分割线 / 关闭按钮悬浮 */
[data-theme="dark"] .pid-port-modal-item {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .pid-port-modal-close:hover { background: rgba(255, 255, 255, 0.08); }

/* ============================================================
 * 六、控制台页内联样式覆盖（flasher/activate admin.html）
 * ============================================================ */
[data-theme="dark"] .admin-grid .form-group input,
[data-theme="dark"] .admin-grid .form-group textarea,
[data-theme="dark"] .admin-grid .form-group select {
    background: var(--input-bg);
}
[data-theme="dark"] .admin-grid .form-group input:focus,
[data-theme="dark"] .admin-grid .form-group textarea:focus,
[data-theme="dark"] .admin-grid .form-group select:focus {
    background: #1a2436;
}
[data-theme="dark"] .admin-grid .form-group select option {
    background: var(--card-bg);
    color: var(--text);
}
[data-theme="dark"] .admin-info-card textarea { background: var(--input-bg); }

/* ============================================================
 * 七、服务器管理（文件编辑器等）
 * ============================================================ */
[data-theme="dark"] .file-editor-body,
[data-theme="dark"] .file-editor-text { background: #121a28; }
[data-theme="dark"] .file-editor-lines { background: #1a2434; color: #8b98ab; }

/* ============================================================
 * 八、凡凡 全站悬浮助手
 * ============================================================ */
[data-theme="dark"] #sa-fab .sa-bubble {
    background: #232b3b;
    color: #dde3ec;
    border-color: rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] #sa-fab .sa-bubble::after { border-left-color: #232b3b; }
[data-theme="dark"] #sa-panel {
    background: #171f2e;
    border-color: rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] #sa-panel .sa-msgs { background: #121a28; }
[data-theme="dark"] #sa-panel .sa-msg .sa-m-body {
    background: #232b3b;
    color: #dde3ec;
}
[data-theme="dark"] #sa-panel .sa-msg .sa-m-body pre,
[data-theme="dark"] #sa-panel .sa-msg .sa-m-body code {
    background: #1a2436;
    color: #a8c8e8;
}
[data-theme="dark"] #sa-panel .sa-msg .sa-m-body th,
[data-theme="dark"] #sa-panel .sa-msg .sa-m-body td { border-color: #3a475c; }
[data-theme="dark"] #sa-panel .sa-msg .sa-m-body th { background: #2b2438; }
[data-theme="dark"] #sa-panel .sa-tooltip { background: #2b2438; color: #a99bff; }
[data-theme="dark"] #sa-panel .sa-err-msg { background: #3a2326; color: #ff8a80; }
[data-theme="dark"] #sa-panel .sa-inputbar {
    background: #1a2233;
    border-top-color: #2b3648;
}
[data-theme="dark"] #sa-panel .sa-inputrow textarea {
    background: #131c2c;
    color: #e6ecf4;
    border-color: #2b3648;
}
[data-theme="dark"] #sa-panel .sa-stopbar button {
    background: #232b3b;
    border-color: #3a475c;
    color: #93a3b8;
}
[data-theme="dark"] #sa-panel .sa-hint { color: #6b7a8f; }
[data-theme="dark"] .sa-thinking-body { color: #a0a8b8; }

/* ============================================================
 * 九、FRP 管理（节点内隧道配置容器等）
 * ============================================================ */
[data-theme="dark"] .frp-tunnel {
    background: #121a28;
}
[data-theme="dark"] .frp-tunnel-header {
    background: rgba(31, 138, 190, 0.08);
    border-bottom-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .frp-ini-section {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .frp-sakura-table td {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

/* ============================================================
 * 十、主页（v40 重构版）
 * ============================================================ */
/* 深色表面变量 */
[data-theme="dark"] {
    --bg-elev: rgba(19, 27, 42, 0.72);
    --border-strong: rgba(150, 180, 210, 0.22);
    --primary-soft: rgba(77, 182, 224, 0.10);
    --primary-soft-2: rgba(77, 182, 224, 0.20);
}

/* 背景：网格线与光斑 */
[data-theme="dark"] .bg-layer::after {
    color: rgba(77, 182, 224, 0.14);
}
[data-theme="dark"] .bg-orb-1 { background: rgba(31, 138, 190, 0.17); }
[data-theme="dark"] .bg-orb-2 { background: rgba(246, 180, 40, 0.08); }
[data-theme="dark"] .bg-orb-3 { background: rgba(31, 138, 190, 0.12); }

/* Hero */
[data-theme="dark"] .hero-glow {
    background: radial-gradient(circle, rgba(31,138,190,0.13) 0%, transparent 68%);
}
[data-theme="dark"] .hero-title {
    background: linear-gradient(115deg, #eef4fb 30%, var(--primary-light) 74%, var(--secondary) 102%);
    -webkit-background-clip: text;
    background-clip: text;
}
[data-theme="dark"] .hero-logo img {
    filter: drop-shadow(0 18px 44px rgba(31, 138, 190, 0.38));
}

/* 次要按钮：深色玻璃感 */
[data-theme="dark"] .btn-secondary {
    background: var(--input-bg);
    color: var(--text);
    border-color: var(--border-strong);
}
[data-theme="dark"] .btn-secondary:hover {
    color: var(--primary-light);
    background: var(--hover-bg);
}

/* 服务卡 / 项目卡 */
[data-theme="dark"] .service-card,
[data-theme="dark"] .project-showcase-card {
    box-shadow: none;
}
[data-theme="dark"] .service-card:hover,
[data-theme="dark"] .project-showcase-card:hover {
    box-shadow: var(--shadow-lg);
}
[data-theme="dark"] .services-divider::after {
    border-bottom-color: rgba(255, 255, 255, 0.16);
}

/* 管理员登录弹窗输入框聚焦光晕（深色下用深色底） */
[data-theme="dark"] #admin-login-overlay input:focus {
    background: #1a2436 !important;
}
