/* ===================================================================
   QTP · 月相双主题设计系统 (Lunar Dual-Theme)
   月之暗面 (Moon Dark Side) = 默认深色
   月之明面 (Moon Bright Side) = 浅色主题
   主题通过 <html data-theme="dark|light"> 切换，状态存于 localStorage
   =================================================================== */

/* ---------- 月之暗面：深色（默认） ---------- */
:root, [data-theme="dark"] {
  --bg: #0b0e1a;
  --bg-elev: #11162a;
  --card: #151a2c;
  --card-hover: #1c2236;
  --border: #28304a;
  --border-strong: #364061;
  --text: #e8ebf5;
  --text-dim: #8a91a8;
  --primary: #7aa2ff;
  --primary-hover: #5e87f0;
  --primary-soft: rgba(122, 162, 255, 0.14);
  --accent: #b08bff;            /* 月辉紫 */
  --accent-soft: rgba(176, 139, 255, 0.15);
  --red: #ff5a6a;               /* A股：涨=红 */
  --green: #2ec27e;             /* A股：跌=绿 */
  --yellow: #f5b942;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  --glow-color: rgba(122, 162, 255, 0.18);
  --ambient: radial-gradient(1200px 520px at 78% -8%, rgba(122,162,255,0.16), transparent 60%),
             radial-gradient(900px 460px at 8% 4%, rgba(176,139,255,0.12), transparent 55%);
  --radius: 13px;
  --radius-sm: 9px;
  --chart-grid: #232b42;
  --chart-tick: #8a91a8;
  --chart-line: #7aa2ff;
  --chart-fill: rgba(122, 162, 255, 0.12);
  --scrollbar: #2a3350;
  --input-bg: #0e1322;
}

/* ---------- 月之明面：浅色 ---------- */
[data-theme="light"] {
  --bg: #eef1f8;
  --bg-elev: #f6f8fd;
  --card: #ffffff;
  --card-hover: #fbfcff;
  --border: #dfe4f0;
  --border-strong: #c7cfe0;
  --text: #15203a;
  --text-dim: #5d6680;
  --primary: #3b63d8;
  --primary-hover: #2c4fc0;
  --primary-soft: rgba(59, 99, 216, 0.10);
  --accent: #8a5cf0;
  --accent-soft: rgba(138, 92, 240, 0.10);
  --red: #e23b4e;
  --green: #18a05a;
  --yellow: #d9940a;
  --shadow: 0 10px 30px rgba(40, 60, 120, 0.10);
  --glow-color: rgba(59, 99, 216, 0.12);
  --ambient: radial-gradient(1100px 480px at 80% -10%, rgba(122,162,255,0.16), transparent 62%),
             radial-gradient(820px 420px at 6% 2%, rgba(176,139,255,0.12), transparent 58%);
  --chart-grid: #e7ebf4;
  --chart-tick: #5d6680;
  --chart-line: #3b63d8;
  --chart-fill: rgba(59, 99, 216, 0.10);
  --scrollbar: #c8d0e2;
  --input-bg: #f4f6fc;
}

/* ---------- Reset & Base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s ease, color .35s ease;
}
/* 月辉环境光：深色为暗夜观测台，浅色为月华白昼 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--ambient);
  pointer-events: none;
  z-index: 0;
  transition: background .35s ease;
}
body > * { position: relative; z-index: 1; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 数字等宽：交易终端质感（数据栏专用字体） */
.num {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', Menlo, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

/* 小标签 / 眉题 */
.eyebrow {
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
}

/* ---------- 页面头部（重设计的统一标题区） ---------- */
.page-header {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}
.page-header .desc {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- Auth pages ---------- */
.auth-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 38px 36px;
  width: 100%; max-width: 410px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: '';
  position: absolute; top: -40px; right: -40px;
  width: 130px; height: 130px; border-radius: 50%;
  background: var(--accent-soft);
  filter: blur(6px);
}
.auth-card > * { position: relative; }
.auth-card h1 { font-size: 23px; margin-bottom: 6px; letter-spacing: -0.3px; }
.auth-card h1 .moon-mark { color: var(--accent); }
.auth-card .sub { color: var(--text-dim); font-size: 13.5px; margin-bottom: 22px; }
.auth-card .form-group { margin-bottom: 15px; }
.auth-card label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.auth-card input, .auth-card textarea, .auth-card select {
  width: 100%; padding: 11px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.auth-card input:focus, .auth-card textarea:focus, .auth-card select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.auth-card .btn {
  width: 100%; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.auth-card .btn:hover { background: var(--primary-hover); }
.auth-card .btn:disabled { opacity: .5; cursor: not-allowed; }
.auth-card .footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-dim); }

.login-hint {
  margin-top: 18px; padding: 14px; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.login-hint .hint-title { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; font-weight: 600; }
.login-hint .hint-row { font-size: 13px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.login-hint .hint-note { font-size: 11px; color: var(--text-dim); margin-top: 8px; line-height: 1.6; }

.alert {
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px;
}
.alert.error { background: rgba(255,90,106,.14); color: var(--red); border: 1px solid rgba(255,90,106,.3); }
.alert.success { background: rgba(46,194,126,.14); color: var(--green); border: 1px solid rgba(46,194,126,.3); }

/* ---------- Navbar ---------- */
.navbar {
  background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0 22px; height: 58px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 100;
}
.navbar .logo { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.navbar .logo span { color: var(--primary); }
.navbar .nav-right { display: flex; align-items: center; gap: 14px; }
.navbar .user-info { font-size: 13px; color: var(--text-dim); }
.navbar .badge {
  padding: 2px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
}
.badge.admin { background: rgba(245,185,66,.2); color: var(--yellow); }
.badge.user { background: var(--primary-soft); color: var(--primary); }
.navbar a {
  font-size: 13px; color: var(--text-dim); padding: 6px 10px;
  border-radius: 7px; transition: all .18s;
}
.navbar a:hover { color: var(--text); background: rgba(128,128,128,.08); text-decoration: none; }
.navbar a.nav-active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }

.btn-logout {
  padding: 6px 14px; background: transparent; border: 1px solid var(--border);
  border-radius: 7px; color: var(--text-dim); font-size: 13px; cursor: pointer;
  transition: all .18s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

/* 月相主题切换下拉（签名元素） */
.theme-switch { display: flex; align-items: center; gap: 8px; }
.moon-orb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text); position: relative; flex: none;
  transition: background .35s ease, box-shadow .35s ease;
}
[data-theme="dark"] .moon-orb { background: #cfd6ea; }
[data-theme="dark"] .moon-orb::after {
  content: ''; position: absolute; border-radius: 50%;
  width: 15px; height: 15px; top: -0.5px; left: 5px;
  background: var(--bg);
}
[data-theme="light"] .moon-orb {
  background: #f5d76e;
  box-shadow: 0 0 7px rgba(245,215,110,.65), inset -3px -2px 4px rgba(180,140,40,.45);
}
.theme-select {
  padding: 6px 10px; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 12.5px; cursor: pointer; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.theme-select:hover { border-color: var(--primary); }
.theme-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.main { padding: 26px 24px 40px; max-width: 1400px; margin: 0 auto; }

/* ---------- Metric cards（重设计：左侧月辉强调条 + 等大数字） ---------- */
.metrics-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.metric-card {
  position: relative;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .18s ease, border-color .18s ease;
}
.metric-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(var(--primary), var(--accent));
  opacity: .85;
}
.metric-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.metric-card .label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; letter-spacing: .3px; }
.metric-card .value { font-size: 25px; font-weight: 700; letter-spacing: -0.6px; }
.metric-card .change { font-size: 13px; margin-top: 5px; }
.change.up { color: var(--red); }
.change.down { color: var(--green); }

/* ---------- Sections / Cards ---------- */
.section {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.section h2 {
  font-size: 15.5px; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 9px; letter-spacing: -0.2px;
}
.section h2::before {
  content: ''; width: 4px; height: 15px; border-radius: 3px;
  background: linear-gradient(var(--primary), var(--accent));
}
.chart-wrap { height: 300px; position: relative; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 13px; text-align: left; font-size: 13px; }
th {
  color: var(--text-dim); font-weight: 600; font-size: 12px;
  letter-spacing: .4px; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s; }
tr:hover td { background: rgba(128,128,128,.06); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }

/* ---------- Buttons ---------- */
.btn-create {
  padding: 8px 16px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.btn-create:hover { background: var(--primary-hover); }
.btn-create:disabled { opacity: .5; cursor: not-allowed; }
.btn-cancel {
  padding: 8px 16px; background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  cursor: pointer; transition: all .18s;
}
.btn-cancel:hover { border-color: var(--text-dim); color: var(--text); }
.btn-ghost {
  padding: 6px 12px; background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 7px; font-size: 12.5px;
  cursor: pointer; transition: all .18s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost.danger:hover { border-color: var(--red); color: var(--red); }

/* ---------- Admin / generic actions ---------- */
.admin-actions { display: flex; gap: 8px; }
.admin-actions button {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-dim); font-size: 12px; cursor: pointer;
}
.admin-actions button:hover { border-color: var(--primary); color: var(--primary); }
.admin-actions button.danger:hover { border-color: var(--red); color: var(--red); }
.role-select {
  padding: 4px 8px; background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 12px;
}

/* ---------- Form controls（供页面内联复用，统一观感） ---------- */
.field {
  width: 100%; padding: 9px 12px; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Loading ---------- */
.loading { text-align: center; padding: 40px; color: var(--text-dim); }
.spinner {
  border: 3px solid var(--border); border-top: 3px solid var(--primary);
  border-radius: 50%; width: 32px; height: 32px;
  animation: spin 1s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(6,9,18,.6); display: flex; align-items: center;
  justify-content: center; z-index: 200; backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px 28px; width: 100%; max-width: 540px;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px;
}
.modal-header h3 { font-size: 18px; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 24px; cursor: pointer; line-height: 1; padding: 0;
}
.modal-close:hover { color: var(--text); }

/* ---------- Strategy tabs（保留兼容） ---------- */
.strat-tab { transition: all 0.2s; }
.strat-tab:hover { border-color: var(--primary); }
.strat-tab-active { border-color: var(--primary) !important; }

/* ---------- Navbar 小屏可滚动 ---------- */
.navbar .nav-right { flex-wrap: nowrap; overflow-x: auto; }
.navbar .nav-right::-webkit-scrollbar { display: none; }

/* 全局滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* 可见键盘聚焦 */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .main { padding: 16px 14px 32px; }
  .navbar { padding: 0 12px; }
}

/* ---------- 尊重减弱动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
