/*
 * 方向A「暗幕·银印」— new-api 注入 CSS
 * 安装：nginx sub_filter 把本文件注入到 <head> 末尾（见 nginx-sample.conf）
 * 版本：1.0.0  2026-11-24
 *
 * 覆盖页面（由 darkmode.js 在目标路径注入 dark class，本文件靠 dark class 生效）：
 *   登录/注册/忘记密码、控制台首页、密钥页、模型/参数页、钱包/充值、使用日志
 */

/* ─────────────────────────────────────────
   Token 层：所有颜色都从这里出，改一处全改
   ───────────────────────────────────────── */
:root {
  --dm-bg:        #0D0F14;
  --dm-bg-card:   #161920;
  --dm-bg-hover:  #1E222E;
  --dm-bg-input:  #1A1E2A;
  --dm-bg-code:   #111318;
  --dm-border:    #2A2E3D;
  --dm-border-focus: #6366F1;
  --dm-text:      #E8EAF0;
  --dm-text-muted:#8B8FA8;
  --dm-text-dim:  #555870;
  --dm-accent:    #6366F1;
  --dm-accent-hover: #4F52D4;
  --dm-accent-soft:  rgba(99,102,241,0.15);
  --dm-success:   #34D399;
  --dm-warn:      #FBBF24;
  --dm-danger:    #F87171;
  --dm-radius-sm: 8px;
  --dm-radius:    12px;
  --dm-radius-lg: 16px;
}

/* ─────────────────────────────────────────
   全局 — 仅在 dark class 存在时生效
   ───────────────────────────────────────── */
html.dm-dark,
html.dm-dark body {
  background-color: var(--dm-bg) !important;
  color: var(--dm-text) !important;
  -webkit-font-smoothing: antialiased;
}

/* Tailwind dark: 变体触发（配合 JS 加 dark class） */
html.dark,
html.dark body {
  background-color: var(--dm-bg) !important;
  color: var(--dm-text) !important;
  -webkit-font-smoothing: antialiased;
}

/* 通用白色/亮色背景覆盖 */
html.dm-dark .bg-white,
html.dm-dark [class*="bg-gray-50"],
html.dm-dark [class*="bg-gray-100"],
html.dm-dark [class*="bg-slate-50"],
html.dm-dark [class*="bg-zinc-50"],
html.dm-dark [class*="bg-neutral-50"] {
  background-color: var(--dm-bg-card) !important;
}

html.dm-dark [class*="bg-gray-200"],
html.dm-dark [class*="bg-slate-200"] {
  background-color: var(--dm-bg-hover) !important;
}

/* 文字颜色 */
html.dm-dark [class*="text-gray-900"],
html.dm-dark [class*="text-slate-900"],
html.dm-dark [class*="text-zinc-900"],
html.dm-dark [class*="text-black"] {
  color: var(--dm-text) !important;
}

html.dm-dark [class*="text-gray-600"],
html.dm-dark [class*="text-gray-700"],
html.dm-dark [class*="text-slate-600"],
html.dm-dark [class*="text-zinc-600"] {
  color: var(--dm-text-muted) !important;
}

html.dm-dark [class*="text-gray-400"],
html.dm-dark [class*="text-gray-500"],
html.dm-dark [class*="text-slate-400"] {
  color: var(--dm-text-dim) !important;
}

/* 边框 */
html.dm-dark [class*="border"],
html.dm-dark [class*="divide-"] > * {
  border-color: var(--dm-border) !important;
}

html.dm-dark hr {
  border-color: var(--dm-border) !important;
}

/* ─────────────────────────────────────────
   卡片 / 容器
   ───────────────────────────────────────── */
html.dm-dark .card,
html.dm-dark [class*="shadow"],
html.dm-dark [class*="rounded"] {
  background-color: var(--dm-bg-card);
  border-color: var(--dm-border);
}

/* 确保卡片圆角 */
html.dm-dark [class*="rounded-lg"],
html.dm-dark [class*="rounded-xl"] {
  border-radius: var(--dm-radius) !important;
}

html.dm-dark [class*="rounded-2xl"],
html.dm-dark [class*="rounded-3xl"] {
  border-radius: var(--dm-radius-lg) !important;
}

/* ─────────────────────────────────────────
   表单 — 登录/注册重点覆盖
   ───────────────────────────────────────── */
html.dm-dark input,
html.dm-dark textarea,
html.dm-dark select {
  background-color: var(--dm-bg-input) !important;
  border-color: var(--dm-border) !important;
  color: var(--dm-text) !important;
  border-radius: var(--dm-radius-sm) !important;
}

html.dm-dark input::placeholder,
html.dm-dark textarea::placeholder {
  color: var(--dm-text-dim) !important;
}

html.dm-dark input:focus,
html.dm-dark textarea:focus,
html.dm-dark select:focus {
  border-color: var(--dm-border-focus) !important;
  outline: none !important;
  box-shadow: 0 0 0 3px var(--dm-accent-soft) !important;
}

html.dm-dark input:-webkit-autofill,
html.dm-dark input:-webkit-autofill:hover,
html.dm-dark input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--dm-bg-input) inset !important;
  -webkit-text-fill-color: var(--dm-text) !important;
  caret-color: var(--dm-text) !important;
}

/* label */
html.dm-dark label {
  color: var(--dm-text-muted) !important;
}

/* ─────────────────────────────────────────
   按钮
   ───────────────────────────────────────── */
/* 主按钮：朱砂→靛紫 */
html.dm-dark button[type="submit"],
html.dm-dark [class*="btn-primary"],
html.dm-dark .bg-blue-500,
html.dm-dark .bg-blue-600,
html.dm-dark [class*="bg-indigo-"],
html.dm-dark [class*="bg-violet-"] {
  background-color: var(--dm-accent) !important;
  color: #fff !important;
  border-radius: var(--dm-radius-sm) !important;
  border: none !important;
  transition: background-color 0.15s ease !important;
}

html.dm-dark button[type="submit"]:hover,
html.dm-dark [class*="btn-primary"]:hover,
html.dm-dark .bg-blue-500:hover,
html.dm-dark .bg-blue-600:hover {
  background-color: var(--dm-accent-hover) !important;
}

/* 次级按钮 */
html.dm-dark button:not([type="submit"]):not([disabled]),
html.dm-dark [class*="btn-secondary"] {
  background-color: var(--dm-bg-hover) !important;
  color: var(--dm-text) !important;
  border-color: var(--dm-border) !important;
  border-radius: var(--dm-radius-sm) !important;
}

html.dm-dark button:hover:not([type="submit"]):not([disabled]) {
  background-color: var(--dm-bg-card) !important;
  border-color: var(--dm-accent) !important;
}

html.dm-dark button:disabled,
html.dm-dark [disabled] {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
}

/* ─────────────────────────────────────────
   导航 / 侧栏
   ───────────────────────────────────────── */
html.dm-dark nav,
html.dm-dark aside,
html.dm-dark [class*="sidebar"],
html.dm-dark [class*="nav-"] {
  background-color: var(--dm-bg) !important;
  border-color: var(--dm-border) !important;
}

html.dm-dark nav a,
html.dm-dark aside a {
  color: var(--dm-text-muted) !important;
  border-radius: var(--dm-radius-sm) !important;
}

html.dm-dark nav a:hover,
html.dm-dark aside a:hover,
html.dm-dark nav a.active,
html.dm-dark aside a.active,
html.dm-dark [class*="active"] a {
  background-color: var(--dm-accent-soft) !important;
  color: var(--dm-accent) !important;
}

/* ─────────────────────────────────────────
   表格
   ───────────────────────────────────────── */
html.dm-dark table {
  background-color: var(--dm-bg-card) !important;
  border-color: var(--dm-border) !important;
}

html.dm-dark th {
  background-color: var(--dm-bg) !important;
  color: var(--dm-text-muted) !important;
  border-color: var(--dm-border) !important;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

html.dm-dark td {
  color: var(--dm-text) !important;
  border-color: var(--dm-border) !important;
}

html.dm-dark tr:hover td {
  background-color: var(--dm-bg-hover) !important;
}

/* ─────────────────────────────────────────
   代码 / 徽章 / 标签
   ───────────────────────────────────────── */
html.dm-dark code,
html.dm-dark pre,
html.dm-dark [class*="code-"] {
  background-color: var(--dm-bg-code) !important;
  color: #A5B4FC !important;
  border-radius: var(--dm-radius-sm) !important;
  border: 1px solid var(--dm-border) !important;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace !important;
}

/* 状态徽章 */
html.dm-dark [class*="badge"],
html.dm-dark [class*="tag"],
html.dm-dark [class*="chip"] {
  background-color: var(--dm-bg-hover) !important;
  color: var(--dm-text-muted) !important;
  border-radius: 4px !important;
  border: 1px solid var(--dm-border) !important;
}

html.dm-dark [class*="badge-success"],
html.dm-dark .text-green-500 { color: var(--dm-success) !important; }
html.dm-dark [class*="badge-warn"],
html.dm-dark .text-yellow-500 { color: var(--dm-warn) !important; }
html.dm-dark [class*="badge-danger"],
html.dm-dark .text-red-500 { color: var(--dm-danger) !important; }

/* ─────────────────────────────────────────
   模态框 / 弹窗
   ───────────────────────────────────────── */
html.dm-dark [role="dialog"],
html.dm-dark [class*="modal"],
html.dm-dark [class*="dialog"] {
  background-color: var(--dm-bg-card) !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: var(--dm-radius-lg) !important;
  color: var(--dm-text) !important;
}

html.dm-dark [class*="modal-backdrop"],
html.dm-dark [class*="overlay"] {
  background-color: rgba(0, 0, 0, 0.7) !important;
}

/* ─────────────────────────────────────────
   下拉菜单
   ───────────────────────────────────────── */
html.dm-dark [class*="dropdown"],
html.dm-dark [role="menu"],
html.dm-dark [role="listbox"] {
  background-color: var(--dm-bg-card) !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: var(--dm-radius) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important;
}

html.dm-dark [role="menuitem"],
html.dm-dark [role="option"] {
  color: var(--dm-text) !important;
}

html.dm-dark [role="menuitem"]:hover,
html.dm-dark [role="option"]:hover {
  background-color: var(--dm-bg-hover) !important;
}

/* ─────────────────────────────────────────
   通知 / Toast
   ───────────────────────────────────────── */
html.dm-dark [class*="toast"],
html.dm-dark [class*="alert"],
html.dm-dark [class*="notification"] {
  background-color: var(--dm-bg-card) !important;
  border: 1px solid var(--dm-border) !important;
  color: var(--dm-text) !important;
  border-radius: var(--dm-radius) !important;
}

/* ─────────────────────────────────────────
   登录页专属 — 居中卡片布局增强
   ───────────────────────────────────────── */
html.dm-dark.dm-auth {
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99,102,241,0.18) 0%, transparent 70%),
              var(--dm-bg) !important;
  min-height: 100vh;
}

html.dm-dark.dm-auth body {
  background: transparent !important;
}

/* 登录卡片 */
html.dm-dark.dm-auth .h-screen,
html.dm-dark.dm-auth [class*="min-h-screen"],
html.dm-dark.dm-auth [class*="h-full"] {
  background: transparent !important;
}

html.dm-dark.dm-auth form,
html.dm-dark.dm-auth [class*="card"],
html.dm-dark.dm-auth [class*="shadow-"] {
  background-color: var(--dm-bg-card) !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: var(--dm-radius-lg) !important;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.05) inset !important;
}

/* 登录页底部量尺（装饰线） */
html.dm-dark.dm-auth body::after {
  content: "";
  display: block;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--dm-accent), transparent);
  opacity: 0.6;
  pointer-events: none;
}

/* 登录页品牌眉标 */
html.dm-dark.dm-auth body::before {
  content: "AI API GATEWAY · SIGN IN";
  display: block;
  position: fixed;
  top: 24px; left: 50%; transform: translateX(-50%);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--dm-text-dim);
  pointer-events: none;
  z-index: 999;
}

/* ─────────────────────────────────────────
   控制台首页 — 数据卡片
   ───────────────────────────────────────── */
html.dm-dark.dm-console [class*="stat"],
html.dm-dark.dm-console [class*="metric"],
html.dm-dark.dm-console [class*="summary"] {
  background-color: var(--dm-bg-card) !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: var(--dm-radius) !important;
}

/* 大数字 */
html.dm-dark.dm-console [class*="text-2xl"],
html.dm-dark.dm-console [class*="text-3xl"],
html.dm-dark.dm-console [class*="text-4xl"] {
  color: var(--dm-text) !important;
  font-variant-numeric: tabular-nums !important;
}

/* ─────────────────────────────────────────
   图表 — 未覆盖说明（见 darkmode.js）
   ───────────────────────────────────────── */
/* Chart.js / Recharts 由 canvas 或 SVG 渲染，颜色靠 JS props，
   CSS 无法覆盖。见 darkmode.js 的 dm_patchCharts() 函数。
   未能覆盖的图表见安装步骤.md「二期待办」章节。 */

/* ─────────────────────────────────────────
   滚动条（WebKit）
   ───────────────────────────────────────── */
html.dm-dark ::-webkit-scrollbar {
  width: 6px; height: 6px;
  background: var(--dm-bg);
}
html.dm-dark ::-webkit-scrollbar-thumb {
  background: var(--dm-border);
  border-radius: 3px;
}
html.dm-dark ::-webkit-scrollbar-thumb:hover {
  background: var(--dm-text-dim);
}

/* ─────────────────────────────────────────
   选中高亮
   ───────────────────────────────────────── */
html.dm-dark ::selection {
  background: var(--dm-accent-soft);
  color: var(--dm-text);
}
