/* ═══════════════════════════════════════════════════════════
   台股雷達 — Dark Terminal / Radar Design System
   ═══════════════════════════════════════════════════════════ */

/* ── Design tokens ───────────────────────────────────────── */
:root {
  --bg-base:      #030509;
  --bg-surface:   rgba(14, 18, 27, 0.6);
  --bg-elevated:  rgba(22, 28, 45, 0.7);
  --bg-hover:     rgba(255, 255, 255, 0.05);
  --bg-gradient:  linear-gradient(145deg, rgba(30, 41, 59, 0.3) 0%, rgba(15, 23, 42, 0.6) 100%);
  --border:       rgba(255, 255, 255, 0.05);
  --border-bright:rgba(255, 255, 255, 0.15);
  --card-glow:    inset 0 1px 1px rgba(255, 255, 255, 0.05), 0 8px 32px rgba(0, 0, 0, 0.4);
  --hover-glow:   inset 0 1px 1px rgba(255, 255, 255, 0.1), 0 8px 32px rgba(77, 143, 255, 0.2);

  --green:        #00ffb3;
  --green-dim:    #00cc8f;
  --red:          #ff4d6d;
  --red-dim:      #d92646;
  --blue:         #5c9aff;
  --blue-dim:     #3373e6;
  --gold:         #ffd050;
  --purple:       #b399ff;

  --text-1: #ffffff;
  --text-2: #a1a9c3;
  --text-3: #636e8e;

  --mono: 'IBM Plex Mono', monospace;
  --sans: 'Outfit', sans-serif;

  --header-h: 60px;
  --sidebar-w: 240px;
  --mobile-tab-h: 56px;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background: var(--bg-base);
  color: var(--text-1);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  transition: background 0.25s, color 0.25s;
}

body.mobile-nav-open { overflow: hidden; }

a { text-decoration: none; color: inherit; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--blue-dim); }

/* ── Animations ──────────────────────────────────────────── */
@keyframes fade-in-up {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-glow {
  0% { text-shadow: 0 0 4px rgba(var(--text-glow-color), 0.3); }
  50% { text-shadow: 0 0 12px rgba(var(--text-glow-color), 0.8); }
  100% { text-shadow: 0 0 4px rgba(var(--text-glow-color), 0.3); }
}

/* ═══════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════ */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: rgba(8,11,18,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.header-logo-icon { font-size: 1.2rem; }
.header-logo-text {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: var(--text-1);
  white-space: nowrap;
}

.header-nav {
  display: flex;
  gap: 4px;
}
.header-nav-item {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.header-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-1);
}

.header-spacer { flex: 1; }

.header-time {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Mobile menu button (hidden on desktop) ─────────────── */
.btn-mobile-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  margin-right: 4px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-1);
  transition: background 0.15s, border-color 0.15s;
}
.btn-mobile-menu:hover { background: var(--bg-hover); }
.mobile-menu-icon {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}
.mobile-menu-icon::before,
.mobile-menu-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.2s, top 0.2s, opacity 0.2s;
}
.mobile-menu-icon::before { top: -6px; }
.mobile-menu-icon::after  { top:  6px; }
body.mobile-nav-open .mobile-menu-icon { background: transparent; }
body.mobile-nav-open .mobile-menu-icon::before {
  top: 0;
  transform: rotate(45deg);
}
body.mobile-nav-open .mobile-menu-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

.sidebar-backdrop {
  display: none;
}

/* ── Mobile bottom tab bar (hidden on desktop) ──────────── */
.mobile-tab-bar {
  display: none;
}

/* ── Main grid ───────────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-group { margin-bottom: 8px; }

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 6px 12px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s, transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-1);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.sidebar-item.active {
  background: rgba(77,143,255,0.12);
  color: var(--blue);
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  background: var(--blue);
  border-radius: 0 2px 2px 0;
}

.sidebar-icon { font-size: 1rem; flex-shrink: 0; }
.sidebar-label { flex: 1; }
.sidebar-badge {
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--blue-dim);
  color: #fff;
  border-radius: 8px;
  padding: 1px 6px;
  min-width: 20px;
  text-align: center;
  display: none;
}
.sidebar-badge:not(:empty) { display: inline-block; }

/* ── Content area ────────────────────────────────────────── */
.content {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ═══════════════════════════════════════════════════════════
   CARDS & SECTION HEADERS
   ═══════════════════════════════════════════════════════════ */

.card {
  background: var(--bg-gradient);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;  /* 不讓 flex-column 壓縮卡片高度 */
  box-shadow: var(--card-glow);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s, border-color 0.25s;
  animation: fade-in-up 0.5s ease-out forwards;
  opacity: 0;
}
.card:hover {
  box-shadow: var(--hover-glow);
  border-color: rgba(99, 120, 180, 0.4);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 22, 36, 0.6);
  flex-wrap: wrap;
}

.section-title-accent {
  width: 3px;
  height: 18px;
  background: linear-gradient(180deg, var(--blue) 0%, var(--purple) 100%);
  border-radius: 2px;
  flex-shrink: 0;
}

.section-title {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-1);
  letter-spacing: 0.02em;
}

.section-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-3);
  white-space: nowrap;
}

.section-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════════
   INPUTS & SELECTS (controls)
   ═══════════════════════════════════════════════════════════ */

.ctrl-input,
.ctrl-select,
.section-controls input,
.section-controls select {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 0.85rem;
  font-family: inherit;
  padding: 8px 14px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}
.ctrl-input:focus,
.ctrl-select:focus,
.section-controls input:focus,
.section-controls select:focus {
  border-color: var(--blue);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 3px rgba(92, 154, 255, 0.2);
}
.ctrl-input::placeholder { color: var(--text-3); }

/* ═══════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════ */

.btn-primary {
  background: var(--blue-dim);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}
.btn-primary:hover:not(:disabled) { 
  background: var(--blue);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(92, 154, 255, 0.4);
}
.btn-primary:active:not(:disabled) { transform: scale(0.96); }
.btn-primary:disabled { opacity: 0.45; cursor: default; }

.btn-secondary {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 18px;
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}
.btn-secondary:active:not(:disabled) { transform: scale(0.96); }
.btn-secondary:disabled { opacity: 0.45; cursor: default; }

.btn-danger {
  background: rgba(255,64,96,0.15);
  color: var(--red);
  border: 1px solid rgba(255,64,96,0.3);
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(255,64,96,0.28); }

.btn-edit {
  background: rgba(77,143,255,0.12);
  color: var(--blue);
  border: 1px solid rgba(77,143,255,0.3);
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-edit:hover { background: rgba(77,143,255,0.22); }

.btn-warning {
  background: rgba(245,200,66,0.12);
  color: var(--gold);
  border: 1px solid rgba(245,200,66,0.3);
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-warning:hover { background: rgba(245,200,66,0.22); }

.btn-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-3);
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.btn-close:hover { color: var(--text-1); background: var(--bg-hover); }

.btn-nav {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-bright);
  border-radius: 4px;
  color: var(--text-2);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 10px;
  transition: background 0.15s;
}
.btn-nav:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-1); }
.btn-nav:disabled { opacity: 0.3; cursor: default; }

/* ═══════════════════════════════════════════════════════════
   UTILITY
   ═══════════════════════════════════════════════════════════ */

.hidden { display: none !important; }

.loading {
  text-align: center;
  padding: 24px;
  color: var(--text-3);
  font-size: 0.88rem;
  font-family: var(--mono);
}

.empty-msg {
  text-align: center;
  padding: 40px;
  color: var(--text-3);
  font-size: 0.88rem;
}

.update-time-hint {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-3);
  white-space: nowrap;
}

.symbol-link {
  cursor: pointer;
  color: var(--blue);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  transition: color 0.15s;
}
.symbol-link:hover { color: var(--green); }

/* ═══════════════════════════════════════════════════════════
   INDEX TILES (美股四大指數)
   ═══════════════════════════════════════════════════════════ */

.indices-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 16px 20px;
}

.index-card {
  padding: 16px;
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: background 0.15s;
  border-radius: 6px;
}
.index-card:last-child { border-right: none; }
.index-card:hover { background: var(--bg-hover); }

.index-name {
  font-size: 0.8rem;
  color: var(--text-2);
  margin-bottom: 2px;
}
.index-symbol {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-3);
  margin-bottom: 8px;
}
.index-close {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}
.index-change {
  font-family: var(--mono);
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.index-pct {
  font-size: 0.78rem;
  opacity: 0.85;
}
.index-up   { color: var(--red); font-weight: 800; text-shadow: 0 0 8px rgba(255, 77, 109, 0.4); }   /* 台股慣例：漲紅跌綠 */
.index-down { color: var(--green); font-weight: 800; text-shadow: 0 0 8px rgba(0, 255, 179, 0.4); }
.index-date {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-3);
  margin-top: 6px;
}

/* ═══════════════════════════════════════════════════════════
   MACRO INDICATORS
   ═══════════════════════════════════════════════════════════ */

.macro-group {
  padding: 10px 20px 6px;
  border-bottom: 1px solid var(--border);
}
.macro-group:last-child { border-bottom: none; }

.macro-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.macro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0;
}

.macro-card {
  border-right: 1px solid var(--border);
}
.macro-card:last-child { border-right: none; }

.macro-close { font-size: 1.2rem !important; }

/* VIX label badges */
.macro-label {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 0.66rem;
  font-weight: 700;
  margin: 2px 0;
}
.macro-label-optimistic { background: rgba(0,229,160,0.15); color: var(--green); }
.macro-label-neutral    { background: rgba(136,146,170,0.15); color: var(--text-2); }
.macro-label-caution    { background: rgba(245,200,66,0.15); color: var(--gold); }
.macro-label-panic      { background: rgba(255,64,96,0.15); color: var(--red); }
.macro-label-positive   { background: rgba(0,229,160,0.15); color: var(--green); }
.macro-label-inverted   { background: rgba(255,64,96,0.15); color: var(--red); }

/* ═══════════════════════════════════════════════════════════
   CHIP GRID (台股籌碼)
   ═══════════════════════════════════════════════════════════ */

.macro-chip-date {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-3);
  font-weight: 400;
  margin-left: 6px;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 4px 0;
}

.chip-card {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.chip-card:last-child { border-right: none; }
.chip-card:hover { background: var(--bg-hover); }

.chip-label {
  font-size: 0.74rem;
  color: var(--text-2);
  margin-bottom: 4px;
}
.chip-value {
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 2px;
}
.chip-sub {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-2);
}

.chip-positive { color: var(--red); }    /* 買超 = 紅（台股慣例） */
.chip-negative { color: var(--green); }  /* 賣超 = 綠 */
.chip-neutral  { color: var(--text-1); }

/* ═══════════════════════════════════════════════════════════
   RECOMMENDATION TABS
   ═══════════════════════════════════════════════════════════ */

.rec-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.rec-tab-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px 6px 0 0;
  background: var(--bg-elevated);
  color: var(--text-2);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: background 0.15s, color 0.15s;
}
.rec-tab-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.rec-tab-btn.active {
  background: var(--bg-surface);
  color: var(--blue);
  border-bottom-color: var(--blue);
  font-weight: 700;
}

.rec-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-dim);
  color: #fff;
  border-radius: 10px;
  font-size: 0.68rem;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
}
.rec-tab-btn.active .rec-tab-badge { background: var(--red-dim); }

.rec-tab-panel { display: none; }
.rec-tab-panel.active { display: block; }
.rec-tab-content { padding: 0; }

.ai-highlight {
  padding: 8px 16px;
  background: rgba(245,200,66,0.06);
  color: var(--gold);
  font-size: 0.8rem;
  font-weight: 600;
  border-left: 3px solid var(--gold);
}
.ai-section-divider {
  padding: 6px 16px;
  background: var(--bg-elevated);
  color: var(--text-3);
  font-size: 0.76rem;
  border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════
   DATA TABLE
   ═══════════════════════════════════════════════════════════ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.data-table th {
  background: rgba(255, 255, 255, 0.02);
  padding: 12px 16px;
  text-align: left;
  font-weight: 700;
  color: var(--text-2);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.data-table tbody tr {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  color: var(--text-1);
}
.data-table tbody tr:hover { 
  background: rgba(255, 255, 255, 0.04); 
}
.data-table tbody tr:last-child td { border-bottom: none; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* signal badges */
.signal-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.74rem;
  font-weight: 700;
  font-family: var(--mono);
}
.signal-BUY   { background: rgba(255,64,96,0.15);  color: var(--red); }
.signal-SELL  { background: rgba(0,229,160,0.15);  color: var(--green); }
.signal-WATCH { background: rgba(245,200,66,0.15); color: var(--gold); }

/* watchlist tag in recommendations */
.watchlist-tag {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(245,200,66,0.18);
  color: var(--gold);
  vertical-align: middle;
}
.rec-watchlist-filter {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.rec-watchlist-filter input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--gold);
}

/* condition badges in watchlist */
.condition-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  background: rgba(77,143,255,0.12);
  color: var(--blue);
}
.note-with-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.note-text {
  font-size: 0.8rem;
  color: var(--text-2);
}

/* text coloring helpers used by scan */
.text-up   { color: var(--red);   font-weight: 800; text-shadow: 0 0 8px rgba(255, 77, 109, 0.4); }
.text-down { color: var(--green); font-weight: 800; text-shadow: 0 0 8px rgba(0, 255, 179, 0.4); }

/* ═══════════════════════════════════════════════════════════
   WATCHLIST
   ═══════════════════════════════════════════════════════════ */

.watchlist-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px 4px;
  border-bottom: 1px solid var(--border);
}

.watchlist-tabs { margin-bottom: 0; }

.watchlist-quick-add {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.watchlist-footer-actions {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  margin-top: 0;
}
.footer-actions-summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-2);
  user-select: none;
  display: block;
}
.footer-actions-summary:hover {
  background: var(--bg-hover);
  color: var(--text-1);
}
.footer-actions-content {
  padding: 12px 16px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.footer-btns {
  display: flex;
  gap: 8px;
}

/* inline group input inside table */
.group-inline-input {
  background: var(--bg-elevated) !important;
  color: var(--text-1) !important;
  border: 1px solid var(--border-bright) !important;
  border-radius: 4px;
  font-size: 0.8rem;
  padding: 2px 6px;
}

.group-tags-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.group-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #2a2a3e;
  border: 1px solid #555;
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 0.78rem;
  color: #ccc;
  white-space: nowrap;
}

.group-tag-remove {
  cursor: pointer;
  color: #888;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 1px;
}

.group-tag-remove:hover {
  color: #f87171;
}

.backtest-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid #444;
}

.backtest-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.backtest-up   { color: #4ade80; }
.backtest-down { color: #f87171; }

.reason-cell { min-width: 140px; max-width: 220px; padding: 4px 6px !important; }
.reason-textarea {
  width: 100%;
  min-height: 48px;
  resize: vertical;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: inherit;
  font-size: 0.82rem;
  font-family: inherit;
  padding: 3px 5px;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.reason-textarea:hover  { border-color: var(--border); }
.reason-textarea:focus  { border-color: var(--accent); outline: none; background: var(--bg-card); }

/* ═══════════════════════════════════════════════════════════
   SCAN SECTION
   ═══════════════════════════════════════════════════════════ */

#scan-results { padding: 12px 16px; }

.scan-group {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.scan-group-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elevated);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-1);
  user-select: none;
  list-style: none;
}
.scan-group-summary::-webkit-details-marker { display: none; }
.scan-group-summary::before {
  content: '▶';
  font-size: 0.65rem;
  margin-right: 8px;
  transition: transform 0.2s;
  color: var(--text-3);
}
details[open] > .scan-group-summary::before { transform: rotate(90deg); }
.scan-group-count {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--blue-dim);
  color: #fff;
  border-radius: 10px;
  padding: 2px 10px;
  font-weight: 700;
  min-width: 36px;
  text-align: center;
}
.scan-group-body { padding: 6px 0; }
.scan-empty { margin: 8px 12px; color: var(--text-3); }

/* ═══════════════════════════════════════════════════════════
   CONDITIONS
   ═══════════════════════════════════════════════════════════ */

.condition-card {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.condition-card:last-child { border-bottom: none; }
.condition-card:hover { background: var(--bg-hover); }

.condition-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.condition-name { font-weight: 700; font-size: 0.92rem; color: var(--text-1); }
.condition-meta { color: var(--text-3); font-size: 0.75rem; }
.condition-desc {
  color: var(--text-2);
  font-size: 0.85rem;
  margin: 0 0 8px;
}
.condition-rules { font-size: 0.78rem; color: var(--text-2); }
.condition-actions { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }

.status-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
}
.status-active   { background: rgba(0,229,160,0.12); color: var(--green); }
.status-inactive { background: rgba(74,82,104,0.2);  color: var(--text-3); }

/* ═══════════════════════════════════════════════════════════
   SUPPLY CHAIN
   ═══════════════════════════════════════════════════════════ */

#sc-content { padding: 16px 20px; }

.sc-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.sc-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.sc-card-header {
  background: var(--blue-dim);
  color: #fff;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 7px 12px;
}
.sc-list {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 50px;
}
.sc-list li {
  font-size: 0.84rem;
  color: var(--text-1);
  line-height: 1.5;
  padding-left: 12px;
  position: relative;
}
.sc-list li::before {
  content: '·';
  position: absolute;
  left: 2px;
  color: var(--blue);
  font-weight: 700;
}
.sc-list li.sc-list-empty { color: var(--text-3); padding-left: 0; }
.sc-list li.sc-list-empty::before { display: none; }

.sc-notes-row {
  background: rgba(245,200,66,0.06);
  border: 1px solid rgba(245,200,66,0.2);
  border-radius: 7px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 0.84rem;
  color: var(--text-1);
  line-height: 1.6;
}
.sc-notes-label { font-weight: 700; margin-right: 8px; color: var(--gold); }
.sc-footer { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding-top: 4px; }

/* ═══════════════════════════════════════════════════════════
   FUNDAMENTAL TABS
   ═══════════════════════════════════════════════════════════ */

#fundamental-content { padding: 16px 20px; }

.fundamental-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
  background: var(--bg-elevated);
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.fundamental-tabs::-webkit-scrollbar { display: none; }
.fundamental-tab {
  flex: 1;
  min-width: 90px;
  text-align: center;
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}
.fundamental-tab.active {
  background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
}
.fundamental-tab:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-1);
}

.fundamental-metric { font-size: 0.78rem; padding: 2px 6px; border-radius: 3px; white-space: nowrap; }

/* Color badging (Taiwan conventions: Red = Up, Green = Down) */
.badge { 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.5rem; 
  border-radius: 6px; 
  font-size: 0.75rem; 
  font-weight: 700; 
  letter-spacing: 0.02em; 
}
.badge.up { background: rgba(239, 68, 68, 0.15); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.25); }
.badge.down { background: rgba(16, 185, 129, 0.15); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.25); }
.badge.na { background: var(--bg-hover); color: var(--text-3); border: 1px solid var(--border); }
.fundamental-up { color: #ef4444; font-weight: 600; }
.fundamental-down { color: #10b981; font-weight: 600; }
.fundamental-na { color: var(--text-3); }

/* Profile card */
.profile-card { padding: 4px 0 12px; }
.profile-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.profile-meta-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.profile-meta-row:hover {
  transform: translateY(-2px);
  border-color: #7c3aed;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.15);
}
.profile-meta-key { font-size: 0.75rem; color: #7c3aed; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.profile-meta-val { font-size: 1.05rem; font-weight: 700; color: var(--text-1); }
.profile-desc {
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-2);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.profile-sync-time { font-size: 0.75rem; color: var(--text-muted); text-align: right; }

/* Chain tab */
.chain-section-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-2);
  margin: 0 0 10px;
  letter-spacing: 0.02em;
}
.chain-rel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.chain-rel-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.chain-rel-header {
  background: var(--green-dim);
  color: var(--bg-base);
  font-size: 0.84rem;
  font-weight: 700;
  padding: 7px 12px;
}

/* Valuation */
.valuation-snapshot {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 4px;
}
.valuation-snapshot-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 10px;
}
.valuation-snapshot-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
}
.vsn-item { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.vsn-label { font-size: 0.72rem; color: var(--text-2); margin-bottom: 2px; }
.vsn-val { font-family: var(--mono); font-size: 1rem; font-weight: 600; color: var(--text-1); }

/* ═══════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════ */

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(8,11,18,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: 12px;
  width: 90%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-1);
}
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* form inside modal */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-2);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  font-size: 0.84rem;
  font-family: inherit;
  color: var(--text-1);
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--blue); }
.form-group textarea {
  font-family: var(--mono);
  font-size: 0.78rem;
  resize: vertical;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.field-reference {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.76rem;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-ref-group {
  display: flex;
  gap: 8px;
  line-height: 1.6;
}
.field-ref-label {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text-1);
  min-width: 110px;
}
.field-ref-freq {
  font-weight: 400;
  color: var(--text-2);
  font-size: 0.72rem;
}
.field-ref-keys {
  color: var(--text-2);
}

/* ═══════════════════════════════════════════════════════════
   CHART MODAL
   ═══════════════════════════════════════════════════════════ */

.chart-modal-content {
  width: 92%;
  max-width: 960px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chart-modal-title h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-1);
  font-family: var(--mono);
}
.chart-subtitle {
  font-size: 0.82rem;
  color: var(--text-2);
}
.chart-header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chart-range-btns, .chart-interval-btns {
  display: flex;
  gap: 2px;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px;
  border-radius: 8px;
}
.chart-range-btn, .chart-interval-btn {
  background: transparent;
  color: var(--text-3);
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--mono);
  transition: all 0.2s ease;
}
.chart-range-btn:hover:not(.active),
.chart-interval-btn:hover:not(.active) {
  color: var(--text-1);
}
.chart-range-btn.active, .chart-interval-btn.active {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.chart-modal-body {
  padding: 14px 18px 18px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: #0e1220;
  border-radius: 0 0 12px 12px;
}

.chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 460px;
  color: var(--text-3);
  font-size: 0.9rem;
  font-family: var(--mono);
}
.chart-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 460px;
  color: var(--red);
  font-size: 0.88rem;
}
.chart-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Chart legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 5px 8px;
  background: var(--bg-elevated);
  font-size: 0.75rem;
  color: var(--text-2);
  border-radius: 4px 4px 0 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-line {
  display: inline-block;
  width: 20px;
  height: 2px;
}
.legend-dashed {
  height: 0;
  border-top: 2px dashed;
  background: transparent;
}
.legend-dotted {
  height: 0;
  border-top: 2px dotted;
  background: transparent;
}
.legend-box {
  display: inline-block;
  width: 13px;
  height: 9px;
  border: 1px solid;
  border-radius: 2px;
}
.legend-sep {
  width: 1px;
  background: var(--border);
  align-self: stretch;
}
.legend-toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  user-select: none;
  color: var(--text-2);
}
.legend-toggle:hover { color: var(--text-1); }
.legend-toggle input[type="checkbox"] {
  width: 11px;
  height: 11px;
  cursor: pointer;
  accent-color: var(--blue);
  flex-shrink: 0;
}
.legend-toggle input[type="checkbox"]:not(:checked) + * { opacity: 0.35; }
.legend-toggle input[type="checkbox"]:not(:checked) ~ * { opacity: 0.35; }

#candlestick-chart,
#volume-chart {
  width: 100%;
  border-radius: 0 0 4px 4px;
  overflow: hidden;
}

.vol-chip-tabs {
  display: flex;
  gap: 4px;
  padding: 4px 0 2px;
}
.vol-chip-tab {
  padding: 2px 10px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.vol-chip-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#chip-panel {
  width: 100%;
  overflow: hidden;
}
.chip-sub-tabs {
  display: flex;
  gap: 4px;
  padding: 4px 0 3px;
}
.chip-sub-tab {
  padding: 1px 8px;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chip-sub-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chart-ohlc-info {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 3px 2px 2px;
  min-height: 1.3em;
  letter-spacing: 0.03em;
  color: var(--text-2);
}
.chart-ohlc-info span { margin-right: 4px; }

/* ═══════════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════════ */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  color: var(--text-1);
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 0.84rem;
  z-index: 2000;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.toast.success { background: rgba(0,179,122,0.2); border-color: var(--green-dim); color: var(--green); }
.toast.error   { background: rgba(204,32,64,0.2);  border-color: var(--red-dim);   color: var(--red); }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }

  .btn-mobile-menu { display: flex; }

  .mobile-tab-bar {
    display: flex;
    align-items: stretch;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    height: calc(var(--mobile-tab-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    background: rgba(11, 14, 24, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    min-height: var(--mobile-tab-h);
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.25s, transform 0.25s;
    position: relative;
  }
  .mobile-tab:hover { color: var(--text-2); }
  .mobile-tab.active { 
    color: var(--blue); 
    transform: translateY(-2px) scale(1.05);
  }
  .mobile-tab.active::after {
    content: '';
    position: absolute;
    top: 2px;
    width: 24px;
    height: 3px;
    background: var(--blue);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--blue);
  }
  body.mobile-nav-open .mobile-tab[data-tab="more"] { color: var(--blue); }

  .mobile-tab-icon {
    font-size: 1.2rem;
    line-height: 1;
  }
  .mobile-tab-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
  }

  .content {
    padding-bottom: calc(20px + var(--mobile-tab-h) + var(--safe-bottom));
  }

  .sidebar {
    display: flex;
    position: fixed;
    top: calc(var(--header-h) + var(--safe-top));
    left: 0;
    bottom: 0;
    width: min(280px, calc(100vw - var(--safe-left) - var(--safe-right) - 48px));
    max-width: 85vw;
    z-index: 250;
    transform: translateX(calc(-100% - var(--safe-left)));
    transition: transform 0.25s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    padding-bottom: var(--safe-bottom);
  }
  body.mobile-nav-open .sidebar {
    transform: translateX(var(--safe-left));
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(8, 11, 18, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .sidebar-backdrop:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
  }

  .indices-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding-bottom: 8px;
  }
  .index-card { 
    border: 1px solid var(--border); 
    border-radius: 8px;
  }
  .chip-grid { grid-template-columns: repeat(2, 1fr); }
  .chip-card { border-right: none; border-bottom: 1px solid var(--border); }
  .macro-grid { grid-template-columns: repeat(2, 1fr); }
  .macro-card { border-right: none; border-bottom: 1px solid var(--border); }
  .sc-cards { grid-template-columns: 1fr; }
  .chain-rel-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .chart-modal-content { width: 98%; max-width: none; }
  
  .hide-mobile { display: none !important; }
  .asset-row { padding: 12px; }
  .asset-rank { font-size: 1rem; width: 24px; margin-right: 8px; }
  .asset-info { min-width: 70px; }
  .asset-symbol { font-size: 0.95rem; }
  .asset-metric .val { font-size: 0.85rem; }
  .asset-metric .lbl { font-size: 0.7rem; }
  .asset-action { min-width: 50px; margin-left: 8px; }
  .asset-score { padding: 4px 10px; font-size: 0.8rem; }
  
  /* Fix Chart Header Layout on Mobile */
  .modal-header {
    position: relative;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding-right: 44px; /* Space for absolute close button */
  }
  .modal-header .btn-close {
    position: absolute;
    top: 14px;
    right: 14px;
  }
  .chart-modal-title { 
    flex-direction: row; 
    flex-wrap: wrap;
    gap: 8px; 
    align-items: center; 
  }
  .chart-header-controls { 
    flex-wrap: wrap; 
    width: 100%;
    justify-content: flex-start;
  }
  .section-header { flex-wrap: wrap; }
  .section-controls { margin-left: 0; width: 100%; }
  .section-controls .ctrl-input,
  .section-controls .ctrl-select,
  .section-controls input,
  .section-controls select {
    flex: 1 1 140px;
    min-width: 0;
    max-width: 100%;
  }

  .data-table,
  .strategy-table { min-width: 520px; }
  #rec-tab-content,
  #scan-results,
  #fundamental-content,
  #conditions-list,
  .rec-tab-content,
  .strategy-panel {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #rec-tab-content::-webkit-scrollbar,
  #scan-results::-webkit-scrollbar,
  #fundamental-content::-webkit-scrollbar,
  #conditions-list::-webkit-scrollbar,
  .rec-tab-content::-webkit-scrollbar,
  .strategy-panel::-webkit-scrollbar {
    display: none;
  }

  .macro-signal-card { flex-direction: column; gap: 12px; }
  .graph-layout {
    position: relative;
    height: 65vh;
    height: 65dvh;
    min-height: 0;
  }
  .graph-canvas { height: 100%; min-height: 0; }
  .graph-panel { 
    position: absolute;
    right: 8px; left: 8px; bottom: 8px; top: auto;
    width: auto;
    max-height: 45vh; 
    background: rgba(14, 18, 32, 0.85);
    border: 1px solid var(--border-bright);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(124, 58, 237, 0.2);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 16px;
    z-index: 20;
  }

  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    width: 100%;
    max-width: none;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 24px 24px 0 0;
    margin-bottom: 0;
    position: relative;
    padding-top: 16px;
  }
  .modal-content::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
  }
  .chart-modal-content {
    width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
  #chart-modal,
  #chip-chart-modal { align-items: stretch; padding: 0; }

  .strategy-bubble { max-width: 92%; }
  .strategy-input-bar { flex-wrap: wrap; }
  .strategy-btn-group { flex-direction: row; width: 100%; }
  .btn-strategy-send,
  .btn-strategy-save { flex: 1; min-height: 44px; }

  .toast {
    left: 16px;
    right: 16px;
    bottom: calc(16px + var(--mobile-tab-h) + var(--safe-bottom));
    max-width: none;
  }
}

@media (max-width: 600px) {
  .app { padding-top: var(--safe-top); }
  .content { padding: 12px; padding-bottom: calc(16px + var(--mobile-tab-h) + var(--safe-bottom)); }

  .header {
    gap: 8px;
    padding: 0 calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  }

  .sidebar-item {
    min-height: 44px;
    padding: 10px 12px;
  }
  .header-nav { display: none; }
  .header-time { display: none; }
  #theme-label { display: none; }
  .btn-theme { padding: 6px 10px; min-width: 40px; min-height: 40px; }
  .header-logo-text { font-size: 1rem; }

  .content {
    padding-top: 12px;
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
    padding-bottom: calc(12px + var(--mobile-tab-h) + var(--safe-bottom));
    gap: 12px;
  }

  .section-header { padding: 12px 14px; }
  .section-controls { gap: 6px; }
  .section-controls .btn-primary,
  .section-controls .btn-secondary {
    flex: 1 1 auto;
    min-height: 40px;
  }

  .chip-grid,
  .macro-grid { grid-template-columns: repeat(2, 1fr); }
  .chip-grid { padding: 12px; }

  .watchlist-toolbar { flex-direction: column; align-items: stretch; min-width: 0; width: 100%; overflow: hidden; }
  .watchlist-quick-add {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    width: 100%;
  }
  .watchlist-quick-add .ctrl-input,
  .section-controls .ctrl-input[style],
  #watchlist-search,
  #rec-search {
    width: auto !important;
    max-width: 100%;
    min-height: 44px;
  }
  .watchlist-quick-add .btn-primary {
    width: auto;
    min-height: 44px;
  }
  #add-symbol { order: 1; flex: 2 1 120px; }
  .watchlist-quick-add .btn-primary { order: 2; flex: 1 1 80px; }
  #add-note { order: 3; flex: 1 1 100%; }

  .footer-actions-content {
    flex-direction: column;
    align-items: stretch;
  }
  .footer-btns {
    width: 100%;
  }
  .footer-btns .btn-secondary {
    flex: 1;
    min-height: 44px;
  }
  .hide-mobile { display: none !important; }

  .backtest-ctrl {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 4px;
    gap: 8px;
  }
  .backtest-ctrl .ctrl-input { flex: 1 1 130px; width: auto !important; min-height: 44px; }
  .backtest-ctrl .btn-secondary { flex: 1 1 auto; width: auto; padding: 0 12px; min-height: 44px; }

  .data-table { min-width: 640px; font-size: 0.8rem; }
  .data-table th,
  .data-table td { padding: 8px 10px; }

  .rec-tabs,
  .strategy-tabs,
  .fundamental-tabs,
  .backtest-tabs,
  .vol-chip-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100%; /* Force width to allow scroll */
  }
  .rec-tabs::-webkit-scrollbar,
  .strategy-tabs::-webkit-scrollbar,
  .fundamental-tabs::-webkit-scrollbar,
  .backtest-tabs::-webkit-scrollbar,
  .vol-chip-tabs::-webkit-scrollbar {
    display: none;
  }
  .rec-tab,
  .rec-tab-btn,
  .strategy-tab,
  .fundamental-tab,
  .backtest-tab,
  .vol-chip-tab {
    flex-shrink: 0;
    white-space: nowrap;
    min-height: 44px; /* Improved touch target */
  }

  .chart-loading,
  .chart-error { height: 240px; }
  .chart-range-btns,
  .chart-interval-btns { flex-wrap: wrap; }
  .chart-range-btn,
  .chart-interval-btn { min-height: 44px; padding: 6px 12px; } /* Improved touch target */

  .wiki-controls { flex-wrap: wrap; }
  .wiki-columns { flex-direction: column; }
  .video-session-actions { flex-wrap: wrap; }
  .video-session-actions .btn-open-session,
  .video-session-actions .btn-watch-video { flex: 1; min-height: 44px; }

  .modal-footer {
    flex-wrap: wrap;
    justify-content: stretch;
  }
  .modal-footer .btn-primary,
  .modal-footer .btn-secondary {
    flex: 1;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .header-logo-icon { display: none; }
  .macro-group { padding: 8px 12px 4px; }
  .field-ref-group { flex-direction: column; gap: 4px; }
  .field-ref-label { min-width: 0; }
}

/* ═══════════════════════════════════════════════════════════
   LIGHT MODE
   ═══════════════════════════════════════════════════════════ */

body.light-mode {
  --bg-base:       #f0f3fa;
  --bg-surface:    #ffffff;
  --bg-elevated:   #eaecf5;
  --bg-hover:      #dde1f0;
  --border:        rgba(80,100,180,0.14);
  --border-bright: rgba(80,100,180,0.30);
  --text-1: #111827;
  --text-2: #374558;
  --text-3: #6b7593;

  /* Keep accent colours — they work on light too */
  --green:    #009966;
  --green-dim:#007a52;
  --red:      #d42040;
  --red-dim:  #a81830;
  --blue:     #2563eb;
  --blue-dim: #1d4dc4;
  --gold:     #b45309;
  --purple:   #7c3aed;
}

body.light-mode .header {
  background: rgba(240,243,250,0.92);
  border-bottom-color: var(--border-bright);
}

body.light-mode .mobile-tab-bar {
  background: rgba(240, 243, 250, 0.96);
  border-top-color: var(--border-bright);
}

/* Light mode grid texture stays subtle */
body.light-mode::before {
  opacity: 0.4;
  background-image:
    linear-gradient(rgba(37,99,235,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37,99,235,0.04) 1px, transparent 1px);
}

/* ================= TABLE ================= */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.table-responsive::-webkit-scrollbar { display: none; }

/* ── Theme toggle button ── */
.btn-theme {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: 20px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  font-family: var(--mono);
}
.btn-theme:hover { background: var(--bg-hover); color: var(--text-1); }
.btn-theme .theme-icon { font-size: 1rem; line-height: 1; }

/* ── 市場信號燈 ── */
.macro-signal-card {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  border: 2px solid transparent;
}
.signal-green  { background: rgba(34,197,94,.08);  border-color: rgba(34,197,94,.3);  }
.signal-yellow { background: rgba(234,179,8,.08);  border-color: rgba(234,179,8,.3);  }
.signal-red    { background: rgba(239,68,68,.08);  border-color: rgba(239,68,68,.3);  }

.signal-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  gap: 4px;
}
.signal-light-emoji { font-size: 2.4rem; line-height: 1; }
.signal-light-label { font-size: 0.9rem; font-weight: 700; color: var(--text-1); }
.signal-score       { font-size: 0.78rem; color: var(--text-3); font-family: var(--mono); }

.signal-right { flex: 1; display: flex; flex-direction: column; gap: 8px; }

.signal-position { font-size: 1rem; color: var(--text-1); }
.signal-position strong { font-size: 1.35rem; }
.signal-desc { font-size: 0.8rem; color: var(--text-3); margin-top: -4px; }

details.signal-details {
  margin-top: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
details.signal-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-2);
  font-weight: 500;
  outline: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
details.signal-details summary::marker {
  color: var(--text-3);
}
details.signal-details summary:hover {
  color: var(--text-1);
}
.signal-components { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
.signal-row {
  display: grid;
  grid-template-columns: 160px 80px 56px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}
.signal-row-name   { color: var(--text-2); }
.signal-row-value  { color: var(--text-1); font-family: var(--mono); }
.signal-row-dots   { display: flex; gap: 4px; }
.signal-dot        { width: 10px; height: 10px; border-radius: 50%; }
.signal-dot-on  { background: var(--accent); }
.signal-dot-off { background: var(--border); }
.signal-row-reason { color: var(--text-3); }

.signal-updated { font-size: 0.72rem; color: var(--text-3); font-family: var(--mono); }

@media (max-width: 600px) {
  .signal-row { grid-template-columns: 1fr 60px 48px; }
  .signal-row-reason { display: none; }
}

.chip-chart-legend {
  display: flex;
  gap: 16px;
  padding: 6px 8px 2px;
  font-size: 0.75rem;
  color: var(--text-2);
}
.chip-chart-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.chip-chart-legend-line {
  width: 20px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   研究筆記
   ═══════════════════════════════════════════════════════════ */

.note-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--bg-elevated);
  transition: border-color 0.15s;
}
.note-card:hover { border-color: var(--border-bright); }

.note-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.note-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.note-date {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-1);
  font-family: 'IBM Plex Mono', monospace;
}
.note-source {
  font-size: 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 4px;
  color: var(--text-2);
}
.note-category-badge {
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(96,165,250,0.15);
  color: #60a5fa;
  border: 1px solid rgba(96,165,250,0.3);
}
.note-analyzed-badge {
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(52,211,153,0.15);
  color: #34d399;
  border: 1px solid rgba(52,211,153,0.3);
}
.note-pending-badge {
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(251,191,36,0.12);
  color: #fbbf24;
  border: 1px solid rgba(251,191,36,0.25);
}
.note-card-header { cursor: pointer; user-select: none; }
.note-collapse-chevron {
  font-size: 0.75rem;
  color: var(--text-2);
  width: 12px;
  display: inline-block;
}
.note-card-body.collapsed { display: none; }
.note-card-body { padding-top: 4px; }
.note-card-actions { display: flex; gap: 4px; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.btn-icon:hover { opacity: 1; background: var(--bg-base); }

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}
.note-tag {
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(167,139,250,0.15);
  color: #a78bfa;
  border: 1px solid rgba(167,139,250,0.25);
}
.note-content {
  font-size: 0.84rem;
  color: var(--text-1);
  white-space: pre-wrap;
  line-height: 1.65;
  max-height: 160px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--bg-base);
  border-radius: 6px;
  margin-bottom: 10px;
}

/* Claude 分析結果 */
.note-analysis {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 2px;
}
.analysis-summary {
  font-size: 0.84rem;
  color: var(--text-1);
  font-style: italic;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: rgba(96,165,250,0.08);
  border-left: 3px solid #60a5fa;
  border-radius: 0 4px 4px 0;
}
.analysis-group { margin-bottom: 8px; }
.analysis-group-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.analysis-group ul {
  margin: 0;
  padding-left: 18px;
}
.analysis-group li {
  font-size: 0.82rem;
  color: var(--text-1);
  line-height: 1.6;
}
.note-stock-sym {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  color: #facc15;
}
.btn-tiny {
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid var(--border-bright);
  background: var(--bg-base);
  color: var(--text-2);
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
}
.btn-tiny:hover { color: var(--text-1); border-color: #60a5fa; }

/* 筆記圖片上傳 */
.note-image-upload {
  border: 2px dashed var(--border-bright);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.note-image-upload:hover { border-color: #60a5fa; background: rgba(96,165,250,0.05); }
.note-upload-hint { font-size: 0.82rem; color: var(--text-3); }
.note-image-thumb {
  max-height: 120px;
  max-width: 100%;
  border-radius: 6px;
  object-fit: contain;
}
.note-image-remove {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#note-image-preview-wrap { position: relative; display: inline-block; }

/* 筆記卡片內的截圖 */
.note-image-container {
  margin: 8px 0;
  position: relative;
  display: inline-block;
}
.note-image-full {
  max-height: 160px;
  max-width: 100%;
  border-radius: 6px;
  object-fit: contain;
  cursor: zoom-in;
  transition: max-height 0.25s;
  display: block;
}
.note-image-full.expanded {
  max-height: 600px;
  cursor: zoom-out;
}
.note-image-hint {
  font-size: 0.7rem;
  color: var(--text-3);
  display: block;
  margin-top: 3px;
}

/* ── 策略分析師 ─────────────────────────────────────────── */
.strategy-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: 8px 0 0;
  padding: 0 16px;
}
.strategy-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
}
.strategy-tab.active { color: #a78bfa; border-bottom-color: #7c3aed; }
.strategy-tab:hover:not(.active) { color: var(--text-1); }

.strategy-panel { display: flex; flex-direction: column; }
.strategy-panel.hidden { display: none; }

/* chat panel */
.strategy-messages {
  min-height: 200px;
  max-height: 420px;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.strategy-msg-system {
  background: rgba(124,58,237,0.08);
  border: 1px solid rgba(124,58,237,0.25);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: #c4b5fd;
  line-height: 1.6;
}
.strategy-msg-row { display: flex; gap: 8px; align-items: flex-start; }
.strategy-msg-row.user { flex-direction: row-reverse; }
.strategy-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.strategy-avatar.claude { background: #1a1730; color: #a78bfa; border: 1px solid #2d2060; }
.strategy-avatar.user   { background: #1e3a5f; color: #60a5fa; border: 1px solid #1e4080; }
.strategy-bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.strategy-bubble.claude { background: var(--bg-elevated); border: 1px solid var(--border); border-top-left-radius: 3px; }
.strategy-bubble.user   { background: #1e3255; border: 1px solid #1e4080; color: #bfdbfe; border-top-right-radius: 3px; }
.strategy-loading-bubble { font-size: 0.78rem; color: var(--text-3); font-style: italic; padding: 8px 12px; }

.strategy-input-bar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}
.strategy-textarea {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-1);
  font-size: 0.8rem;
  resize: none;
  height: 52px;
  line-height: 1.5;
  font-family: var(--mono);
}
.strategy-textarea:focus { outline: none; border-color: #4c3ca0; }
.strategy-btn-group { display: flex; flex-direction: column; gap: 5px; }
.btn-strategy-send {
  background: #7c3aed; color: #fff;
  border: none; border-radius: 6px;
  padding: 6px 14px; font-size: 0.76rem; font-weight: 600; cursor: pointer;
}
.btn-strategy-send:hover { background: #6d28d9; }
.btn-strategy-send:disabled { background: var(--bg-elevated); color: var(--text-3); cursor: not-allowed; }
.btn-strategy-save {
  background: var(--bg-elevated); color: #6ee7b7;
  border: 1px solid #065f46; border-radius: 6px;
  padding: 6px 10px; font-size: 0.72rem; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn-strategy-save:hover { background: #065f46; }
.btn-strategy-save:disabled { opacity: 0.4; cursor: not-allowed; }

/* strategies table */
.strategy-table {
  width: 100%; border-collapse: collapse; font-size: 0.78rem;
  margin: 8px 0;
}
.strategy-table th {
  text-align: left; padding: 12px 16px;
  color: var(--text-3); font-weight: 600; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.strategy-table tbody tr { transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.strategy-table td { padding: 12px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.02); vertical-align: top; }
.strategy-table tbody tr:hover td { background: transparent; }
.strategy-table tbody tr:hover { background: rgba(255, 255, 255, 0.04); transform: translateY(-1px); }
.strategy-summary-cell { max-width: 420px; line-height: 1.55; color: var(--text-1); }
.strategy-date-cell { color: var(--text-3); font-size: 0.72rem; white-space: nowrap; }
.tag-pending  { display:inline-flex; align-items:center; padding:4px 10px; border-radius:99px; font-size:0.7rem; font-weight:600; background:rgba(96, 165, 250, 0.15); color:#60a5fa; border:1px solid rgba(96, 165, 250, 0.3); }
.tag-applied  { display:inline-flex; align-items:center; padding:4px 10px; border-radius:99px; font-size:0.7rem; font-weight:600; background:rgba(74, 222, 128, 0.15); color:#4ade80; border:1px solid rgba(74, 222, 128, 0.3); }
.btn-develop  { background:#7c3aed; color:#fff; padding:6px 14px; border-radius:99px; font-size:0.7rem; font-weight:600; cursor:pointer; border:none; transition: all 0.2s; }
.btn-develop:hover { background:#6d28d9; transform: scale(1.05); }

/* ── 影片掃描 ───────────────────────────────────────────── */
.btn-video-scan {
  background: transparent;
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-video-scan:hover { background: rgba(245,158,11,0.1); }
.btn-video-scan:disabled { opacity: 0.4; cursor: not-allowed; }

/* source badge in strategies table */
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.67rem;
  color: #f59e0b;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: 4px;
  padding: 1px 6px;
  margin-top: 3px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-badge a { color: inherit; text-decoration: none; }
.source-badge a:hover { text-decoration: underline; }

/* video session cards */
.video-session-list { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; }
.video-session-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: default;
  transition: border-color 0.15s;
}
.video-session-card:hover { border-color: #4c3ca0; }
.video-session-channel { font-size: 0.7rem; color: #f59e0b; font-weight: 700; margin-bottom: 4px; }
.video-session-title { font-size: 0.82rem; color: var(--text-1); font-weight: 600; line-height: 1.4; margin-bottom: 8px; }
.video-session-actions { display: flex; gap: 8px; }
.btn-open-session {
  background: #7c3aed; color: #fff;
  border: none; border-radius: 5px;
  padding: 5px 12px; font-size: 0.72rem; font-weight: 600; cursor: pointer;
}
.btn-open-session:hover { background: #6d28d9; }
.btn-watch-video {
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 5px 10px; font-size: 0.72rem; cursor: pointer;
}
.btn-watch-video:hover { color: var(--text-1); border-color: var(--text-2); }

/* no-update note in video sessions list */
.video-no-update {
  font-size: 0.78rem;
  color: var(--text-2);
  padding: 10px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── 歷史討論 date grouping ─────────────────────────────── */
.video-history-date {
  font-size: 0.72rem;
  color: var(--text-2);
  font-weight: 700;
  padding: 12px 16px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.video-history-date:first-child { border-top: none; margin-top: 0; }

/* delete button */
.btn-delete-session, .btn-delete-strategy {
  background: transparent;
  color: #6b7280;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 0.72rem;
  cursor: pointer;
  margin-left: auto;
}
.btn-delete-session:hover, .btn-delete-strategy:hover {
  color: #ef4444;
  border-color: #ef4444;
}

/* Watchlist Health styles */
.watchlist-health-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.health-summary-row {
  display: flex;
  gap: 12px;
}
.health-card {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.health-card-title {
  font-size: 0.75rem;
  color: var(--text-3);
  font-weight: 500;
}
.health-card-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-1);
}
.health-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 768px) {
  .health-details-grid {
    grid-template-columns: 1fr;
  }
  .health-summary-row {
    flex-direction: column;
  }
}
.health-section-card {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.01);
  padding: 16px;
  border-radius: 8px;
}
.health-section-card h4 {
  margin: 0 0 12px 0;
  font-size: 0.85rem;
  color: var(--text-2);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.health-stats-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.health-stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}
.health-stat-item > span:first-child {
  width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-2);
}
.health-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-surface);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.health-progress-bar .bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}
.health-progress-bar .bar.info { background: #60a5fa; }
.health-progress-bar .bar.danger { background: #f43f5e; }
.health-progress-bar .bar.success { background: #10b981; }
.health-progress-bar .bar.warning { background: #f59e0b; }
.health-progress-bar .bar.alarm { background: #ec4899; }

.health-stat-count {
  width: 90px;
  text-align: right;
  color: var(--text-3);
  font-size: 0.75rem;
}

.btn-diagnose-send {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
  transition: transform 0.1s, box-shadow 0.15s;
}
.btn-diagnose-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}
.btn-diagnose-send:active {
  transform: translateY(0);
}

/* Wiki double-column in recommendation cards */
.wiki-row td { padding: 0; }
.wiki-columns { display: flex; gap: 1rem; padding: 0.75rem 1rem 1rem; background: var(--bg-elevated); border-top: 1px solid var(--border); }
.wiki-col { flex: 1; }
.wiki-col-label { font-size: 0.75rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; margin-bottom: 0.4rem; letter-spacing: 0.05em; }
.wiki-col-body { font-size: 0.85rem; color: var(--text-1); line-height: 1.6; }

/* Wiki Research page */
.wiki-card { 
  background: var(--bg-surface);
  border: 1px solid var(--border); 
  border-radius: 12px; 
  margin-bottom: 0.75rem; 
  overflow: hidden; 
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.wiki-card:hover {
  transform: translateY(-2px);
  border-color: #7c3aed;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.15);
}
.wiki-card-header { display: flex; align-items: center; gap: 0.75rem; padding: 1rem; flex-wrap: wrap; }
.wiki-entity-key { font-weight: 700; font-size: 1rem; color: var(--text-1); }
.wiki-entity-name { color: var(--text-2); font-size: 0.85rem; }
.wiki-badge { font-size: 0.7rem; padding: 0.2rem 0.6rem; border-radius: 12px; background: rgba(124, 58, 237, 0.2); color: #a78bfa; font-weight: 600; border: 1px solid rgba(124, 58, 237, 0.3); }
.wiki-meta { font-size: 0.75rem; color: var(--text-muted); margin-left: auto; }
.sentiment-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; min-width: 80px; background: var(--bg-hover); }
.wiki-search-input { 
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border); 
  color: var(--text-1);
  border-radius: 20px; 
  padding: 0.4rem 1rem; 
  font-size: 0.9rem;
  transition: all 0.2s;
}
.wiki-search-input:focus { border-color: #7c3aed; box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2); outline: none; }
.wiki-type-btn,
.wiki-sort-btn { 
  border: 1px solid var(--border); 
  background: var(--bg-surface); 
  color: var(--text-2);
  border-radius: 20px; 
  padding: 0.375rem 0.85rem; 
  cursor: pointer; 
  font-size: 0.85rem;
  transition: all 0.2s;
  font-weight: 500;
}
.wiki-type-btn:hover,
.wiki-sort-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.wiki-type-btn.active,
.wiki-sort-btn.active { 
  background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%); 
  color: white; 
  border-color: transparent; 
  box-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}
.wiki-controls-divider {
  display: inline-block;
  width: 1px;
  height: 1.25rem;
  background: var(--border);
  margin: 0 0.25rem;
  vertical-align: middle;
}
.wiki-controls { display: flex; gap: 0.5rem; align-items: center; }

.wiki-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0.25rem;
  font-size: 0.85rem;
  color: var(--text-2);
}
.wiki-pagination.hidden { display: none; }
.wiki-page-btn {
  border: 1px solid var(--border-bright);
  background: var(--bg-elevated);
  color: var(--text-1);
  border-radius: 6px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: var(--sans);
}
.wiki-page-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--blue);
}
.wiki-page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.wiki-page-info {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-3);
  min-width: 10rem;
  text-align: center;
}

/* ── Knowledge Graph ─────────────────────────────────────────── */
.graph-layout {
  display: flex;
  gap: 1rem;
  height: calc(100vh - 160px);
  min-height: 500px;
  position: relative;
}

.graph-canvas {
  flex: 1;
  background: radial-gradient(circle at center, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  border-radius: 12px;
  border: 1px solid var(--border-bright);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.5);
  overflow: hidden;
}

.graph-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.graph-loading {
  animation: graph-pulse 1.2s ease-in-out infinite;
}

@keyframes graph-pulse {
  50% { opacity: 0.45; }
}

.graph-panel {
  width: 280px;
  position: absolute;
  right: 16px;
  top: 16px;
  bottom: 16px;
  z-index: 10;
  background: rgba(14, 18, 32, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-bright);
  border-radius: 12px;
  padding: 1.2rem;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(124, 58, 237, 0.2);
}

.graph-panel h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-1);
  margin: 0 0 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.graph-panel-section { margin-bottom: 1.2rem; }

.graph-panel-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7c3aed;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.graph-panel p {
  font-size: 0.85rem;
  color: var(--text-2);
  line-height: 1.6;
  margin: 0;
}

.filter-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-chip:hover {
  background: var(--bg-hover);
  color: var(--text-1);
}

.filter-chip input[type="checkbox"] { margin: 0; accent-color: #7c3aed; }
.filter-stock:has(input:checked) { border-color: #3b82f6; background: rgba(59, 130, 246, 0.1); color: #60a5fa; }
.filter-channel:has(input:checked) { border-color: #f59e0b; background: rgba(245, 158, 11, 0.1); color: #fbbf24; }
.filter-theme:has(input:checked) { border-color: #10b981; background: rgba(16, 185, 129, 0.1); color: #34d399; }

/* ═══════════════════════════════════════════════════════════
   Backtest Section
   ═══════════════════════════════════════════════════════════ */
.backtest-tabs {
  display: flex;
  gap: 4px;
}
.backtest-tab {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.backtest-tab.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.backtest-tab:disabled {
  opacity: 0.4;
  cursor: default;
}

.backtest-summary {
  display: flex;
  gap: 12px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.backtest-summary-card {
  flex: 1;
  min-width: 160px;
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.backtest-summary-card.green  { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.3); }
.backtest-summary-card.yellow { background: rgba(245,158,11,0.1);  border: 1px solid rgba(245,158,11,0.3); }
.backtest-summary-card.red    { background: rgba(239,68,68,0.1);   border: 1px solid rgba(239,68,68,0.3); }
.bsc-label { font-size: 0.85rem; font-weight: 600; color: var(--text-1); }
.bsc-count { font-size: 0.78rem; font-weight: 400; color: var(--text-3); }
.bsc-stat  { display: flex; align-items: baseline; gap: 4px; }
.bsc-num   { font-size: 1.15rem; font-weight: 700; color: var(--text-1); }
.bsc-unit  { font-size: 0.72rem; color: var(--text-3); }

.backtest-table-wrap {
  overflow-x: auto;
  margin-top: 12px;
}
.backtest-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}
.backtest-table th {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  font-weight: 500;
  white-space: nowrap;
}
.backtest-table th:first-child { text-align: left; }
.backtest-table td {
  text-align: right;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-subtle, #1e293b);
  white-space: nowrap;
}
.backtest-table td:first-child { text-align: left; }
.bt-row-green  td { background: rgba(16,185,129,0.04); }
.bt-row-yellow td { background: rgba(245,158,11,0.04); }
.bt-row-red    td { background: rgba(239,68,68,0.04); }

.pct-pos { color: #10b981; }
.pct-neg { color: #ef4444; }

.error-msg {
  color: #ef4444;
  font-size: 0.85rem;
  padding: 8px 0;
}

/* Backtest charts & pagination */
.backtest-charts {
  margin: 12px 0 4px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.backtest-detail-toggle {
  display: block;
  margin: 14px 0 0;
  font-size: 0.8rem;
  padding: 4px 14px;
}
.bt-pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  padding: 8px 4px;
}
.bt-page-btn {
  min-width: 30px;
  padding: 3px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 0.8rem;
  cursor: pointer;
}
.bt-page-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.bt-page-btn:disabled { opacity: 0.35; cursor: default; }

.wiki-row-card {
  background: rgba(124, 58, 237, 0.05);
  border-radius: 8px;
  padding: 12px;
  margin: 2px 0 12px 16px;
  border-left: 2px solid #7c3aed;
}

/* ================= ASSET LIST (Modern Exchange Style) ================= */
.asset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}
.asset-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.asset-row:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}
.asset-rank {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-3);
  width: 32px;
  text-align: center;
  margin-right: 12px;
}
.asset-info {
  display: flex;
  flex-direction: column;
  min-width: 90px;
}
.asset-symbol {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-1);
}
.asset-name {
  font-size: 0.8rem;
  color: var(--text-2);
  margin-top: 2px;
}
.asset-metrics {
  display: flex;
  flex: 1;
  justify-content: space-around;
  gap: 16px;
}
.asset-metric {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.asset-metric .val {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-1);
}
.asset-metric .lbl {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 2px;
}
.asset-action {
  margin-left: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 60px;
}
.asset-score {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  text-align: center;
}
.asset-score.bg-green {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

/* Watchlist Health Custom Holdings Extensions */
.health-mode-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 0 16px;
}

.btn-mode {
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-mode:hover {
  background: var(--bg-hover);
  color: var(--text-1);
  border-color: var(--border-bright);
}

.btn-mode.active {
  background: rgba(77, 143, 255, 0.15);
  color: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 12px rgba(92, 154, 255, 0.2);
}

.custom-holdings-panel {
  margin: 0 16px 20px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--card-glow);
}

.custom-holdings-input-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.custom-holdings-input-row .form-input {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 0.85rem;
  padding: 8px 14px;
  outline: none;
  transition: all 0.2s;
  flex: 1;
  min-width: 150px;
}

.custom-holdings-input-row .form-input:focus {
  border-color: var(--blue);
  background: rgba(255, 255, 255, 0.05);
}

.custom-holdings-table-container {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.custom-holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.custom-holdings-table th {
  background: rgba(255, 255, 255, 0.03);
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  color: var(--text-2);
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.custom-holdings-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
}

.custom-holdings-table tr:last-child td {
  border-bottom: none;
}

.up {
  color: var(--red) !important;
}

.down {
  color: var(--green) !important;
}
