/* ── Design Tokens: Light / Financial Dashboard ── */
:root {
  --bg:           #f8fafc;
  --bg-card:      #ffffff;
  --bg-card2:     #f1f5f9;
  --bg-hover:     #f1f5f9;
  --border:       #e2e8f0;
  --border2:      #cbd5e1;
  --text:         #0f172a;
  --text-muted:   #334155;
  --text-dim:     #52606d;
  --primary:      #3b82f6;
  --primary-h:    #2563eb;
  --primary-glow: rgba(59,130,246,.10);
  --profit:       #dc2626;
  --loss:         #16a34a;
  --profit-dim:   rgba(220,38,38,.10);
  --loss-dim:     rgba(22,163,74,.10);
  --warn:         #d97706;
  --radius:       10px;
  --radius-sm:    6px;
  --transition:   .15s cubic-bezier(.4,0,.2,1);
  color-scheme:   light;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Fira Sans', -apple-system, 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  min-height: 100dvh;
  zoom: 1.05; /* 全站文字整體放大，因為原本 px 字級太多、太細，逐一調整成本太高 */
}
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Focus & Motion ── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── Cursor & Base Interactive ── */
button, [onclick], .tab, .sum-card, .wl-chip, .wl-chip-del, .wl-ref-btn,
.ai-quick button, .ai-refresh-btn, .ai-news-title, .wl-table tbody tr {
  cursor: pointer;
}
a { color: inherit; }

/* ── Header ── */
.hd {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.hd-logo { display: flex; align-items: center; gap: 10px; }
.hd-icon { color: var(--primary); display: flex; }
.hd-title { font-size: 16px; font-weight: 700; letter-spacing: .3px; }
.hd-sep { color: var(--border2); }
.hd-sub { font-size: 13px; color: var(--text-dim); }
.hd-badge {
  background: var(--primary-glow);
  border: 1px solid rgba(59,130,246,.3);
  color: #1d4ed8;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 20px;
  font-weight: 500;
  box-shadow: 0 0 8px rgba(59,130,246,.12);
}

/* ── Tabs ── */
.tabs {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 13px 15px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: .2px;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  text-decoration: none;
}
.tab:hover { color: var(--text-muted); background: rgba(15,23,42,.04); }
.tab:active { background: rgba(59,130,246,.07); }
.tab.on { border-color: var(--primary); color: var(--primary); }

/* ── Layout ── */
.main {
  padding: 20px;
  width: 90%;
  max-width: 1920px;
  margin: 0 auto;
}
@media (max-width: 768px)  { .main { width: 95%; padding: 14px; } }
@media (max-width: 480px)  { .main { width: 100%; padding: 12px; } }
.panel { display: none; }
.panel.on { display: block; }

/* ── Card ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  transition: border-color var(--transition);
}
.card:last-child { margin-bottom: 0; }
.card:hover { border-color: var(--border2); }
.card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .7px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Form ── */
.fg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.fg label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}
.fg input, .fg select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.fg input:hover:not(:disabled), .fg select:hover:not(:disabled) {
  border-color: #94a3b8;
}
.fg input:focus, .fg select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.fg select option { background: var(--bg-card2); }
.fg input:disabled { opacity: .4; cursor: not-allowed; }

/* ── Buttons ── */
.btn {
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: .2px;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); box-shadow: 0 0 12px rgba(59,130,246,.3); }
.btn-ghost { background: transparent; color: var(--primary); border-color: rgba(59,130,246,.35); }
.btn-ghost:hover { background: var(--primary-glow); border-color: rgba(59,130,246,.6); }
.btn-danger { background: rgba(239,68,68,.1); color: #dc2626; border-color: rgba(239,68,68,.25); }
.btn-danger:hover { background: rgba(239,68,68,.18); border-color: rgba(239,68,68,.45); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Fee preview ── */
.fee-box {
  background: var(--primary-glow);
  border: 1px solid rgba(59,130,246,.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #1d4ed8;
  margin-top: 8px;
  display: none;
  line-height: 1.9;
  animation: fadeSlideIn .2s ease;
}
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.fee-box b { color: #1e40af; font-weight: 600; }

/* ── Summary cards ── */
.sum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.holdings-overview-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 14px;
  align-items: stretch;
  margin-bottom: 14px;
}
.holdings-overview-grid .sum-grid { margin-bottom: 0; }
@media (max-width: 900px) { .holdings-overview-grid { grid-template-columns: 1fr; } }
.sum-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.sum-card:hover { border-color: var(--border2); box-shadow: 0 0 0 1px var(--border2); transform: translateY(-1px); }
.sum-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.sum-val   { font-size: 28px; font-weight: 700; letter-spacing: -.3px; font-family: 'Fira Code', monospace; }
#panel-pnl table { font-size: 15px; }
#panel-pnl .card-title { font-size: 13px; }
#panel-history table { font-size: 15px; }
#panel-history .card-title { font-size: 13px; }
#panel-holdings table { font-size: 15px; }
#panel-holdings .card-title { font-size: 13px; }
.alloc-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
@media (max-width: 1300px) { .alloc-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1000px) { .alloc-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .alloc-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px)  { .alloc-grid { grid-template-columns: 1fr; } }
.alloc-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; transition: border-color var(--transition); }
.alloc-card:hover { border-color: var(--border2); }
.alloc-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.alloc-card-name { font-size: 13px; font-weight: 600; }
.alloc-card-del { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; padding: 0 2px; line-height: 1; }
.alloc-card-del:hover { color: var(--profit); }

/* ── Table ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 13px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--bg);
  border-bottom: 1px solid var(--border2);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .5px;
}
td { padding: 10px 13px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover td { background: var(--bg-hover); }
thead th { cursor: default; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
.sort-arrow { display: inline-block; margin-left: 3px; font-size: 9px; color: var(--text-dim); }
.sort-arrow.active { color: var(--accent, #2563eb); }
.tr { text-align: right; }
.tc { text-align: center; }

/* ── Tags ── */
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; letter-spacing: .2px; }
.tag-buy  { background: var(--profit-dim); color: var(--profit); border: 1px solid rgba(248,113,113,.2); }
.tag-sell { background: var(--loss-dim);   color: var(--loss); border: 1px solid rgba(74,222,128,.2); }
.tag-etf  { background: rgba(59,130,246,.12); color: #1d4ed8; font-size: 10px; border: 1px solid rgba(59,130,246,.2); }
.tag-industry { background: var(--bg-hover); color: var(--text-dim); border: 1px solid var(--border); }

/* ── P&L ── */
.pos { color: var(--profit); font-weight: 700; }
.neg { color: var(--loss);   font-weight: 700; }
.neu { color: var(--text); }

/* ── Misc ── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty { text-align: center; padding: 40px; color: var(--text-dim); font-size: 13px; }

.import-box {
  border: 1px dashed var(--border2);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 12px;
  background: var(--bg);
}
.import-box textarea {
  width: 100%; height: 100px;
  padding: 8px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-family: 'Fira Code', monospace;
  font-size: 12px;
  resize: vertical;
  background: var(--bg-card);
  color: var(--text);
  transition: border-color var(--transition);
}
.import-box textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.px-input {
  width: 80px; padding: 4px 7px;
  border: 1px solid var(--border2);
  border-radius: 4px; font-size: 12px;
  text-align: right; background: var(--bg);
  color: var(--text);
  font-family: 'Fira Code', monospace;
}
.px-input:focus { outline: none; border-color: var(--primary); }

.note { font-size: 13px; color: var(--text-dim); line-height: 1.9; }
.note b    { color: var(--text-muted); }
.note code { font-family: 'Fira Code', monospace; font-size: 11px; background: var(--bg-card2); padding: 1px 5px; border-radius: 3px; color: #0e7490; }

/* ══════════════════════════════════════════
   AI 分析面板
   ══════════════════════════════════════════ */
.ai-search-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.ai-search-row input {
  flex: 0 0 200px; padding: 8px 12px;
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  font-size: 15px; font-family: 'Fira Code', monospace;
  background: var(--bg); color: var(--text); letter-spacing: .5px;
}
.ai-search-row input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.ai-quick { display: flex; gap: 5px; flex-wrap: wrap; }
.ai-quick button {
  padding: 5px 11px; border-radius: 4px;
  border: 1px solid var(--border2); background: transparent;
  color: var(--text-muted); cursor: pointer; font-size: 12px;
  font-family: 'Fira Code', monospace; font-weight: 500;
  transition: all .15s;
}
.ai-quick button:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-glow); }

.ai-stock-hd {
  background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius-sm);
  padding: 12px 16px; display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap; margin-bottom: 14px;
}
.ai-sname  { font-size: 17px; font-weight: 700; }
.ai-price  { font-size: 24px; font-weight: 700; font-family: 'Fira Code', monospace; }
.ai-chg    { font-size: 14px; font-weight: 600; font-family: 'Fira Code', monospace; }
.ai-up     { color: var(--profit); }
.ai-down   { color: var(--loss); }
.ai-meta   { display: flex; gap: 16px; margin-left: auto; flex-wrap: wrap; }
.ai-meta-item  { text-align: right; }
.ai-meta-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.ai-meta-val   { font-size: 14px; font-weight: 600; font-family: 'Fira Code', monospace; }

.ai-main-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; margin-bottom: 14px; }
@media (min-width: 1400px) { .ai-main-grid { grid-template-columns: 1fr 360px; } }
@media (min-width: 1800px) { .ai-main-grid { grid-template-columns: 1fr 400px; } }
@media (max-width: 900px)  { .ai-main-grid { grid-template-columns: 1fr; } }

.ai-chart-card { background: #ffffff; border: 1px solid #e2e8f0; border-radius: var(--radius); overflow: hidden; }
.ai-chart-toolbar {
  display: flex; gap: 8px; padding: 8px 12px;
  background: #f8fafc; border-bottom: 1px solid #e2e8f0;
  align-items: center; flex-wrap: wrap; justify-content: space-between;
}
.ai-overlay-tabs { display: flex; gap: 4px; }
.ai-overlay-tab { padding: 3px 10px; font-size: 11px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg-card); color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.ai-overlay-tab:not(.on):hover { border-color: var(--primary); color: var(--primary); background: var(--primary-glow); }
.ai-overlay-tab.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.ai-ma-legend { display: flex; gap: 12px; margin-left: 4px; font-size: 11px; color: #52606d; }
.ai-ma-dot { width: 12px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 3px; vertical-align: middle; }
#ai-main-chart { width: 100%; }
/* lightweight-charts 有時候會在瀏覽器縮放（zoom）比例改變時量到過期的寬度，導致 canvas 實際比容器寬、把整頁撐出橫向捲軸；
   這裡強制它跟它產生的 canvas 都不能超過容器寬度，當保底防線 */
.tv-lightweight-charts, .tv-lightweight-charts canvas { max-width: 100%; }
.ai-chart-wrap { position: relative; }
#ai-draw-canvas { position: absolute; top: 0; left: 0; pointer-events: none; }
.ai-draw-tools { display: flex; gap: 6px; align-items: center; }
.ai-draw-select { padding: 3px 6px; font-size: 11px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg-card); color: var(--text-muted); cursor: pointer; }
.ai-draw-btn { padding: 3px 10px; font-size: 11px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg-card); color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.ai-draw-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-glow); }
.ai-draw-btn.on { background: #dc2626; border-color: #dc2626; color: #fff; }
.ai-draw-lines-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; }
.ai-draw-lines-list:not(:empty) { padding-top: 8px; }
.ai-draw-line-chip { display: flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 6px 2px 9px; border-radius: 10px; background: #f1f5f9; color: #52606d; }
.ai-draw-line-chip button { border: none; background: none; cursor: pointer; color: #94a3b8; font-size: 12px; line-height: 1; padding: 0 2px; }
.ai-draw-line-chip button:hover { color: #dc2626; }
.ai-ind-row { display: flex; border-top: 1px solid #e2e8f0; }
.ai-ind-pane { flex: 1; border-right: 1px solid #e2e8f0; }
.ai-ind-pane:last-child { border-right: none; }
.ai-ind-label { font-size: 11px; color: #52606d; padding: 5px 10px; background: #f8fafc; border-bottom: 1px solid #e2e8f0; text-transform: uppercase; letter-spacing: .5px; }
#ai-rsi-chart, #ai-macd-chart { width: 100%; }

.ai-panel { display: flex; flex-direction: column; gap: 10px; }
.ai-score-box {
  background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius); padding: 14px 16px;
}
.ai-score-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.ai-score-num { font-size: 42px; font-weight: 800; font-family: 'Fira Code', monospace; letter-spacing: -2px; }
.ai-rec-badge { padding: 5px 12px; border-radius: 5px; font-size: 12px; font-weight: 600; }
.ai-rec-strong { background: var(--loss-dim);              color: #15803d; }
.ai-rec-good   { background: rgba(245,158,11,.12);         color: #b45309; }
.ai-rec-watch  { background: rgba(249,115,22,.12);          color: #c2410c; }
.ai-rec-avoid  { background: var(--profit-dim);             color: #b91c1c; }
.ai-oneliner-banner { padding: 10px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.ai-light-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.ai-sec-title { font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 7px; }
.ai-ind-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ai-ind-card  { background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius-sm); padding: 9px 10px; }
.ai-ind-card-label { font-size: 11px; color: var(--text-dim); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .3px; }
.ai-ind-card-val   { font-size: 15px; font-weight: 700; font-family: 'Fira Code', monospace; }
.ai-ind-card-sub   { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.ai-zone-box { background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius-sm); overflow: hidden; }
.ai-zone-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.ai-zone-row:last-child { border-bottom: none; }
.ai-zone-row.hi-zone  { background: rgba(239,68,68,.05); }
.ai-zone-row.buy-zone { background: rgba(245,158,11,.06); }
.ai-zone-row.lo-zone  { background: rgba(34,197,94,.05); }
.ai-zone-row.warn-zone { background: rgba(217,119,6,.08); }
.ai-zone-label { font-size: 12px; color: var(--text-dim); }
.ai-zone-val   { font-size: 14px; font-weight: 700; font-family: 'Fira Code', monospace; }

.ai-detail-list { display: flex; flex-direction: column; gap: 4px; }
.ai-detail-item { display: flex; align-items: flex-start; gap: 7px; font-size: 12px; line-height: 1.6; color: var(--text-muted); }
.ai-dot       { width: 6px; height: 6px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.ai-dot-pass  { background: var(--loss); }
.ai-dot-fail  { background: var(--border2); }

.ai-dim-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
@media (max-width: 1100px) { .ai-dim-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px)  { .ai-dim-grid { grid-template-columns: 1fr; } }
.ai-dim-card-hd { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; }
.ai-dim-card-name { font-size: 13px; font-weight: 700; color: var(--text-muted); flex: 1; }
.ai-dim-card-score { font-weight: 700; font-family: 'Fira Code', monospace; font-size: 13px; }
.ai-dim-card-track { height: 5px; background: var(--border2); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.ai-dim-card-fill  { height: 100%; border-radius: 3px; transition: width .5s cubic-bezier(.4,0,.2,1); }

.ai-bottom-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (min-width: 1400px) { .ai-bottom-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; } }
@media (max-width: 700px)  { .ai-bottom-grid { grid-template-columns: 1fr; } }
.ai-market-sep { border-top: 1px solid var(--border); margin: 10px 0; }
.ai-fund-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .ai-fund-grid { grid-template-columns: 1fr; } }
.ai-river-legend { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; flex-wrap: wrap; }
.ai-river-legend-item { display: inline-flex; align-items: center; gap: 4px; }
.ai-river-legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex-shrink: 0; }
.ai-fund-label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.ai-div-stat-row { display: flex; gap: 32px; margin-bottom: 16px; }
.ai-div-stat-val { font-size: 22px; font-weight: 700; color: var(--text); font-family: 'Fira Code'; }
.ai-div-stat-label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.ai-div-bars { display: flex; align-items: flex-end; gap: 12px; height: 120px; }
.ai-div-bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; height: 100%; }
.ai-div-bar-val { font-size: 11px; color: var(--text-muted); font-family: 'Fira Code'; margin-bottom: 4px; }
.ai-div-bar { width: 100%; max-width: 40px; background: #fbbf24; border-radius: 3px 3px 0 0; min-height: 2px; }
.ai-div-bar-year { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.ai-period-btns { display: flex; gap: 6px; margin-bottom: 12px; }
.ai-period-btn { padding: 4px 12px; font-size: 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-card); color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.ai-period-btn:not(.on):hover { border-color: var(--primary); color: var(--primary); background: var(--primary-glow); }
.ai-period-btn.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.ai-inst-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 12px; }
.ai-inst-table th, .ai-inst-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); font-family: 'Fira Code'; }
.ai-inst-table th:first-child, .ai-inst-table td:first-child { text-align: left; font-family: inherit; }
.ai-inst-table th { color: var(--text-dim); font-weight: 600; }
.ai-inst-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.ai-inst-table tbody { display: block; max-height: 280px; overflow-y: auto; }
.ai-inst-table thead, .ai-inst-table tbody tr, .ai-inst-table tfoot { display: table; width: 100%; table-layout: fixed; }
.ai-inst-table tbody tr { transition: background var(--transition); }
.ai-inst-table tbody tr:hover { background: var(--bg-hover); }
.screener-grid { display: flex; flex-direction: column; gap: 8px; }
.screener-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); transition: background var(--transition), border-color var(--transition); }
.screener-row:hover { background: var(--bg-hover); }
.screener-row.active { background: var(--primary-glow); border-color: var(--primary); }
.screener-row-label { flex: 0 0 auto; min-width: 132px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); background: var(--bg-card2); border-radius: var(--radius-sm); padding: 7px 10px; display: flex; align-items: center; gap: 5px; }
.screener-row-info { flex: 0 0 auto; display: inline-flex; color: var(--text-dim); cursor: help; transition: color var(--transition); border-radius: 999px; }
.screener-row-info:hover, .screener-row-info:focus-visible { color: var(--primary); }
.screener-row-fields { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.screener-row select, .screener-row input[type="number"] { flex: 1 1 0; min-width: 0; font-size: 12.5px; padding: 7px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); cursor: pointer; color: var(--text); }
.screener-row input[type="number"] { cursor: text; }
.screener-row-suffix, .screener-row-static { flex: 0 0 auto; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.screener-row-add { flex: 0 0 auto; width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); border: none; background: var(--primary); color: #fff; font-size: 17px; line-height: 1; cursor: pointer; transition: background var(--transition); }
.screener-row-add:hover { background: var(--primary-h); }
.screener-row-add.on { background: var(--loss); font-size: 12.5px; width: auto; padding: 0 10px; gap: 4px; border-radius: 999px; }
@media (max-width: 700px) { .screener-row { flex-wrap: wrap; } .screener-row-label { flex: 1 1 100%; } .screener-row-fields { flex: 1 1 100%; flex-wrap: wrap; } }
.screener-tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--border); }
.screener-tab { padding: 7px 14px; font-size: 13px; font-weight: 500; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.screener-tab:hover { color: var(--text-muted); }
.screener-tab.on { color: var(--primary); border-bottom-color: var(--primary); }
.screener-strategy-box { min-height: 44px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--text-dim); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.screener-strategy-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--primary-glow); color: var(--text-muted); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; }
.screener-strategy-chip button { border: none; background: none; cursor: pointer; color: var(--text-dim); font-size: 13px; line-height: 1; padding: 2px; }
.screener-strategy-chip button:hover { color: #dc2626; }
.screener-strategy-sep { color: var(--text-dim); font-size: 12px; }
.screener-result-stat { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.screener-result-stat .ai-div-stat-val { font-size: 28px; }
.screener-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 12px; }
.screener-table th, .screener-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); font-family: 'Fira Code'; }
.screener-table th:first-child, .screener-table td:first-child { text-align: left; font-family: inherit; }
.screener-table th { color: var(--text-dim); font-weight: 600; }
.screener-table tbody tr { transition: background var(--transition); }
.screener-table tbody tr:hover { background: var(--bg-hover); }
.screener-preset-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.screener-preset-row:last-child { border-bottom: none; }
.screener-preset-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.screener-preset-desc { font-size: 12px; color: var(--text-dim); }
.ai-news-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.ai-news-item { padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.ai-news-item:last-child { border-bottom: none; }
.ai-news-title { font-size: 13px; color: var(--text-muted); text-decoration: none; line-height: 1.5; display: block; transition: color .15s; }
.ai-news-title:hover { color: var(--primary); }
.ai-news-date  { font-size: 11px; color: var(--text-dim); margin-top: 2px; font-family: 'Fira Code', monospace; }

/* ── Watchlist ── */
.wl-input {
  width: 100%; height: 90px; padding: 8px 10px;
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  font-family: 'Fira Code', monospace; font-size: 13px; resize: vertical;
  background: var(--bg); color: var(--text);
}
.wl-input:focus { outline: none; border-color: var(--primary); }
.wl-badge { display: inline-block; padding: 3px 9px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.wl-badge-strong { background: var(--loss-dim);          color: #15803d; }
.wl-badge-good   { background: rgba(245,158,11,.12);     color: #b45309; }
.wl-badge-watch  { background: rgba(249,115,22,.12);      color: #c2410c; }
.wl-badge-avoid  { background: var(--profit-dim);         color: #b91c1c; }
.wl-bar-mini { display: inline-block; width: 50px; height: 4px; background: var(--border2); border-radius: 2px; overflow: hidden; vertical-align: middle; }
.wl-bar-mini-fill { height: 100%; border-radius: 2px; }
.wl-table tbody tr { cursor: pointer; }

/* ── Spinner ── */
.ai-spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border2); border-top-color: var(--primary); border-radius: 50%; animation: ai-spin .7s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-loading { display: flex; align-items: center; gap: 10px; padding: 30px; justify-content: center; color: var(--text-dim); font-size: 14px; }
.ai-error { padding: 12px 14px; color: #b91c1c; background: var(--profit-dim); border-radius: var(--radius-sm); border-left: 3px solid var(--profit); font-size: 13px; margin-bottom: 12px; }
.ai-empty-msg { text-align: center; padding: 50px; color: var(--text-dim); font-size: 13px; }

/* ── Toast 通知 ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--bg-card2); border: 1px solid var(--border2);
  color: var(--text); font-size: 13px; padding: 10px 20px;
  border-radius: 30px; box-shadow: 0 4px 20px rgba(15,23,42,.18);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 1000; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok   { border-color: rgba(74,222,128,.4); color: var(--loss); }
.toast.err  { border-color: rgba(248,113,113,.4); color: var(--profit); }

/* ── Settings info box ── */
.s-info { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 14px; }

/* ── Cache bar ── */
.ai-cache-bar { display:flex; align-items:center; gap:8px; font-size:11px; color:var(--text-dim); padding:0 0 10px; flex-wrap:wrap; }
.ai-cache-dot { width:6px; height:6px; border-radius:50%; flex-shrink:0; }
.ai-refresh-btn { padding:2px 8px; border:1px solid var(--border2); border-radius:4px; background:transparent; color:var(--text-muted); cursor:pointer; font-size:11px; transition:all .15s; font-family:inherit; }
.ai-refresh-btn:hover { border-color:var(--primary); color:var(--primary); }
.ai-name-label { font-size:15px; color:var(--text-muted); font-weight:400; }

/* ── Watchlist chips ── */
.wl-chip-wrap { display:flex; flex-wrap:wrap; gap:7px; }
.wl-chip { display:inline-flex; align-items:center; gap:5px; background:var(--bg); border:1px solid var(--border2); border-radius:6px; padding:6px 10px; font-size:13px; cursor:pointer; transition:all var(--transition); }
.wl-chip:hover { border-color:var(--primary); background:var(--primary-glow); }
.wl-chip-id { font-family:'Fira Code',monospace; font-weight:600; color:var(--text); }
.wl-chip-name { color:var(--text-muted); font-size:11px; }
.wl-chip-del { color:var(--text-dim); background:none; border:none; cursor:pointer; padding:0 0 0 4px; font-size:16px; line-height:1; transition:color .15s; }
.wl-chip-del:hover { color:var(--profit); }
.wl-saved-hd { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.wl-saved-label { font-size:11px; font-weight:700; color:var(--text-dim); text-transform:uppercase; letter-spacing:.6px; }
.icon-link-btn { display:inline-flex; align-items:center; justify-content:center; width:26px; height:26px; border-radius:5px; color:var(--text-dim); transition:all .15s; }
.icon-link-btn:hover { background:var(--primary-glow); color:var(--primary); }
.wl-ref-btn { background:none; border:1px solid var(--border2); color:var(--text-muted); border-radius:4px; padding:2px 6px; font-size:13px; cursor:pointer; transition:all .15s; }
.wl-ref-btn:hover { border-color:var(--primary); color:var(--primary); }
.wl-ref-btn:disabled { opacity:.4; cursor:default; }
.wl-row-loading { opacity:.5; pointer-events:none; }
.wl-refresh-time { font-size:10px; color:var(--text-dim); white-space:nowrap; }
.wl-add-chip { display:inline-flex; align-items:center; gap:4px; background:var(--bg); border:1px dashed var(--border2); border-radius:6px; padding:4px 8px; }
.wl-add-input { background:none; border:none; outline:none; color:var(--text); font-size:13px; font-family:'Fira Code',monospace; width:80px; }
.wl-add-input::placeholder { color:var(--text-dim); }
.wl-bulk-area { margin-top:12px; border-top:1px solid var(--border); padding-top:12px; }
.wl-bulk-label { font-size:11px; color:var(--text-dim); margin-bottom:6px; display:flex; justify-content:space-between; }
/* 愛心 / 關心清單 */
.heart-btn { background:none; border:none; cursor:pointer; padding:1px 4px; font-size:16px; line-height:1; transition:transform .15s; color:var(--text-dim); opacity:.45; }
.heart-btn:hover { transform:scale(1.25); opacity:1; }
.heart-btn.fav { color:#dc2626; opacity:1; }
.fav-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(185px,1fr)); gap:10px; }
.fav-card { background:var(--bg-card2); border:1px solid var(--border); border-radius:var(--radius); padding:14px 16px; cursor:pointer; transition:all var(--transition); }
.fav-card:hover { border-color:#dc2626; background:rgba(239,68,68,.07); }
.fav-empty { padding:48px 0; text-align:center; color:var(--text-dim); line-height:2; }
/* AI 推薦 / 搜尋 */
.rec-search-wrap { position:relative; margin-bottom:12px; }
.rec-search-wrap svg { position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--text-dim); pointer-events:none; }
.rec-search-input { width:100%; background:var(--bg); border:1px solid var(--border2); color:var(--text); border-radius:var(--radius-sm); padding:8px 12px 8px 34px; font-size:13px; outline:none; font-family:'Fira Sans',sans-serif; transition:border-color .15s; }
.rec-search-input:focus { border-color:var(--primary); }
.rec-theme-btn { background:var(--bg); border:1px solid var(--border2); color:var(--text-muted); border-radius:20px; padding:4px 12px; font-size:12px; cursor:pointer; transition:all .15s; white-space:nowrap; }
.rec-theme-btn:hover,.rec-theme-btn.on { border-color:var(--primary); color:var(--primary); background:var(--primary-glow); }
.rec-stock-item { display:flex; align-items:center; gap:10px; padding:8px 0; border-bottom:1px solid var(--border); }
.rec-stock-item:last-child { border-bottom:none; }
/* 除權息日曆 */
.dc-scope-row { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:10px; margin-bottom:14px; }
.dc-scope-btn { background:var(--bg); border:1px solid var(--border2); color:var(--text-muted); border-radius:20px; padding:5px 14px; font-size:13px; cursor:pointer; transition:all .15s; }
.dc-scope-btn:hover { border-color:var(--primary); color:var(--primary); }
.dc-scope-btn.on { border-color:var(--primary); color:var(--primary); background:var(--primary-glow); font-weight:600; }
.dc-nav-row { display:flex; align-items:center; justify-content:center; gap:14px; margin-bottom:14px; }
.dc-nav-title { font-size:17px; font-weight:700; min-width:110px; text-align:center; font-family:'Fira Code',monospace; }
.dc-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.dc-dow { text-align:center; font-size:11px; color:var(--text-dim); text-transform:uppercase; letter-spacing:.5px; padding-bottom:6px; }
.dc-cell { min-height:96px; border:1px solid var(--border); border-radius:var(--radius-sm); padding:6px; background:var(--bg); display:flex; flex-direction:column; gap:4px; transition:border-color var(--transition); }
.dc-cell:hover { border-color:var(--border2); }
.dc-cell.out { opacity:.35; }
.dc-cell.today { border-color:var(--primary); box-shadow:0 0 0 1px var(--primary); }
.dc-cell-date { font-size:12px; font-weight:600; color:var(--text-muted); font-family:'Fira Code',monospace; }
.dc-pill { background:var(--bg-card); border:1px solid var(--border2); border-radius:5px; padding:3px 6px; font-size:11px; line-height:1.5; cursor:pointer; transition:border-color .15s; }
.dc-pill:hover { border-color:var(--primary); }
.dc-pill-code { font-weight:700; font-family:'Fira Code',monospace; }
.dc-pill-tag { display:inline-block; font-size:9px; font-weight:700; border-radius:3px; padding:0 4px; margin-left:3px; }
.dc-pill-tag.cash { background:var(--profit-dim); color:var(--profit); }
.dc-pill-tag.stock { background:var(--loss-dim); color:var(--loss); }
.dc-more { font-size:11px; color:var(--primary); cursor:pointer; text-align:center; padding:2px 0; }
.dc-upcoming-row { display:flex; align-items:center; gap:12px; padding:9px 4px; border-bottom:1px solid var(--border); font-size:13px; }
.dc-upcoming-row:last-child { border-bottom:none; }
.dc-upcoming-date { font-family:'Fira Code',monospace; color:var(--text-dim); min-width:78px; }
.dc-modal-bg { position:fixed; inset:0; background:rgba(15,23,42,.45); display:flex; align-items:center; justify-content:center; z-index:100; }
.dc-modal { background:var(--bg-card); border:1px solid var(--border2); border-radius:var(--radius); padding:20px; width:360px; max-height:80vh; overflow-y:auto; }
.dc-modal-hd { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.dc-modal-close { background:none; border:none; color:var(--text-dim); cursor:pointer; font-size:18px; line-height:1; }
