/* =========================================================
 * TradingView-inspired dark theme
 * Taiwan stock convention: red = up, green = down
 * ========================================================= */

:root {
  --bg-0:       #0c0e15;   /* deepest */
  --bg-1:       #131722;   /* primary surface (TradingView base) */
  --bg-2:       #1c2030;   /* panel / card */
  --bg-3:       #252a3a;   /* hover */
  --border-1:   #2a2e39;   /* primary border */
  --border-2:   #363c4e;   /* secondary border */

  --text-1:     #d1d4dc;   /* primary text */
  --text-2:     #9a9da9;   /* secondary */
  --text-3:     #6a6e7c;   /* muted */
  --text-4:     #4a4e5c;   /* very muted */

  --accent:     #2962FF;   /* TradingView blue */
  --accent-2:   #3179f5;
  --up:         #f23645;   /* TW red = up */
  --down:       #089981;   /* TW green = down */
  --warn:       #ff9800;

  --radius:     6px;
  --radius-lg:  8px;
  --topbar-h:   48px;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg-1);
  color: var(--text-1);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.cursor-pointer { cursor: pointer; }
.text-xs { font-size: 11px; }
.text-lg { font-size: 16px; }
.text-up   { color: var(--up); }
.text-down { color: var(--down); }
.text-muted { color: var(--text-3); }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.flex-gap { display: flex; gap: 8px; align-items: center; }
.space-y-2 > * + * { margin-top: 8px; }
.w-full { width: 100%; }

/* ============ Top Bar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 64px;
}
.topbar-left  { display: flex; align-items: stretch; gap: 22px; height: 100%; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-1);
  padding-right: 22px;
  border-right: 1px solid var(--border-1);
}
.brand svg { width: 26px; height: 26px; color: var(--accent); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: 0.04em; }
.brand-tag {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.3em;
  margin-top: 2px;
}

/* ============ Ticker Bar(跑馬燈)============ */
.ticker-bar {
  height: 34px;
  overflow: hidden;
  background: var(--bg-0);
  border-bottom: 1px solid var(--border-1);
  position: relative;
}
.ticker-content {
  display: inline-flex;
  white-space: nowrap;
  align-items: center;
  height: 100%;
  animation: ticker-scroll 90s linear infinite;
  will-change: transform;
}
.ticker-bar:hover .ticker-content { animation-play-state: paused; }
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 22px;
  font-size: 13px;
  border-right: 1px solid rgba(255,255,255,0.04);
}
.ticker-item .ticker-symbol  { color: var(--text-2); font-weight: 500; font-size: 12px; }
.ticker-item .ticker-px      { color: var(--text-1); font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.ticker-item .ticker-chg     { font-size: 11px; font-family: 'JetBrains Mono', monospace; }
.ticker-loading { color: var(--text-3); font-size: 12px; padding: 0 20px; }

.tabs { display: flex; align-items: stretch; height: 100%; }
.tab {
  position: relative;
  background: transparent;
  border: 0;
  color: var(--text-2);
  font-size: 14px;
  font-family: inherit;
  padding: 0 16px;
  cursor: pointer;
  transition: color .15s;
}
.tab:hover { color: var(--text-1); }
.tab.active { color: var(--text-1); }
.tab.active::after {
  content: '';
  position: absolute;
  left: 8px; right: 8px;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px 1px 0 0;
}

/* ============ Indices Strip ============ */
.indices-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
}
.idx {
  display: flex;
  align-items: center;
  gap: 6px;
}
.idx-name { color: var(--text-3); }
.idx-px   { color: var(--text-1); font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.idx-chg  { font-size: 11px; font-family: 'JetBrains Mono', monospace; }
.idx-loading { color: var(--text-3); font-size: 11px; }

.icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  background: transparent;
  border: 1px solid var(--border-1);
  border-radius: var(--radius);
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
}
.icon-btn-sm:hover { color: var(--text-1); background: var(--bg-2); border-color: var(--border-2); }
.icon-btn-sm svg { width: 14px; height: 14px; }
.icon-btn-sm.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Layout ============ */
.container {
  max-width: 1800px;
  margin: 0 auto;
  padding: 18px 24px;
}
.page { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-title    { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -0.02em; color: #fff; }
.page-subtitle { font-size: 14px; color: var(--text-3); margin: 8px 0 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ============ Cards ============ */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.card.flat { padding: 0; overflow: hidden; }
.card.kpi  { padding: 14px 16px; }

/* 可摺疊卡片 (details/summary) */
details.collapsible-card {
  padding: 0;
}
.collapsible-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  user-select: none;
  position: relative;
  transition: background 0.15s;
}
.collapsible-summary::-webkit-details-marker { display: none; }
.collapsible-summary:hover {
  background: rgba(41, 98, 255, 0.04);
}
.collapsible-summary::after {
  content: '▾';
  color: var(--text-3);
  font-size: 12px;
  margin-left: 12px;
  transition: transform 0.2s ease;
  display: inline-block;
}
details.collapsible-card[open] > .collapsible-summary::after {
  transform: rotate(180deg);
  color: var(--accent);
}
.collapsible-hint {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.02em;
  margin-left: auto;
  margin-right: 4px;
}
.collapsible-content {
  padding: 4px 18px 18px;
  border-top: 1px solid var(--border-1);
}
.collapsible-content > *:first-child { margin-top: 14px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
}
.card-sub { font-size: 13px; color: var(--text-3); }
.sub-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; letter-spacing: 0.04em; }

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-1);
}

/* ============ KPI ============ */
.kpi-label {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
  font-weight: 500;
}
.kpi-value {
  font-family: 'Inter', -apple-system, "Noto Sans TC", sans-serif !important;
  font-size: 36px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-1);
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}

/* ============ Today Movers ============ */
.mover-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-1);
}
.mover-row:last-child { border-bottom: 0; }
.mover-info { display: flex; align-items: center; gap: 8px; }
.mover-sym  { font-family: 'JetBrains Mono', monospace; color: var(--text-3); font-size: 11px; }
.mover-name { color: var(--text-1); }
.mover-right { display: flex; align-items: center; gap: 10px; font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.mover-empty { color: var(--text-4); font-size: 11px; padding: 12px 0; }

/* ============ Chart wrappers ============ */
.chart-wrap      { position: relative; height: 240px; }
.chart-wrap-tall { position: relative; height: 280px; }

/* Asset growth chart · Y-axis range controls */
.growth-range-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  font-size: 12px;
}
.growth-range-label {
  color: var(--text-2);
  font-weight: 500;
  margin-right: 4px;
}
.growth-range-controls .input-sm {
  width: 110px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.growth-range-dash {
  color: var(--text-3);
  margin: 0 2px;
}
.growth-range-hint {
  margin-left: auto;
  color: var(--text-3);
  font-size: 11px;
}
@media (max-width: 768px) {
  .growth-range-controls .input-sm { width: 90px; }
  .growth-range-hint { display: none; }
}
.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-4);
  font-size: 12px;
}
.chart-empty.hidden { display: none; }

/* ============ Segmented control ============ */
.seg {
  display: inline-flex;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius);
  padding: 2px;
}
.seg-btn {
  background: transparent;
  border: 0;
  color: var(--text-3);
  font-size: 11px;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all .15s;
}
.seg-btn:hover { color: var(--text-1); }
.seg-btn.active {
  background: var(--bg-3);
  color: var(--text-1);
}

/* ============ Heatmap ============ */
.heatmap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.heatmap-year {
  display: flex;
  align-items: center;
  gap: 8px;
}
.heatmap-year-label {
  width: 36px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-3);
}
.heatmap-months {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  flex: 1;
}
.heatmap-cell {
  height: 40px;
  border-radius: 4px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-2);
  cursor: default;
  transition: filter .15s;
}
.heatmap-cell:hover { filter: brightness(1.3); }
.heatmap-cell.empty { color: var(--text-4); }
.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 10px;
  color: var(--text-3);
  margin-top: 6px;
}
.heatmap-legend-cells { display: flex; gap: 2px; }
.heatmap-legend-cells > div { width: 12px; height: 12px; border-radius: 2px; }

/* ============ Buttons ============ */
.btn-accent {
  background: var(--accent);
  color: #fff;
  border: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
}
.btn-accent:hover { background: var(--accent-2); }
.btn-ghost {
  background: var(--bg-2);
  color: var(--text-1);
  border: 1px solid var(--border-1);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-ghost:hover { background: var(--bg-3); border-color: var(--border-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger {
  background: transparent;
  color: var(--up);
  border: 1px solid rgba(242, 54, 69, 0.3);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-danger:hover { background: rgba(242, 54, 69, 0.08); }

/* ============ Type tabs (buy/sell/dividend) ============ */
.type-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-1);
}
.type-tab {
  position: relative;
  background: transparent;
  border: 0;
  color: var(--text-3);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 16px;
  cursor: pointer;
  transition: color .15s;
}
.type-tab:hover { color: var(--text-1); }
.type-tab.active { color: var(--text-1); }
.type-tab.active::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}
.type-tab[data-type="buy"].active::after  { background: var(--up); }
.type-tab[data-type="sell"].active::after { background: var(--down); }

/* ============ Forms ============ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.form-grid > div { display: flex; flex-direction: column; }
.form-grid label {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 5px;
  font-weight: 500;
}
.form-grid input,
.form-grid select,
.input {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius);
  color: var(--text-1);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
  font-variant-numeric: tabular-nums;
}
.form-grid input:focus,
.form-grid select:focus,
.input:focus { border-color: var(--accent); }
.form-grid input[readonly] { background: var(--bg-0); color: var(--text-2); }
.form-grid input::placeholder { color: var(--text-4); }
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.input-sm {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius);
  color: var(--text-1);
  font-family: inherit;
  font-size: 12px;
  padding: 5px 10px;
  outline: none;
  width: 220px;
}
.hint { font-size: 10px; color: var(--text-4); margin: 4px 0 0; }

/* ============ Table ============ */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table thead {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
}
.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-2);
  font-size: 13px;
  padding: 13px 16px;
  letter-spacing: 0.02em;
}
.data-table th.right { text-align: right; }
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-1);
  color: var(--text-1);
}
.data-table td.right { text-align: right; font-family: 'JetBrains Mono', monospace; }
.data-table td.left  { text-align: left; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.015); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tfoot td {
  padding: 12px 14px;
  background: var(--bg-1);
  font-weight: 500;
  border-top: 1px solid var(--border-1);
}
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}
.data-table th.sortable:hover { color: var(--text-1); }
.data-table th.sortable.sort-active { color: var(--accent); }
.data-table th.sortable::after {
  content: ' ⇅';
  opacity: 0.25;
  font-size: 10px;
}
.data-table th.sortable.sort-active::after { opacity: 1; }
.data-table th.sortable.sort-desc::after  { content: ' ↓'; }
.data-table th.sortable.sort-asc::after   { content: ' ↑'; }
.empty-row td {
  text-align: center;
  color: var(--text-4);
  padding: 32px;
}

/* ============ Tags ============ */
.tag {
  display: inline-block;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  color: var(--text-2);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 0.02em;
}
.tag-buy  { background: rgba(242, 54, 69, 0.1);  color: var(--up);   border-color: rgba(242, 54, 69, 0.2); }
.tag-sell { background: rgba(8, 153, 129, 0.1); color: var(--down); border-color: rgba(8, 153, 129, 0.2); }
.tag-div  { background: rgba(41, 98, 255, 0.1); color: var(--accent); border-color: rgba(41, 98, 255, 0.25); }
.tag-hist { background: rgba(154, 157, 169, 0.1); color: var(--text-2); border-color: rgba(154, 157, 169, 0.25); }

.symbol-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.symbol-cell .sym { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-3); }
.symbol-cell .name { font-size: 13px; color: var(--text-1); }

.clickable-name {
  cursor: pointer;
  transition: color 0.15s ease;
  position: relative;
}
.clickable-name:hover .name {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

/* 訊號 tooltip(持倉滑鼠 hover 時顯示) */
.has-tooltip .signal-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 140px;
  max-width: 320px;
  align-items: center;
}
.has-tooltip:hover .signal-tooltip {
  display: flex;
}
.signal-tooltip-label {
  width: 100%;
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  margin-bottom: 2px;
  font-family: 'JetBrains Mono', monospace;
}

.editable-price {
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color .15s;
}
.editable-price:hover { border-bottom-color: var(--accent); }

/* ============ Icon button (table action) ============ */
.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: transparent;
  border: 1px solid var(--border-1);
  border-radius: 4px;
  color: var(--text-3);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.icon-action:hover { color: var(--text-1); border-color: var(--border-2); }
.icon-action.danger:hover { color: var(--up); border-color: rgba(242, 54, 69, 0.3); }

/* ============ Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade .15s ease;
}
.modal-box {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  width: 36rem;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box.small { width: 24rem; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-title { font-size: 14px; font-weight: 600; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ============ Batch price list ============ */
.batch-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
}
.batch-row {
  display: grid;
  grid-template-columns: 1.5fr 2fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.batch-row > .col-sym { font-family: 'JetBrains Mono', monospace; color: var(--text-3); font-size: 11px; }
.batch-row > .col-name { color: var(--text-1); font-size: 12px; }

/* ============ Concentration bar(集中度警示)============ */
.concentration-info {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text-2);
}
.concentration-info strong { color: var(--text-1); font-size: 16px; }
.concentration-info strong.text-up { color: var(--up); }
.concentration-stacked-bar {
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  background: var(--bg-0);
  margin-bottom: 14px;
}
.concentration-stacked-bar > div {
  height: 100%;
  transition: filter .15s;
  min-width: 1px;
}
.concentration-stacked-bar > div:hover { filter: brightness(1.25); }
.concentration-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 12px;
  color: var(--text-2);
}
.concentration-legend > div {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.concentration-legend .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============ News page ============ */
textarea.input { font-family: inherit; resize: vertical; line-height: 1.55; }

/* LIVE card */
.live-card .card-title { display: flex; align-items: center; gap: 8px; }
.live-dot {
  width: 8px; height: 8px;
  background: var(--up);
  border-radius: 50%;
  animation: live-pulse 2s infinite;
  display: inline-block;
}
@keyframes live-pulse {
  0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(242,54,69,0.55); }
  50%     { opacity: 0.8; box-shadow: 0 0 0 6px rgba(242,54,69,0); }
}

/* 三大法人對比表格(今日/昨日) */
.fund-table {
  display: flex;
  flex-direction: column;
}
.fund-row {
  display: grid;
  grid-template-columns: 55px 1fr 1fr;
  gap: 8px;
  padding: 8px 4px;
  align-items: center;
  border-bottom: 1px solid var(--border-1);
  font-size: 13px;
}
.fund-row:last-child { border-bottom: 0; }
.fund-row.fund-header {
  border-bottom: 1px solid var(--border-2);
  padding-bottom: 4px;
  padding-top: 2px;
  font-size: 10px;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
}
.fund-col-date {
  text-align: right;
  letter-spacing: 0.02em;
}
.fund-name {
  color: var(--text-1);
  font-weight: 500;
}
.fund-val {
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
}

/* 國內市場頂部「資料時間」摘要 */
.market-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(28, 32, 48, 0.5);
  border-radius: 4px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  border-left: 2px solid var(--accent);
}

/* 每行指數的小標籤(LIVE 或 日期) */
.index-tag-live {
  display: inline-block;
  font-size: 9px;
  color: var(--up);
  background: rgba(242, 54, 69, 0.15);
  border: 1px solid rgba(242, 54, 69, 0.4);
  padding: 1px 5px;
  border-radius: 2px;
  margin-left: 4px;
  font-weight: 600;
  letter-spacing: 0.05em;
  animation: live-pulse 2s infinite;
}
.index-tag-date {
  display: inline-block;
  font-size: 9px;
  color: var(--text-3);
  background: rgba(154, 157, 169, 0.1);
  padding: 1px 5px;
  border-radius: 2px;
  margin-left: 4px;
  font-family: 'JetBrains Mono', monospace;
}

/* LIVE 標籤(盤中自動刷新時顯示) */
.market-live-tag {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--up);
  background: rgba(242, 54, 69, 0.12);
  border: 1px solid rgba(242, 54, 69, 0.35);
  padding: 1px 7px;
  border-radius: 3px;
  margin-left: 8px;
  letter-spacing: 0.05em;
  animation: live-pulse 2s infinite;
}
.market-live-tag.hidden { display: none !important; }

.live-items, .advice-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.live-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 4px;
  border-radius: var(--radius);
  position: relative;
}
.live-item:hover { background: var(--bg-1); }
.live-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 22px;
  border-radius: 4px;
  background: var(--bg-3);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-2);
  flex-shrink: 0;
  letter-spacing: 0.04em;
  cursor: text;
  outline: none;
}
.live-item-icon.icon-us    { background: rgba(41,98,255,0.18); color: var(--accent); }
.live-item-icon.icon-tw    { background: rgba(8,153,129,0.18); color: var(--down); }
.live-item-icon.icon-alert { background: rgba(255,152,0,0.18); color: var(--warn); }
.live-item-icon.icon-news  { background: rgba(154,157,169,0.15); color: var(--text-2); }

.live-item-body {
  flex: 1;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-2);
  outline: none;
  min-height: 22px;
  padding: 0 4px;
  border-radius: 3px;
  cursor: text;
}

.live-item-time {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  padding-top: 4px;
  letter-spacing: 0.02em;
}
.live-item-time-fresh {
  color: var(--up);
  font-weight: 600;
}
.live-item-time-fresh::before {
  content: '🔥 ';
  font-size: 11px;
}
.live-item-time-stale {
  color: var(--warn);
}
.live-item-time-stale::before {
  content: '⚠️ ';
  font-size: 11px;
}
.live-item-stale .live-item-body {
  opacity: 0.55;
}
.live-item-body:focus, .live-item-icon:focus {
  background: rgba(41,98,255,0.08);
  outline: 1px solid var(--accent);
}
.live-item-body:empty::before {
  content: '點擊以編輯內容...';
  color: var(--text-4);
}
.live-item-body strong { color: var(--text-1); margin-right: 6px; }

.item-delete-btn {
  position: absolute;
  top: 8px;
  right: 4px;
  width: 22px; height: 22px;
  border-radius: 4px;
  background: transparent;
  border: 0;
  color: var(--text-4);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: all .15s;
}
.live-item:hover .item-delete-btn,
.advice-item:hover .item-delete-btn { opacity: 1; }
.item-delete-btn:hover { color: var(--up); background: rgba(242,54,69,0.1); }

/* Advice items */
.advice-title { color: var(--down); }
.advice-item {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-2);
  padding: 6px 32px 6px 4px;
  border-radius: var(--radius);
  position: relative;
}
.advice-item:hover { background: var(--bg-1); }
.advice-item-body {
  outline: none;
  padding: 0 4px;
  border-radius: 3px;
  cursor: text;
}
.advice-item-body:focus {
  background: rgba(41,98,255,0.08);
  outline: 1px solid var(--accent);
}
.advice-item-body:empty::before {
  content: '點擊以編輯,可用 **粗體** 標示重點';
  color: var(--text-4);
}
.advice-item-body strong { color: var(--down); font-weight: 600; }

.empty-block { padding: 16px 4px; color: var(--text-4); font-size: 12px; text-align: center; }

/* Bottom row: holding news (left) + market (right) */
.grid-news-bottom {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 12px;
}

.news-count-badge {
  background: var(--bg-3);
  color: var(--text-3);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 400;
}

.holding-news-list { display: flex; flex-direction: column; }
.holding-news-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-1);
  cursor: pointer;
}
.holding-news-item:last-child { border-bottom: 0; }
.holding-news-item:hover { background: rgba(255,255,255,0.015); }
.holding-news-tag {
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}
.holding-news-body { flex: 1; min-width: 0; }
.holding-news-headline {
  font-size: 13px;
  color: var(--text-1);
  line-height: 1.55;
}
.holding-news-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-3);
  margin-top: 4px;
}
.sentiment-up   { color: var(--up); }
.sentiment-down { color: var(--down); }
.sentiment-neutral { color: var(--text-3); }

/* 利多 / 利空 / 中性 小標籤 */
.sentiment-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}
.tag-bullish {
  color: var(--up);
  background: rgba(242, 54, 69, 0.12);
  border-color: rgba(242, 54, 69, 0.3);
}
.tag-bearish {
  color: var(--down);
  background: rgba(8, 153, 129, 0.12);
  border-color: rgba(8, 153, 129, 0.3);
}
.tag-neutral {
  color: var(--text-3);
  background: rgba(154, 157, 169, 0.08);
  border-color: rgba(154, 157, 169, 0.2);
}

/* Market indices on right */
.index-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-1);
}
.index-row:last-child { border-bottom: 0; }
.index-name-wrap { display: flex; align-items: center; gap: 6px; }
.index-name { font-size: 13px; color: var(--text-1); }
.index-tag {
  background: var(--bg-3);
  color: var(--text-3);
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.04em;
}
.index-right { text-align: right; font-family: 'JetBrains Mono', monospace; }
.index-value { font-weight: 600; font-size: 16px; line-height: 1.2; }
.index-change { font-size: 11px; margin-top: 2px; }

.section-divider {
  border-top: 1px solid var(--border-1);
  padding-top: 14px;
  margin-top: 14px;
}
.section-title {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.section-title::before {
  content: '';
  display: inline-block;
  width: 3px; height: 12px;
  background: var(--accent);
  border-radius: 2px;
}

/* ============ Watchlist ============ */
.watchlist-add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.watchlist-add-form .input {
  flex: 0 0 auto;
  width: 180px;
}
.watchlist-tip {
  margin-left: 8px;
  font-size: 11px;
  color: var(--text-3);
}

/* 群組分區 */
.watchlist-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.watchlist-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.watchlist-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 6px 4px;
  border-bottom: 1px solid var(--border-1);
}
.watchlist-group-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: 0.02em;
}
.watchlist-group-name::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: middle;
}
.watchlist-group-count {
  font-size: 11px;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
}
.watchlist-group-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  opacity: 0.5;
  transition: all 0.15s ease;
}
.watchlist-group-btn:hover {
  background: var(--bg-3);
  color: var(--accent);
  opacity: 1;
}
.watchlist-group-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.watchlist-group-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-3);
  padding: 24px 16px;
  font-size: 12px;
  border: 1px dashed var(--border-1);
  border-radius: 6px;
  background: rgba(28, 32, 48, 0.3);
  font-style: italic;
}
.watchlist-card {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: grab;
  transition: all 0.15s ease;
  position: relative;
}
.watchlist-card:active { cursor: grabbing; }
.watchlist-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.watchlist-card.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

/* 群組是 drop target 時的高亮 */
.watchlist-group.drop-target {
  background: rgba(41, 98, 255, 0.06);
  border-radius: 8px;
  padding: 6px;
  margin: -6px;
}
.watchlist-group.drop-target .watchlist-group-head {
  background: rgba(41, 98, 255, 0.18);
  border-radius: 4px;
  border-bottom-color: var(--accent);
  padding: 6px 10px;
}
.watchlist-group.drop-target .watchlist-group-empty {
  border-color: var(--accent);
  background: rgba(41, 98, 255, 0.1);
  color: var(--accent);
}
.watchlist-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.watchlist-card-sym {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--text-3);
}
.watchlist-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watchlist-card-price {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.watchlist-card-change {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  margin-top: 2px;
}

/* 訊號徽章列 */
.signal-row {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-1);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 24px;
  align-items: center;
}
.signal-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px solid;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.signal-bullish {
  color: #f23645;
  background: rgba(242, 54, 69, 0.12);
  border-color: rgba(242, 54, 69, 0.35);
}
.signal-bearish {
  color: #089981;
  background: rgba(8, 153, 129, 0.12);
  border-color: rgba(8, 153, 129, 0.35);
}
.signal-loading, .signal-none {
  font-size: 10px;
  color: var(--text-3);
  font-style: italic;
}
/* 卡片右上角的動作鈕(group + delete) */
.watchlist-card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.watchlist-card:hover .watchlist-card-actions {
  opacity: 1;
}
.watchlist-card-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.watchlist-card-btn:hover {
  background: var(--bg-3);
  color: var(--accent);
}
.watchlist-card-btn.watchlist-card-del:hover {
  background: rgba(242, 54, 69, 0.15);
  color: var(--up);
}
.watchlist-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-3);
  padding: 40px 16px;
  font-size: 13px;
}

/* K-line modal · 專業版(4 段:K線+MA / Volume+MV / KD / MACD) */
.modal-box.kline-box {
  width: 94vw;
  max-width: 1280px;
  max-height: 94vh;
  overflow-y: auto;
  padding: 18px 22px;
}
.kline-info {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-1);
  line-height: 1.7;
}
.kline-info .ma-legend {
  font-size: 11px;
  display: inline-block;
  margin-top: 2px;
}
.kline-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}
.kline-range {
  display: flex;
  gap: 4px;
}
.kline-toolbar .seg-btn {
  padding: 6px 14px;
  font-size: 12px;
}
.kline-loading {
  margin-left: auto;
  color: var(--accent);
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
}

/* 4 段 chart 區塊 */
.kline-section {
  position: relative;
  margin-bottom: 8px;
}
.kline-section-label {
  position: absolute;
  top: 4px;
  left: 8px;
  font-size: 10px;
  color: var(--text-3);
  background: rgba(28, 32, 48, 0.75);
  padding: 2px 6px;
  border-radius: 3px;
  z-index: 2;
  pointer-events: none;
  letter-spacing: 0.04em;
  font-family: 'JetBrains Mono', monospace;
}
.kline-wrap-main {
  position: relative;
  height: 400px;
  width: 100%;
}
.kline-wrap-sub {
  position: relative;
  height: 120px;
  width: 100%;
}

/* ============ Read-only (Guest) mode ============ */
.readonly-banner {
  background: linear-gradient(90deg, rgba(41,98,255,0.18), rgba(41,98,255,0.08));
  border-bottom: 1px solid rgba(41,98,255,0.4);
  color: var(--text-1);
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* 唯讀模式 · 隱藏所有標記 data-write 的元素 */
body.readonly [data-write] {
  display: none !important;
}

/* 唯讀模式 · 交易紀錄/現金的「刪除」按鈕欄位 */
body.readonly .icon-action {
  display: none !important;
}

/* 唯讀模式 · 價格欄不可點 */
body.readonly .price-clickable {
  cursor: default !important;
  text-decoration: none !important;
}
body.readonly .price-clickable:hover {
  background: transparent !important;
}

/* ============ MOPS quick link ============ */
.mops-card {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}
.mops-big-link {
  display: block;
  text-align: center;
  padding: 16px 20px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s ease;
}
.mops-big-link:hover {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ============ Cash management ============ */
.cash-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  color: var(--text-1);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius);
  z-index: 200;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4a5060; }

/* =========================================================
 * Responsive — 手機 / 平板自適應(桌面版不受影響)
 * 三段斷點:
 *   ≤ 1024px → 平板橫向 / 小筆電
 *   ≤ 768px  → 平板直向 / 大手機
 *   ≤ 480px  → 一般手機直向
 * ========================================================= */

@media (max-width: 1024px) {
  .container { padding: 16px; max-width: 100%; }
  .grid-news-bottom { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  body { font-size: 14px; }

  /* Top bar */
  .topbar-row { padding: 0 12px; height: 56px; }
  .topbar-left { gap: 12px; }
  .brand { gap: 8px; padding-right: 12px; }
  .brand svg { width: 22px; height: 22px; }
  .brand-name { font-size: 16px; }
  .brand-tag { display: none; }   /* 標語在手機上藏起來省空間 */
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 0 12px; font-size: 13px; flex-shrink: 0; }

  /* Ticker */
  .ticker-bar { height: 30px; }
  .ticker-item { padding: 0 16px; font-size: 12px; }

  /* Container & page head */
  .container { padding: 12px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-title { font-size: 22px; }
  .page-subtitle { font-size: 13px; }

  /* Grids → 縮排 */
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid-3 { grid-template-columns: 1fr; gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; gap: 10px; }

  /* KPI */
  .card.kpi { padding: 12px 14px; }
  .kpi-label { font-size: 12px; margin-bottom: 6px; }
  .kpi-value { font-size: 24px; }
  .kpi-sub { font-size: 12px; margin-top: 6px; }

  /* Cards */
  .card { padding: 14px 16px; }
  .card-title { font-size: 15px; }
  .card-sub { font-size: 12px; }

  /* Tables */
  .data-table { font-size: 13px; }
  .data-table th { padding: 10px 10px; font-size: 12px; }
  .data-table td { padding: 11px 10px; }
  .card-toolbar { flex-direction: column; gap: 8px; align-items: stretch; }
  .input-sm { width: 100%; }

  /* Forms — 4 col → 2 col */
  .form-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .form-actions { grid-column: 1 / -1; }

  /* Charts */
  .chart-wrap { height: 200px; }
  .chart-wrap-tall { height: 240px; }

  /* Heatmap */
  .heatmap-cell { height: 32px; font-size: 10px; border-radius: 3px; }
  .heatmap-year-label { width: 32px; font-size: 10px; }
  .heatmap-months { gap: 3px; }

  /* News page */
  .live-item { gap: 8px; padding: 6px 4px; }
  .live-item-icon { width: 28px; height: 20px; font-size: 9px; }
  .live-item-body { font-size: 12px; line-height: 1.5; }

  .concentration-legend { font-size: 11px; gap: 6px 12px; }

  /* Type tabs (買進/賣出/配息) */
  .type-tabs { overflow-x: auto; }
  .type-tab { padding: 8px 14px; font-size: 13px; flex-shrink: 0; }

  /* Modal */
  .modal-box { width: 95vw; padding: 16px; max-height: 90vh; }
  .modal-box.small { width: 92vw; }

  /* Page-head action buttons */
  .flex-gap { flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 480px) {
  body { font-size: 13px; }

  .ticker-bar { height: 28px; }
  .ticker-item { padding: 0 12px; font-size: 11px; }
  .ticker-item .ticker-px { font-size: 11px; }
  .ticker-item .ticker-chg { font-size: 10px; }

  .topbar-row { padding: 0 10px; height: 52px; }
  .brand svg { width: 20px; height: 20px; }
  .brand-name { font-size: 14px; }
  .tab { padding: 0 10px; font-size: 12px; }

  .container { padding: 10px; }
  .page-title { font-size: 20px; }

  /* KPI 2x2 + 更緊湊 */
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 6px; }
  .card.kpi { padding: 10px 12px; }
  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 11px; }
  .kpi-sub { font-size: 11px; }

  .card { padding: 12px 14px; }
  .card-title { font-size: 14px; }

  /* Forms 完全 1 欄 */
  .form-grid { grid-template-columns: 1fr; }

  /* Tables 最緊湊 */
  .data-table th, .data-table td { padding: 9px 8px; font-size: 12px; }
  .symbol-cell .name { font-size: 12px; }
  .symbol-cell .sym  { font-size: 10px; }
  .icon-action { width: 22px; height: 22px; }

  /* Heatmap 更小 */
  .heatmap-cell { height: 26px; font-size: 9px; }
  .heatmap-months { gap: 2px; }

  /* Modal */
  .modal-box { padding: 12px; width: 96vw; }

  /* News list */
  .holding-news-item { gap: 8px; padding: 10px 0; }
  .holding-news-tag { font-size: 10px; padding: 3px 6px; }
  .holding-news-headline { font-size: 12px; }

  /* Charts smaller */
  .chart-wrap { height: 180px; }
  .chart-wrap-tall { height: 200px; }

  /* Concentration */
  .concentration-info strong { font-size: 14px; }
  .concentration-legend > div { font-size: 11px; }
}
