/* ============================================================
 * Reusable Components
 * ============================================================ */

/* ---------- Sidebar ---------- */
.sidebar {
  position: relative;
  z-index: 20;
}
.sidebar.collapsed {
  width: var(--sidebar-w-collapsed) !important;
}
.sidebar.collapsed .sidebar-label {
  opacity: 0;
  width: 0;
  pointer-events: none;
}
.sidebar.collapsed #sidebar-toggle i {
  transform: rotate(180deg);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  position: relative;
  transition: all 0.15s var(--ease-out);
  white-space: nowrap;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.18), rgba(59, 130, 246, 0.02));
  color: var(--brand-bright);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -3px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--brand);
  box-shadow: 0 0 10px var(--brand-glow);
}
.nav-item i {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  padding: 14px 12px 6px;
}
.sidebar.collapsed .nav-section-label {
  text-align: center;
  padding: 14px 0 6px;
  font-size: 0;
}
.sidebar.collapsed .nav-section-label::first-letter {
  font-size: 10px;
}

/* ---------- Market index card ---------- */
.idx-card {
  min-width: 200px;
  flex-shrink: 0;
}
.idx-card .idx-name {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.idx-card .idx-value {
  font-size: 22px;
  font-weight: 600;
  font-family: var(--font-mono);
  margin-top: 6px;
  letter-spacing: -0.02em;
}
.idx-card .idx-change {
  font-size: 12px;
  font-family: var(--font-mono);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.idx-card .idx-spark {
  margin-top: 10px;
  height: 36px;
}

/* ---------- Tag matrix / word cloud ---------- */
.theme-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
  position: relative;
}
.theme-tag:hover {
  border-color: var(--brand);
  color: var(--brand-bright);
  background: var(--brand-soft);
  transform: translateY(-1px);
}
.theme-tag .heat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.theme-tag.size-lg { font-size: 15px; padding: 8px 14px; font-weight: 500; }
.theme-tag.size-md { font-size: 13px; }
.theme-tag.size-sm { font-size: 11px; padding: 4px 10px; opacity: 0.85; }

/* ---------- Heatmap ---------- */
.heatmap {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 64px;
  gap: 4px;
}
.heat-cell {
  position: relative;
  border-radius: 4px;
  padding: 8px 10px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s var(--ease-out), filter 0.15s;
  border: 1px solid transparent;
}
.heat-cell:hover {
  transform: scale(1.03);
  z-index: 2;
  border-color: var(--border-strong);
  filter: brightness(1.15);
}
.heat-cell .name {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.heat-cell .pct {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  align-self: flex-end;
}

/* ---------- Timeline ---------- */
.timeline {
  position: relative;
  padding-left: 20px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding-bottom: 16px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -19px;
  top: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 2px solid var(--border-strong);
}
.timeline-item.level-high::before {
  border-color: var(--up);
  box-shadow: 0 0 8px var(--up-glow);
}
.timeline-item.level-warn::before {
  border-color: var(--warn);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}
.timeline-item.level-info::before {
  border-color: var(--brand);
  box-shadow: 0 0 8px var(--brand-glow);
}
.timeline-item .t-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
.timeline-item .t-title {
  font-size: 13px;
  color: var(--text-primary);
  margin-top: 2px;
  line-height: 1.45;
}
.timeline-item .t-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---------- Chat ---------- */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100%;
  background: var(--bg-base);
}
.chat-sessions {
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  overflow-y: auto;
}
.chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}
.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: msgIn 0.3s var(--ease-out);
}
.msg.user {
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.msg.agent .msg-avatar {
  background: linear-gradient(135deg, var(--info), var(--brand));
  color: #fff;
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.35);
}
.msg.user .msg-avatar {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.msg-bubble {
  max-width: 760px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.65;
}
.msg.agent .msg-bubble {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-top-left-radius: 3px;
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--brand), #2563eb);
  color: #fff;
  border-top-right-radius: 3px;
}

/* Agent thinking block */
.thinking {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(10, 14, 23, 0.5);
}
.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  background: var(--bg-hover);
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
}
.thinking-header:hover {
  color: var(--text-primary);
}
.thinking-header .chev {
  transition: transform 0.2s;
}
.thinking.open .thinking-header .chev {
  transform: rotate(90deg);
}
.thinking-body {
  padding: 8px 12px 12px;
  display: none;
}
.thinking.open .thinking-body {
  display: block;
}
.tool-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 12px;
  border-bottom: 1px dashed var(--border);
  opacity: 0;
  transform: translateY(4px);
  animation: toolIn 0.3s var(--ease-out) forwards;
}
.tool-row:last-child { border-bottom: none; }
.tool-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  flex-shrink: 0;
}
.tool-name {
  color: var(--text-primary);
  font-weight: 500;
  min-width: 110px;
}
.tool-result {
  color: var(--text-secondary);
  flex: 1;
}
.tool-status {
  margin-left: auto;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tool-status.running { color: var(--warn); }
.tool-status.done { color: var(--success); }
.tool-status .spinner {
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--warn);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.tool-status i { width: 13px; height: 13px; }

/* Chat input */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 14px 24px 18px;
  background: var(--bg-panel);
}
.quick-questions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.qq-btn {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 16px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all 0.15s;
}
.qq-btn:hover {
  border-color: var(--brand);
  color: var(--brand-bright);
  background: var(--brand-soft);
}
.chat-input-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input-wrap:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.chat-input-wrap textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  resize: none;
  max-height: 140px;
  line-height: 1.5;
  padding: 6px 0;
}
.chat-input-wrap textarea::placeholder {
  color: var(--text-muted);
}

/* ---------- Stock card inside chat ---------- */
.stock-card-inline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 10px 0;
  border: 1px solid var(--border);
}
.stock-card-inline .sc-cell {
  background: var(--bg-panel);
  padding: 10px 12px;
}
.stock-card-inline .sc-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.stock-card-inline .sc-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  margin-top: 3px;
}

/* ---------- Theme card ---------- */
.theme-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  transition: all 0.2s var(--ease-out);
  position: relative;
  overflow: hidden;
}
.theme-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brand), var(--info), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}
.theme-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}
.theme-card:hover::before { opacity: 1; }

.heat-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-hover);
  overflow: hidden;
  margin-top: 8px;
}
.heat-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--brand), var(--info));
  transition: width 0.8s var(--ease-out);
  box-shadow: 0 0 8px var(--brand-glow);
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 9px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  position: relative;
  top: 1px;
}
.tab:hover {
  color: var(--text-primary);
}
.tab.active {
  color: var(--brand-bright);
  border-bottom-color: var(--brand);
}

/* ---------- Table ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.data-table tbody tr {
  transition: background 0.12s;
}
.data-table tbody tr:hover {
  background: var(--bg-hover);
}
.data-table .num {
  text-align: right;
  font-family: var(--font-mono);
}
.data-table th.num { text-align: right; }

/* Position bar (in portfolio) */
.pos-bar {
  width: 80px;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}
.pos-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--brand-bright));
  border-radius: 2px;
}

/* ---------- K-line (SVG container) ---------- */
.kline-wrap {
  width: 100%;
  height: 320px;
  position: relative;
}
.kline-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Watch list / sidebar in research ---------- */
.watch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}
.watch-item:hover {
  background: var(--bg-hover);
}
.watch-item.active {
  background: var(--brand-soft);
  border-color: rgba(59, 130, 246, 0.3);
}
.watch-item .w-name {
  font-size: 13px;
  font-weight: 500;
}
.watch-item .w-code {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.watch-item .w-price {
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
}

/* ---------- Alert feed ---------- */
.alert-item {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  cursor: pointer;
}
.alert-item:hover {
  background: var(--bg-hover);
}
.alert-item.is-read {
  opacity: 0.55;
}
.alert-item.is-read:hover {
  opacity: 0.8;
}
.alert-target {
  transition: opacity 0.12s;
}
.alert-target:hover {
  opacity: 0.8;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chain-clickable {
  transition: all 0.15s var(--ease-out);
}
.chain-clickable:hover {
  transform: translateY(-2px);
  border-color: var(--brand) !important;
  box-shadow: 0 0 12px rgba(59,130,246,0.35);
}
.alert-indicator {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}
.alert-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  min-width: 54px;
  padding-top: 1px;
}
.alert-body {
  flex: 1;
  min-width: 0;
}
.alert-title {
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.alert-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.5;
}

/* Filter pills */
.filter-pills {
  display: flex;
  gap: 6px;
}
.pill {
  padding: 5px 13px;
  font-size: 12px;
  border-radius: 14px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover { color: var(--text-primary); }
.pill.active {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-bright);
}

/* Relation graph (simple SVG) */
.relation-graph {
  width: 100%;
  height: 280px;
}

/* Chain nodes */
.chain-node {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  font-size: 12px;
  color: var(--text-primary);
}
.chain-node.primary {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-bright);
}
.chain-arrow {
  color: var(--text-muted);
  font-size: 16px;
}
