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

html, body {
  height: 100%;
  background: #0a0f1e;
  color: #e2e8f0;
  font-family: 'PingFang SC', 'Microsoft YaHei', -apple-system, sans-serif;
  overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #111d35; }
::-webkit-scrollbar-thumb { background: #354a6b; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4a6491; }

/* ── Glass card ── */
.card, .glass {
  background: rgba(17, 29, 53, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
}

/* ── Header ── */
#app-header {
  transform: translateZ(0);
  will-change: transform;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(10, 15, 30, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 100;
}

.logo-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #359970, #1d6347);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 16px rgba(53, 153, 112, 0.35);
}

/* ── Tab buttons ── */
.tab-btn {
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #9ca3af;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn:hover { color: #fff; background: rgba(255,255,255,0.05); }
.tab-active {
  color: #fff !important;
  background: linear-gradient(135deg, rgba(35,125,89,0.45), rgba(35,125,89,0.2)) !important;
  border-bottom: 2px solid #35996e;
}

.online-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #58b58c;
}
.member-badge {
  background: rgba(17,29,53,0.7);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  color: #d1d5db;
}

/* ── Main layout ── */
#app-main {
  position: fixed;
  top: 52px; left: 0; right: 0; bottom: 0;
}

.tab-view {
  position: absolute;
  inset: 0;
}

/* ── 交易大厅 两栏布局 ── */
#view-trade, #view-contract {
  display: flex;
  flex-direction: row;
}

/* ── 左栏：聊天面板 ── */
#chat-panel, #contract-chat-panel {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(10, 15, 30, 0.5);
  height: 100%;
}

.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(17,29,53,0.4);
}

.agent-avatar {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #359970, #1d6347);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.agent-dot {
  position: absolute;
  bottom: -1px; right: -1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #58b58c;
  border: 2px solid #0a0f1e;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quick-cmds {
  flex-shrink: 0;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.quick-btn {
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(36, 125, 89, 0.4);
  color: #6ee7b7;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.quick-btn:hover {
  border-color: #358c66;
  background: rgba(35,125,89,0.15);
}

.chat-input-wrap {
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(17,29,53,0.7);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
}
#chat-input, #contract-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 13px;
  color: #e2e8f0;
  line-height: 1.5;
  font-family: inherit;
}
#chat-input::placeholder, #contract-chat-input::placeholder { color: #4b5563; }
.send-btn, #contract-send-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: #247d59;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.send-btn:hover { background: #359970; }

/* ── 右栏：可视化面板 ── */
#viz-panel {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-width: 0;      /* 防止 flex-item 溢出 */
}

/* 欢迎屏 — flex居中 */
#viz-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  text-align: center;
  padding: 40px 20px;
}
/* 动态内容 — 默认不显示，有内容后显示 */
#viz-dynamic {
  display: none;     /* JS 用 style.display 控制，不用 classList.hidden */
}

.welcome-icon {
  width: 80px; height: 80px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(35,125,89,0.3), rgba(35,125,89,0.1));
  border: 1px solid rgba(35,125,89,0.25);
  box-shadow: 0 0 32px rgba(53,153,112,0.2);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}
.welcome-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 420px;
}

/* ── 其他Tab：滚动视图 ── */
.scroll-view { overflow-y: auto; }
.inner-wrap { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ── 通用卡片 ── */
.card {
  padding: 16px;
  background: rgba(17,29,53,0.7);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  transition: transform 0.2s;
}
.card-hover:hover { transform: translateY(-2px); }
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: #d1d5db;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
}

/* ── 图表容器 ── */
.chart-box {
  position: relative;
  height: 180px;
  margin-top: 12px;
}

/* ── 逃逸进度 ── */
.escape-board {
  max-height: 180px;
  overflow-y: auto;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── 聊天气泡 ── */
.msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #247d59, #1d6347);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fff;
  max-width: 82%;
  word-break: break-word;
  line-height: 1.5;
}
.msg-ai-wrap {
  display: flex;
  gap: 8px;
  align-self: flex-start;
  max-width: 90%;
}
.msg-ai-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}
.msg-ai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.msg-ai-bubble {
  background: rgba(17, 29, 53, 0.9);
  border: 1px solid rgba(53, 153, 112, 0.2);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  font-size: 13px;
  color: #d1d5db;
  word-break: break-word;
  line-height: 1.6;
}
.msg-ai-bubble strong { color: #a7f3d0; font-weight: 700; }
.msg-ai-bubble em { color: #93c5fd; }
.msg-ai-bubble code {
  background: rgba(53,153,112,0.15);
  padding: 1px 5px; border-radius: 4px;
  font-size: 0.85em; font-family: monospace;
}

/* 打字动画 */
@keyframes typingBounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}
.typing-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #58b58c;
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* 消息淡入 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-fade { animation: fadeIn 0.3s ease-out; }

/* ── 按钮 ── */
.icon-btn {
  background: none; border: none; cursor: pointer;
  color: #6b7280; font-size: 13px; padding: 4px 8px;
  transition: color 0.2s;
}
.icon-btn:hover { color: #d1d5db; }
.btn-primary {
  flex: 1; padding: 9px 0; border-radius: 8px;
  background: #247d59; border: none; cursor: pointer;
  color: #fff; font-size: 13px; font-weight: 500;
  transition: background 0.2s;
}
.btn-primary:hover { background: #359970; }
.btn-ghost {
  flex: 1; padding: 9px 0; border-radius: 8px;
  background: transparent; border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer; color: #9ca3af; font-size: 13px;
  transition: all 0.2s;
}
.btn-ghost:hover { background: rgba(255,255,255,0.05); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: rgba(13, 21, 41, 0.97);
  border: 1px solid rgba(36,125,89,0.25);
  border-radius: 16px;
  padding: 24px;
  width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

/* ── Form fields ── */
.field-label {
  display: block; font-size: 11px; color: #9ca3af; margin-bottom: 6px;
}
.field-select, .field-input {
  width: 100%; border-radius: 8px; padding: 8px 12px;
  font-size: 13px; color: #e2e8f0; outline: none;
  background: #111d35; border: 1px solid rgba(255,255,255,0.1);
  font-family: inherit;
}
.field-select:focus, .field-input:focus { border-color: #247d59; }

.layer-btn {
  flex: 1; padding: 8px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent; color: #9ca3af;
  font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.layer-btn:hover { border-color: #247d59; color: #fff; }
.layer-active {
  border-color: #247d59 !important;
  background: rgba(35,125,89,0.2) !important;
  color: #fff !important;
}

/* Toggle */
.toggle-on {
  width: 40px; height: 20px; border-radius: 10px;
  background: #247d59; cursor: pointer;
  position: relative; transition: background 0.2s; flex-shrink: 0;
}
.toggle-off { background: #4b5563 !important; }
.toggle-knob-on {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: all 0.2s;
}
.toggle-knob-off { right: auto !important; left: 2px !important; }

/* ── Badges ── */
.badge-red {
  padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
}

/* ── Progress bar ── */
.progress-bg {
  height: 6px; border-radius: 3px;
  background: #111d35; overflow: hidden; flex: 1;
}
.progress-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.4,0,0.2,1);
}

/* ── Sector pill ── */
.sector-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; transition: transform 0.15s;
}
.sector-pill:hover { transform: scale(1.06); }

/* ── Stat card (欢迎页 & 各Tab) ── */
.stat-card {
  background: rgba(17,29,53,0.85);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px; padding: 14px;
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }

/* ── Pulse animation ── */
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font-size: 11px; color: #6b7280; font-weight: 500;
  padding: 8px 10px 6px; text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.data-table th.r { text-align: right; }
.data-table th.c { text-align: center; }
.data-table td {
  font-size: 12px; color: #d1d5db;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table td.r { text-align: right; }
.data-table td.c { text-align: center; }
.mono { font-family: 'Courier New', monospace; font-size: 11px; color: #58b58c; }

/* ── Layer badges ── */
.layer-abs { background: rgba(59,130,246,.18); color: #93c5fd; border: 1px solid rgba(59,130,246,.3); border-radius: 4px; padding: 1px 6px; font-size: 10px; }
.layer-beta { background: rgba(139,92,246,.18); color: #c4b5fd; border: 1px solid rgba(139,92,246,.3); border-radius: 4px; padding: 1px 6px; font-size: 10px; }
.layer-alpha { background: rgba(245,158,11,.18); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); border-radius: 4px; padding: 1px 6px; font-size: 10px; }

/* ── Portfolio viz specific ── */
.viz-section { display: flex; flex-direction: column; gap: 16px; }
