/* ============================================================
   Ai币圈 · 合约行情分析系统 — 设计令牌与基础组件层
   theme.css：设计令牌 / Reset / 排版 / 组件（按钮·表单·弹窗·登录）
   断点策略：360px（手机）/ 768px（平板）/ 1200px（桌面）
   ============================================================ */

/* ---------- 设计令牌：深色（默认） ---------- */
:root {
  /*  surfaces  */
  --bg-primary:      #0b0f18;
  --bg-secondary:    #101724;
  --bg-card:         #141c2c;
  --bg-card-hover:   #1a2436;
  --bg-elevated:     #1b2537;
  --bg-input:        #0e1522;
  --bg-overlay:      rgba(3, 7, 15, .72);

  /*  borders  */
  --border-color:    #243044;
  --border-light:    #1a2434;
  --border-strong:   #33415c;

  /*  text  */
  --text-primary:    #e9eef7;
  --text-secondary:  #97a3b8;
  --text-tertiary:   #5d6b82;

  /*  semantic  */
  --color-long:      #0ecb81;   /* 做多 / 涨 */
  --color-short:     #f6465d;   /* 做空 / 跌 */
  --color-range:     #38bdf8;   /* 震荡 */
  --color-uncertain: #8b94a7;   /* 待确认 */
  --color-warn:      #f0b90b;

  /*  brand  */
  --color-primary:        #6366f1;
  --color-primary-hover:  #818cf8;
  --color-primary-strong: #4f46e5;
  --color-primary-soft:   rgba(99, 102, 241, .15);
  --color-cyan:           #22d3ee;
  --gradient-primary:     linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --gradient-long:        linear-gradient(135deg, #0ecb81 0%, #34d399 100%);
  --gradient-short:       linear-gradient(135deg, #f6465d 0%, #fb7185 100%);

  /*  chart (供 chart.js / backtestUI 读取)  */
  --chart-bg:       #0b0f18;
  --chart-text:     #8b94a7;
  --chart-grid:     #1c2636;
  --chart-border:   #243044;
  --chart-grid-soft:rgba(148, 163, 184, .08);

  /*  elevation  */
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .30);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg:   0 14px 44px rgba(0, 0, 0, .48);
  --shadow-glow: 0 0 0 1px rgba(99, 102, 241, .35), 0 10px 34px rgba(99, 102, 241, .16);

  /*  radii  */
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-full: 999px;

  /*  layout  */
  --header-h: 56px;
  --nav-h:    60px;

  /*  typography  */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", "Courier New", monospace;

  /*  motion  */
  --ease:      cubic-bezier(.4, 0, .2, 1);
  --dur-fast:  140ms;
  --dur-base:  220ms;
  --dur-slow:  320ms;

  color-scheme: dark;
}

/* ---------- 设计令牌：浅色 ---------- */
[data-theme="light"] {
  --bg-primary:      #f3f5f9;
  --bg-secondary:    #ffffff;
  --bg-card:         #ffffff;
  --bg-card-hover:   #f8fafc;
  --bg-elevated:     #ffffff;
  --bg-input:        #f1f5f9;
  --bg-overlay:      rgba(15, 23, 42, .42);

  --border-color:    #e3e9f2;
  --border-light:    #eef2f7;
  --border-strong:   #cbd5e1;

  --text-primary:    #101828;
  --text-secondary:  #475467;
  --text-tertiary:   #98a2b3;

  --color-long:      #067647;
  --color-short:     #d92d20;
  --color-range:     #026aa2;
  --color-uncertain: #667085;
  --color-warn:      #b54708;

  --color-primary:        #4f46e5;
  --color-primary-hover:  #4338ca;
  --color-primary-strong: #4338ca;
  --color-primary-soft:   rgba(79, 70, 229, .10);
  --color-cyan:           #0891b2;

  --chart-bg:       #ffffff;
  --chart-text:     #667085;
  --chart-grid:     #eef2f7;
  --chart-border:   #dde3ec;
  --chart-grid-soft:rgba(16, 24, 40, .06);

  --shadow-sm:   0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md:   0 4px 14px rgba(16, 24, 40, .08);
  --shadow-lg:   0 14px 40px rgba(16, 24, 40, .12);
  --shadow-glow: 0 0 0 1px rgba(79, 70, 229, .22), 0 10px 30px rgba(79, 70, 229, .10);

  color-scheme: light;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--dur-base) var(--ease), color var(--dur-base) var(--ease);
}

img { max-width: 100%; height: auto; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }
ul, ol { list-style: none; }

::selection { background: rgba(99, 102, 241, .32); color: var(--text-primary); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ---------- 排版工具 ---------- */
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- 按钮体系 ---------- */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  background: var(--gradient-primary);
  color: #fff; font-size: 13px; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn-primary:hover { filter: brightness(1.12); box-shadow: var(--shadow-glow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(.98); }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-card-hover); }

.btn-small {
  padding: 5px 12px; font-size: 12px; font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card); color: var(--text-secondary);
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn-small:hover { color: var(--text-primary); border-color: var(--border-strong); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.th-danger { color: var(--color-short); border-color: color-mix(in srgb, var(--color-short) 35%, transparent); }
.th-danger:hover { background: color-mix(in srgb, var(--color-short) 10%, transparent); border-color: var(--color-short); }
.btn-danger { color: var(--color-short); border-color: color-mix(in srgb, var(--color-short) 40%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--color-short) 12%, transparent); border-color: var(--color-short); }
.btn-warning { color: var(--color-warn); border-color: color-mix(in srgb, var(--color-warn) 40%, transparent); }
.btn-warning:hover { background: color-mix(in srgb, var(--color-warn) 12%, transparent); border-color: var(--color-warn); }

/* 策略弹窗专用按钮（保留原类名） */
.btn-reset-default {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  color: var(--color-warn);
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--color-warn) 45%, transparent);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
}
.btn-reset-default:hover { background: color-mix(in srgb, var(--color-warn) 12%, transparent); }
.btn-cancel {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
}
.btn-cancel:hover { color: var(--text-primary); border-color: var(--border-strong); }
.btn-save-apply {
  padding: 8px 18px; font-size: 13px; font-weight: 600;
  color: #fff; background: var(--gradient-primary);
  border: none; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: all var(--dur-fast) var(--ease);
}
.btn-save-apply:hover { filter: brightness(1.12); box-shadow: var(--shadow-glow); }

/* ---------- 表单体系 ---------- */
input[type="text"], input[type="number"], input[type="password"], input[type="file"], select, textarea {
  padding: 8px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
input::placeholder { color: var(--text-tertiary); }
input:disabled { opacity: .5; cursor: not-allowed; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-tertiary) 50%),
                    linear-gradient(135deg, var(--text-tertiary) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
select option { background: var(--bg-elevated); color: var(--text-primary); }

.form-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}
.form-row:last-child { border-bottom: none; }
.form-row > label { flex: 0 0 150px; font-size: 13px; color: var(--text-secondary); }
.form-row input[type="number"], .form-row select { width: 150px; }

.form-group-title {
  margin: 14px 0 6px;
  font-size: 12px; font-weight: 600;
  color: var(--color-primary);
  letter-spacing: .06em;
}
.form-group-title:first-child { margin-top: 0; }

.radio-group { display: flex; gap: 6px; flex-wrap: wrap; }
.radio-option {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 12px; color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.radio-option:hover { border-color: var(--border-strong); color: var(--text-primary); }
.radio-option input { display: none; }
.radio-option:has(input:checked) {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-soft);
}
.radio-option input:checked + span { color: var(--color-primary); font-weight: 600; }

.switch-label {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-secondary);
  cursor: pointer;
  position: relative;
}
.switch-label input { display: none; }
.switch-label::before {
  content: ""; width: 34px; height: 20px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  position: relative;
  transition: background var(--dur-fast) var(--ease);
  flex: none;
}
.switch-label::after {
  content: ""; width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute; left: 3px;
  transform: translateX(0);
  transition: transform var(--dur-fast) var(--ease);
}
.switch-label:has(input:checked)::before { background: var(--color-primary); }
.switch-label:has(input:checked)::after { transform: translateX(14px); }
.switch-label input:checked + span { color: var(--text-primary); }

/* 独立开关（toggle-switch，JS 切换 .active） */
.toggle-switch {
  width: 42px; height: 24px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
  flex: none;
}
.toggle-switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff; border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease);
}
.toggle-switch.active { background: var(--color-primary); }
.toggle-switch.active::after { transform: translateX(18px); }

/* 分段控件（radio-pill-group） */
.radio-pill-group {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}
.radio-pill-group label {
  padding: 5px 14px;
  font-size: 12px; color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.radio-pill-group label input { display: none; }
.radio-pill-group label.active,
.radio-pill-group label:has(input:checked) {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  font-size: 10px; font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  letter-spacing: .02em;
  white-space: nowrap;
}

/* ---------- 空状态 ---------- */
.no-signal, .no-data {
  padding: 28px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.7;
}

/* ---------- 弹层：模态框 ---------- */
.modal {
  position: fixed; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease);
}
.modal.show, .modal[style*="display: flex"], .modal[style*="display:flex"] { opacity: 1; }

.modal-dialog {
  width: 460px; max-width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(12px) scale(.98);
  transition: transform var(--dur-base) var(--ease);
}
.modal[style*="display: flex"] .modal-dialog,
.modal[style*="display:flex"] .modal-dialog { transform: translateY(0) scale(1); }
.modal-wide .modal-dialog { width: 860px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  font-size: 15px; font-weight: 600;
  flex: none;
}
.modal-close {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-tertiary);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
  flex: none;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-card-hover); }
.modal-body { padding: 16px 18px; overflow-y: auto; overscroll-behavior: contain; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  flex: none;
}

/* ---------- Toast ---------- */
.toast, #globalToast {
  position: fixed; top: 76px; left: 50%;
  transform: translateX(-50%);
  padding: 11px 22px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease), transform var(--dur-base) var(--ease);
}

/* ---------- 登录屏 ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  padding: 20px;
}
.login-screen[style*="display: none"] { display: none !important; }
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 60% 45% at 18% 8%, rgba(99, 102, 241, .16), transparent 60%),
    radial-gradient(ellipse 55% 40% at 85% 85%, rgba(34, 211, 238, .10), transparent 60%),
    var(--bg-primary);
}
.login-container { position: relative; width: 100%; max-width: 400px; }
.login-card {
  padding: 34px 32px 26px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}
.login-logo { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }
.login-logo-icon {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  font-size: 24px; font-weight: 700; color: #fff;
  box-shadow: var(--shadow-glow);
  flex: none;
}
.login-brand { display: flex; flex-direction: column; }
.login-title { font-size: 19px; font-weight: 700; letter-spacing: .02em; }
.login-subtitle { font-size: 12px; color: var(--text-tertiary); }
.login-welcome { font-size: 22px; font-weight: 700; margin-bottom: 18px; }
.login-field {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  margin-bottom: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.login-field:focus-within { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.login-field-icon { font-size: 14px; opacity: .65; flex: none; }
.login-field input {
  flex: 1;
  padding: 13px 0;
  background: none; border: none;
  font-size: 14px;
}
.login-field input:focus { outline: none; box-shadow: none; }
.login-error {
  min-height: 18px;
  font-size: 12px;
  color: var(--color-short);
  margin-bottom: 6px;
}
.login-submit {
  width: 100%;
  padding: 13px;
  background: var(--gradient-primary);
  color: #fff;
  font-size: 15px; font-weight: 700;
  border: none; border-radius: var(--radius-md);
  box-shadow: var(--shadow-glow);
  transition: all var(--dur-fast) var(--ease);
}
.login-submit:hover { filter: brightness(1.12); transform: translateY(-1px); }
.login-submit:active { transform: scale(.98); }
.login-switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-tertiary);
}
.login-switch span { color: var(--color-primary); font-weight: 600; cursor: pointer; }
.login-switch span:hover { color: var(--color-primary-hover); text-decoration: underline; }
.login-footer-text {
  margin-top: 18px;
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
}

/* ---------- 通用弹层（signal-popup，simulate.js 动态创建） ---------- */
.signal-popup-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1500;
  padding: 20px;
}
.signal-popup {
  width: 600px; max-width: 92vw;
  max-height: 86vh;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.signal-popup-header {
  display: flex; align-items: center;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px; font-weight: 600;
  flex: none;
}
.signal-popup-body { padding: 16px 18px; overflow-y: auto; }
.signal-popup-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
.signal-popup-body th, .signal-popup-body td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  white-space: nowrap;
}
.signal-popup-body th { color: var(--text-tertiary); font-weight: 600; }

/* ---------- 减弱动效（无障碍） ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
