/* ============================================================
   CryptoTools — app.css
   自定义样式：覆盖 Tabler 局部样式 + 专用组件
   ============================================================ */

/* ── CSS 变量（深色/浅色主题适配） ────────────────────────── */
:root,
[data-bs-theme="light"] {
  --ct-chart-bg:       #f8fafc;
  --ct-ticker-bg:      #f1f5f9;
  --ct-sidebar-bg:     #f8fafc;
  --ct-sidebar-tab-bg: #f1f5f9;
  --ct-card-hover:     #e2e8f0;
  --ct-up-color:       #22c55e;
  --ct-down-color:     #ef4444;
  --ct-resize-bg:      #e2e8f0;
  --ct-strategy-bg:    #f8fafc;
}

[data-bs-theme="dark"] {
  --ct-chart-bg:       #060e1a;
  --ct-ticker-bg:      #0f2235;
  --ct-sidebar-bg:     #0b1929;
  --ct-sidebar-tab-bg: #060e1a;
  --ct-card-hover:     #132b47;
  --ct-up-color:       #4ade80;
  --ct-down-color:     #f87171;
  --ct-resize-bg:      #1e293b;
  --ct-strategy-bg:    #0c1c2e;
}

/* ── 全局布局 ──────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
}

.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.page-wrapper {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── 品种信息栏 ─────────────────────────────────────────────── */
.ticker-bar {
  background: var(--ct-ticker-bg);
  flex-shrink: 0;
  min-height: 44px;
}

.ticker-pair {
  color: var(--tblr-primary);
  font-size: 15px !important;
  letter-spacing: 0.3px;
}

.ticker-price {
  font-size: 22px !important;
  font-variant-numeric: tabular-nums;
}

.ticker-change {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ticker-change.up   { color: var(--ct-up-color);   }
.ticker-change.down { color: var(--ct-down-color); }

/* ── 价格涨跌颜色 ───────────────────────────────────────────── */
.price-up   { color: var(--ct-up-color)   !important; }
.price-down { color: var(--ct-down-color) !important; }

/* ── 量化策略工具栏 ─────────────────────────────────────────── */
.strategy-bar,
.strategy-launcher {
  background: var(--ct-strategy-bg);
  flex-shrink: 0;
  font-size: 12px;
}

.strategy-launcher {
  min-height: 34px;
}

.strategy-param {
  padding: 2px 5px !important;
  font-size: 11px !important;
}

/* ── K 线图表区域 ───────────────────────────────────────────── */
#chart-container {
  background: var(--ct-chart-bg);
}

/* 加载遮罩 */
.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ct-chart-bg);
  z-index: 10;
  transition: opacity 0.3s;
}

.chart-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── 底部周期栏 & 行情统计 ─────────────────────────────────── */
.bottom-bar {
  flex-shrink: 0;
  background: var(--ct-ticker-bg);
  font-size: 12px;
}

.interval-btn {
  font-size: 12px !important;
  padding: 2px 10px !important;
  border-radius: 4px !important;
  color: var(--tblr-secondary-color);
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.15s;
}

.interval-btn:hover {
  border-color: var(--tblr-primary);
  color: var(--tblr-primary);
}

.interval-btn.active {
  background: var(--tblr-primary) !important;
  color: #fff !important;
  border-color: var(--tblr-primary) !important;
  font-weight: 600;
}

/* ── 拖拽把手 ──────────────────────────────────────────────── */
#resize-handle {
  width: 6px;
  flex-shrink: 0;
  background: var(--ct-resize-bg);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  user-select: none;
}

#resize-handle:hover,
#resize-handle.dragging {
  background: var(--tblr-primary);
}

.resize-dots {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.resize-dots span {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--tblr-secondary-color);
  display: block;
}

/* ── 侧边栏 ─────────────────────────────────────────────────── */
#sidebar {
  width: 280px;
  min-width: 180px;
  max-width: 480px;
  background: var(--ct-sidebar-bg);
  border-left: 1px solid var(--tblr-border-color);
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.25s ease;
}

#sidebar.is-collapsed {
  width: 0 !important;
  min-width: 0 !important;
  border-left: none;
}

/* Tabs 标签栏 */
.sidebar-tabs {
  background: var(--ct-sidebar-tab-bg);
  flex-shrink: 0;
}

.sidebar-tab {
  background: transparent;
  font-size: 12px;
  border-bottom: 2px solid transparent !important;
  color: var(--tblr-secondary-color);
  transition: color 0.15s, border-color 0.15s;
  cursor: pointer;
}

.sidebar-tab.active {
  color: var(--tblr-primary);
  border-bottom-color: var(--tblr-primary) !important;
  font-weight: 700;
}



/* 侧边栏内容面板 */
.sidebar-panel {
  flex: 1;
  min-height: 0;
}

/* ── 搜索添加栏 ─────────────────────────────────────────────── */
.watchlist-search-bar {
  flex-shrink: 0;
  background: var(--ct-sidebar-bg);
}

/* 搜索候选下拉浮层 */
.symbol-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--tblr-body-bg);
  border: 1px solid var(--tblr-border-color);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 280px;
  overflow-y: auto;
}

.symbol-search-dropdown li {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  border-bottom: 1px solid var(--tblr-border-color-translucent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.12s;
}

.symbol-search-dropdown li:last-child { border-bottom: none; }
.symbol-search-dropdown li:hover,
.symbol-search-dropdown li.active { background: var(--ct-card-hover); }

.symbol-search-dropdown li.in-watchlist {
  opacity: 0.5;
  cursor: default;
}

.symbol-search-dropdown .search-pair { font-weight: 600; color: var(--tblr-primary); }
.symbol-search-dropdown .search-tag  { font-size: 10px; color: var(--tblr-secondary-color); }

/* ── 自选列表条目 ───────────────────────────────────────────── */
.watchlist-container {
  background: var(--ct-sidebar-bg);
}

.watchlist-card {
  padding: 10px 14px;
  border-bottom: 1px solid #1a2e42;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
  background: #0b1929;
}

[data-bs-theme="light"] .watchlist-card {
  background: #f8fafc;
  border-bottom-color: var(--tblr-border-color);
}

.watchlist-card:hover {
  background: #0f2035;
}

[data-bs-theme="light"] .watchlist-card:hover {
  background: #eef2f7;
}

.watchlist-card.active {
  border-left: 3px solid #3b82f6;
  padding-left: 11px;
  background: #132b47;
}

[data-bs-theme="light"] .watchlist-card.active {
  background: #dbeafe;
  border-left-color: var(--tblr-primary);
}

/* 顶行：币种名 + 移除按钮 */
.watchlist-card .wl-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.watchlist-card .wl-name {
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  transition: color 0.12s;
}

[data-bs-theme="light"] .watchlist-card .wl-name {
  color: #334155;
}

/* 选中卡片：名称高亮为蓝色，加小圆点 */
.watchlist-card.active .wl-name {
  color: #93c5fd;
  font-weight: 700;
}

.watchlist-card.active .wl-name::before {
  content: '● ';
  color: #3b82f6;
  font-size: 9px;
  vertical-align: middle;
}

/* 中行：价格 + 涨跌幅 */
.watchlist-card .wl-row-mid {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}

.watchlist-card .wl-price {
  font-size: 14px;
  font-weight: 600;
  color: #f1f5f9;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

[data-bs-theme="light"] .watchlist-card .wl-price {
  color: #0f172a;
}

.watchlist-card .wl-change {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.watchlist-card .wl-change.up   { color: var(--ct-up-color); }
.watchlist-card .wl-change.down { color: var(--ct-down-color); }

/* 底行：历史存储 + 趋势按钮 */
.watchlist-card .wl-row-bot {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: #475569;
}

.watchlist-card .wl-store-label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  margin: 0;
  color: #60a5fa;
}

.watchlist-card .wl-store-chk {
  margin: 0;
  cursor: pointer;
  accent-color: #3b82f6;
  width: 12px;
  height: 12px;
}

.watchlist-card .wl-history-btn {
  background: transparent;
  border: none;
  padding: 0 2px;
  font-size: 11px;
  cursor: pointer;
  color: #60a5fa;
  line-height: 1;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.watchlist-card .wl-history-btn:hover { opacity: 0.75; }

/* 移除按钮：常态半透明，悬停高亮 */
.watchlist-card .wl-remove-btn {
  background: transparent;
  border: none;
  color: #334155;
  font-size: 12px;
  cursor: pointer;
  padding: 1px 3px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}

.watchlist-card:hover .wl-remove-btn { opacity: 1; }
.watchlist-card .wl-remove-btn:hover  { color: var(--ct-down-color); }

/* 价格变化高亮动画 */
@keyframes priceFlashUp {
  0%   { background: rgba(74, 222, 128, 0.35); }
  100% { background: transparent; }
}
@keyframes priceFlashDown {
  0%   { background: rgba(248, 113, 113, 0.35); }
  100% { background: transparent; }
}
.price-flash-up   { animation: priceFlashUp   0.6s ease; }
.price-flash-down { animation: priceFlashDown 0.6s ease; }

/* ── 消息中心列表 ────────────────────────────────────────────── */
.notify-container {
  background: var(--ct-sidebar-bg);
}

.notify-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--tblr-border-color-translucent);
  font-size: 12px;
}

.notify-item .notify-title {
  font-weight: 600;
  margin-bottom: 1px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.notify-item .notify-title-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notify-item .notify-unread-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}
.notify-item .notify-meta  { margin-bottom: 2px; }
.notify-item .notify-time  { color: var(--tblr-secondary-color); font-size: 10px; }
.notify-item .notify-body  { color: var(--tblr-secondary-color); font-size: 11px; }

.notify-item.type-error   { border-left: 3px solid var(--ct-down-color); }
.notify-item.type-warning { border-left: 3px solid #f59e0b; }
.notify-item.type-price   { border-left: 3px solid #a78bfa; }
.notify-item.type-signal  { border-left: 3px solid var(--tblr-primary); }

/* 可点击跳转的消息条目 */
.notify-item-clickable {
  cursor: pointer;
  transition: background 0.15s;
}
.notify-item-clickable:hover {
  background: var(--tblr-active-bg, rgba(255,255,255,0.05));
}
.notify-jump {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  color: #60a5fa;
  user-select: none;
}

/* 消息未读角标 */
.notify-badge {
  font-size: 10px !important;
  min-width: 16px;
  padding: 1px 5px !important;
}

/* ── 侧边栏收起后展开触发条 ─────────────────────────────────── */
#sidebar-expand-strip {
  width: 18px;
  flex-shrink: 0;
  background: var(--ct-sidebar-tab-bg);
  border-left: 1px solid var(--tblr-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--tblr-primary);
  font-size: 18px;
  font-weight: 700;
  transition: background 0.15s;
}

#sidebar-expand-strip:hover { background: var(--ct-card-hover); }

/* ── 页脚 ───────────────────────────────────────────────────── */
.ct-footer.footer {
  padding: 0 !important;
  min-height: 0 !important;
  height: 32px;
  display: flex;
  align-items: center;
  border-top: 1px solid var(--tblr-border-color-translucent);
  flex-shrink: 0;
}

.ct-server-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
}

.ct-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6c757d;
  flex-shrink: 0;
}

.ct-status-dot.connected {
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
  animation: statusPulse 2.5s ease-in-out infinite;
}

.ct-status-dot.disconnected {
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
}

@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25); }
  50%       { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.08); }
}

.ct-status-text {
  color: var(--tblr-secondary-color);
}

.ct-status-text.connected    { color: #22c55e; }
.ct-status-text.disconnected { color: #ef4444; }

/* ── 历史报价模态框 ──────────────────────────────────────────── */
#history-chart-container {
  border: 1px solid var(--tblr-border-color);
  border-radius: 6px;
  overflow: hidden;
  background: var(--ct-chart-bg);
}

/* ── SweetAlert2 深色主题覆盖 ──────────────────────────────── */
[data-bs-theme="dark"] .swal2-popup {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
}

[data-bs-theme="dark"] .swal2-title { color: #f1f5f9; }
[data-bs-theme="dark"] .swal2-html-container { color: #94a3b8; }

.swal2-container.swal2-top-end > .swal2-popup {
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

/* Toast 定位样式 */
.swal2-container.swal2-bottom-end {
  padding: 0 1rem 1rem 0;
}

/* ── 图表工具浮动栏（左上角） ──────────────────────────────── */
#chart-toolbar {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chart-tool-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ct-ticker-bg);
  border: 1px solid var(--tblr-border-color);
  border-radius: 5px;
  cursor: pointer;
  color: var(--tblr-secondary-color);
  transition: all 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.chart-tool-btn:hover {
  border-color: var(--tblr-primary);
  color: var(--tblr-primary);
  background: var(--ct-chart-bg);
}

.chart-tool-btn.active {
  background: var(--tblr-primary) !important;
  border-color: var(--tblr-primary) !important;
  color: #fff !important;
  box-shadow: 0 2px 8px rgba(37,99,235,0.35);
}

/* ── 测量工具浮层 ───────────────────────────────────────────── */
#measure-canvas {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

#measure-tooltip {
  position: absolute;
  z-index: 20;
  background: rgba(37, 99, 235, 0.92);
  color: #fff;
  padding: 7px 12px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.85;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(3px);
}

[data-bs-theme="dark"] #measure-tooltip {
  background: rgba(59, 130, 246, 0.88);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.5);
}

.mtt-diff  { font-weight: 700; }
.mtt-pct   { opacity: 0.88; }
.mtt-price { opacity: 0.68; font-size: 11px; }

/* ── 响应式：小屏幕隐藏侧边栏 ──────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    display: none !important;
  }
  #resize-handle {
    display: none !important;
  }
}

/* ── 滚动条美化（深色模式） ─────────────────────────────────── */
[data-bs-theme="dark"] ::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
[data-bs-theme="dark"] ::-webkit-scrollbar-track  { background: #0b1929; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb  { background: #334155; border-radius: 4px; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #475569; }
