/* ══════════════════════════════════════════════════════════════
   portfolio.css  ―  ポートフォリオヒートマップ スタイルシート
   ヒートマップ / モーダル / 統計バー / 銘柄リスト / レスポンシブ
   ══════════════════════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { overflow-x: hidden; }

/* ── CSS Variables (Light / Dark / Auto) ── */
/* Claude デスクトップアプリ準拠のウォームトーンパレット */
:root,
html[data-theme="light"] {
  --bg:        #f7f2ee;
  --surface:   #ffffff;
  --surface2:  #f0e9e3;
  --surface3:  #e8ddd7;
  --border:    #d4c8c0;
  --border2:   #e4d9d2;
  --text:      #1c1714;
  --text2:     #78695f;
  --text3:     rgba(28,23,20,0.50);
  --shadow:    0 8px 32px rgba(0,0,0,0.10);
  --shadow2:   rgba(0,0,0,0.35);
  --null-cell: #e8ddd7;
  --cat-bg:    #e0d4cc;
  --handle:    #d4c8c0;
  --chart-grid:rgba(0,0,0,0.06);
  --cost-line: rgba(80,65,55,0.55);
  --cost-text: rgba(80,65,55,0.80);
  --scrollbar-thumb:       rgba(0,0,0,0.18);
  --scrollbar-thumb-hover: rgba(0,0,0,0.30);
  --scrollbar-track:       transparent;
  --accent:    #cc785c;
  /* 意味色（良い/注意/警告/中立）＝全タブ共通の正（#515 P1・ライト）。verdict/severity はこれを使う */
  --tone-good: #4f8a4d;
  --tone-ok:   #b88a2e;
  --tone-warn: #c2603f;
  --tone-neu:  #8a8178;
  /* 判定バッジ/ゲージのトーン（#475 rev2）は --tone-* のエイリアス（既存参照を壊さない・値は不変） */
  --vg-good:   var(--tone-good);
  --vg-ok:     var(--tone-ok);
  --vg-warn:   var(--tone-warn);
  --vg-neu:    var(--tone-neu);
  /* 型スケール＝6サイズ（役割固定・ad-hoc px を段階的に廃止・#515 P1）。テーマ非依存 */
  --fs-hero:   24px;
  --fs-lg:     18px;
  --fs-md:     15px;
  --fs-base:   13px;
  --fs-sm:     11px;
  --fs-xs:     9.5px;
  /* 余白・角丸・影 */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;
  --r-card: 14px; --r-pill: 999px; --r-chip: 8px;
  --shadow-card: 0 2px 10px rgba(0,0,0,0.04);
  /* コンテンツ最大幅（#525 R1・iPad/PC で中央寄せ。モバイルは実質全幅） */
  --app-max: 1080px;
}
html[data-theme="dark"] {
  --bg:        #1c1917;
  --surface:   #27211e;
  --surface2:  #322b28;
  --surface3:  #3d3530;
  --border:    #48403b;
  --border2:   #3d3530;
  --text:      #f5f0ec;
  --text2:     #a09188;
  --text3:     rgba(245,240,236,0.50);
  --shadow:    0 8px 32px rgba(0,0,0,0.55);
  --shadow2:   rgba(0,0,0,0.72);
  --null-cell: #322b28;
  --cat-bg:    #2e2722;
  --handle:    #48403b;
  --chart-grid:rgba(255,255,255,0.06);
  --cost-line: rgba(255,250,245,0.65);
  --cost-text: rgba(255,250,245,0.80);
  --scrollbar-thumb:       rgba(255,255,255,0.15);
  --scrollbar-thumb-hover: rgba(255,255,255,0.26);
  --scrollbar-track:       transparent;
  --accent:    #cc785c;
  /* 意味色（#515 P1・ダーク・コントラスト確保） */
  --tone-good: #7aa978;
  --tone-ok:   #d8b25a;
  --tone-warn: #dd7a55;
  --tone-neu:  #a99e92;
  /* --vg-* は --tone-* のエイリアス（値は不変） */
  --vg-good:   var(--tone-good);
  --vg-ok:     var(--tone-ok);
  --vg-warn:   var(--tone-warn);
  --vg-neu:    var(--tone-neu);
}
/* セマンティックカラー（テーマ非依存・市場慣例＋状態色）。
   ハードコード hex を排し、意味で参照できるようトークン化（Design System 準拠）。 */
:root {
  --pos:     #FF3B30;  /* 上昇・含み益＝赤（日本市場慣例） */
  --neg:     #34C759;  /* 下落・含み損＝緑 */
  --danger:  #FF3B30;  /* エラー・破壊的操作 */
  --success: #34C759;  /* 成功・確定 */
  --warn:    #FF9F0A;  /* 警告・コード強調 */

  /* ── categorical シリーズ配色（Risk ドーナツ等・Claude ウォームトーン基調）── */
  --series-1:  #cc785c;
  --series-2:  #6a8caf;
  --series-3:  #c2a36b;
  --series-4:  #7fa885;
  --series-5:  #a878a8;
  --series-6:  #d09a4e;
  --series-7:  #5f9ea0;
  --series-8:  #bd6b6b;
  --series-9:  #8a9a5b;
  --series-10: #9d8df1;
  --series-11: #d4a0b8;
  --series-12: #7ba6c9;
  --series-unknown: #9ca3af;

  /* ── Wealth 資産種別配色（種別ごとに意味づけされた固定色） ── */
  --asset-equity:        #cc785c;
  --asset-fund:          #7ba0c4;
  --asset-pension:       #9c8fbc;
  --asset-cash:          #6fae86;
  --asset-insurance:     #d9a441;
  --asset-crypto:        #c98a5e;
  --asset-bond:          #b0b0b0;
  --asset-fx:            #8c8c8c;
  --asset-equity-margin: #e09070;
  --asset-points:        #c9c2b8;

  /* ── チャート線色 ── */
  --chart-ma-fast:    #5ac8fa;  /* 5日MA */
  --chart-ma-mid:     #2e90d8;  /* 200日MA */
  --chart-ma-slow:    #1a5fa0;  /* 50週MA */
  --chart-price-up:   #30D158;  /* iPhone Stocks 式・US式 上昇 */
  --chart-price-down: #FF453A;  /* iPhone Stocks 式・US式 下落 */
  --chart-cash:       #6fae86;  /* Wealth 現金比率チャート */

  /* ── セル文字色（輝度で選ぶコントラスト ink・テーマ非依存） ── */
  --ink-on-light:   #1C1C1E;
  --ink-on-dark:    #FFFFFF;
  --ink-on-light-2: rgba(0,0,0,0.55);
  --ink-on-dark-2:  rgba(255,255,255,0.82);
}
/* @media (prefers-color-scheme: dark) は app.js の applyTheme() が
   matchMedia で解決して data-theme="dark" を明示セットするため不要。
   システムテーマ追従は JS 側で行う（applyTheme / matchMedia listener）。 */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 16px;
  padding-top: 0;           /* トップ余白は .sticky-top が保持 */
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: -webkit-fill-available;
  user-select: none;
  -webkit-user-select: none;
}

#d3-load-error {
  position: fixed; inset: 0; background: var(--bg); z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; text-align: center; gap: 16px;
}
#d3-load-error h2 { color: var(--danger); font-size: 18px; }
#d3-load-error p  { color: var(--text2); font-size: 13px; line-height: 1.6; }
#d3-load-error code { color: var(--warn); background: var(--surface3); padding: 2px 6px; border-radius: 4px; }

/* アプリシェル: ヘッダ内側・stats・タブバー・各パネルを 1080px で中央寄せ（#525 R1）。
   sticky-top / body の背景は全幅のまま、左右 gutter は --bg で埋まる。モバイルは実質全幅で不変。 */
.header,
.stats-outer,
.tab-bar,
.tab-panel { max-width: var(--app-max); margin-inline: auto; }

.sticky-top {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: 4px;
  transition: box-shadow 0.2s;
}
.sticky-top.stuck {
  /* spread=-4px でサイドへのはみ出しを消し、下方向のみ影を出す */
  box-shadow: 0 4px 8px -4px rgba(0,0,0,0.15);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: nowrap;
  gap: 8px;
}
.header > div:first-child { min-width: 0; }
.title { font-size: 20px; font-weight: 700; letter-spacing: 0.3px; white-space: nowrap; }
.subtitle { font-size: 12px; color: var(--text2); margin-top: 3px; }

/* コントロール：横スクロール可能1行（nowrap統一） */
.controls {
  display: flex; flex-direction: row; flex-wrap: nowrap;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  align-items: center; gap: 6px; padding: 0; background: var(--bg);
  flex-shrink: 0;
}
.controls::-webkit-scrollbar { display: none; }

.btn {
  padding: 5px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.15s;
}
.btn:hover { background: var(--surface2); }
.btn.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.spin-anim { opacity: 0.7; cursor: default; }

.btn-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.btn-select:hover { background: var(--surface2); }

.countdown {
  font-size: 12px;
  color: var(--text2);
  min-width: 64px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.divider { display: none; }

/* ── Stats card (マネーフォワード式・横スクロールなし) ── */
.stats-outer { position: relative; margin-bottom: 20px; }
.eye-btn {  /* カード右上の金額マスク切替 */
  position: absolute; top: 10px; right: 10px; z-index: 1;
  width: 32px; height: 28px; justify-content: center;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text2); cursor: pointer; padding: 0; line-height: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s; display: flex; align-items: center;
}
.eye-btn:hover { color: var(--text); background: var(--surface3); }
.eye-btn.hidden { color: var(--accent); border-color: var(--accent); }

.stats {
  display: block; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
}

/* 主役: 運用資産総額 */
.stat-hero { display: flex; flex-direction: column; gap: 3px; }
.stat-hero-label { font-size: 11px; color: var(--text2); letter-spacing: 0.3px; }
.stat-hero-value { font-size: 26px; font-weight: 700; line-height: 1.15; letter-spacing: 0.5px; white-space: nowrap; }

/* サブ: 資産総額 / 投資用キャッシュ */
.stat-subrow { display: flex; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--border2); }
.stat-sub-item { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.stat-sub-item + .stat-sub-item { border-left: 1px solid var(--border2); padding-left: 14px; }
.stat-sub-item:first-child { padding-right: 14px; }
.stat-sub-label { font-size: 10px; color: var(--text2); letter-spacing: 0.3px; }
.stat-sub-value { font-size: 15px; font-weight: 600; white-space: nowrap; }
.stat-sub-pct { font-size: 12px; font-weight: 600; color: var(--text2); margin-left: 5px; }

.pos { color: var(--pos); }  /* プラス=赤（日本株市場慣例） */
.neg { color: var(--neg); }  /* マイナス=緑 */
.neu { color: var(--text2); }
.stat-fg { color: var(--text); }  /* stats バーの白文字（#309） */
.stat-src { display: inline-block; font-size: 9px; font-weight: 400; color: var(--text2); opacity: 0.6; letter-spacing: 0; margin-left: 6px; vertical-align: middle; }  /* MF実値タグ */

/* ── Period / Refresh switch ── */
.period-switch, .refresh-switch {
  display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  flex-wrap: nowrap; flex-shrink: 0;
}
.period-btn, .refresh-btn {
  padding: 4px 9px; border: none; border-right: 1px solid var(--border2);
  background: var(--surface); color: var(--text2); cursor: pointer;
  font-size: 12px; font-family: inherit; white-space: nowrap; flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.period-btn:last-child, .refresh-btn:last-child { border-right: none; }
.period-btn:hover, .refresh-btn:hover { background: var(--surface2); color: var(--text); }
.period-btn.active { background: var(--text); color: var(--bg); font-weight: 600; }
.refresh-btn.active { background: var(--text); color: var(--bg); font-weight: 600; }

.pnl-btn {
  padding: 4px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text2); cursor: pointer; font-size: 12px;
  font-family: inherit; white-space: nowrap; transition: background 0.12s, color 0.12s;
}
.pnl-btn:hover { background: var(--surface2); color: var(--text); }
.pnl-btn.active { background: var(--text); border-color: var(--border); color: var(--bg); font-weight: 600; }

.csv-btn {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text2); cursor: pointer; font-size: 12px;
  font-family: inherit; white-space: nowrap; transition: background 0.12s, color 0.12s;
}
.csv-btn:hover { background: var(--surface2); color: var(--text); }

/* Heatmap パネルを内部スクロール化し、body スクロールでヘッダーが
   タブバー上まで動かないようにする（list/watchlist と挙動を統一・#215） */
#panel-heatmap {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#heatmap-wrap { width: 100%; position: relative; margin-top: 0; }
#heatmap { width: 100%; display: block; border-radius: 6px; }
.cell-g { cursor: pointer; }
.cell-g rect { transition: opacity 0.1s; }
.cell-g:hover rect { opacity: 0.8; }
.cell-g text { pointer-events: none; }
.cat-label {
  fill: var(--text3);
  font-size: 11px; font-weight: 700;
  letter-spacing: 1.2px; text-transform: uppercase;
  dominant-baseline: hanging;
}
.lbl-sym { font-weight: 400; letter-spacing: -0.3px; text-anchor: middle; dominant-baseline: middle; }
.lbl-pct { font-weight: 300; text-anchor: middle; dominant-baseline: middle; }
.lbl-val { fill: rgba(255,255,255,0.55); text-anchor: middle; dominant-baseline: middle; }

.tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 13px;
  pointer-events: none;
  z-index: 9000;
  min-width: 280px;
  box-shadow: var(--shadow);
  display: none;
}
.tt-hdr {
  font-size: 15px; font-weight: 700;
  margin-bottom: 8px; padding-bottom: 7px;
  border-bottom: 1px solid var(--border2);
  display: flex; align-items: center; gap: 8px;
}
.tt-sym { font-size: 13px; color: var(--text2); font-weight: 400; }
.tt-row { display: flex; justify-content: space-between; gap: 14px; padding: 2.5px 0; }
.tt-label { color: var(--text2); white-space: nowrap; }
.tt-val { font-weight: 600; text-align: right; }
.tt-sep { border-top: 1px solid var(--border2); margin: 6px 0; }
.tt-hint { font-size: 11px; color: var(--text2); margin-top: 8px; text-align: center; }
/* Exposure 内訳ツールチップ行 */
.tt-risk-row {
  display: grid;
  grid-template-columns: 38px 1fr 60px 34px;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
}
.tt-risk-ticker {
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tt-risk-name {
  font-size: 10.5px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.tt-risk-bar-wrap {
  height: 4px;
  background: var(--border2);
  border-radius: 2px;
  overflow: hidden;
}
.tt-risk-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}
.tt-risk-pct {
  font-weight: 700;
  font-size: 11px;
  text-align: right;
  white-space: nowrap;
}

.footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
  gap: 6px;
}
.legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text2); }
.legend-bar { height: 9px; width: 160px; border-radius: 3px; background: linear-gradient(to right, #1B5E20, #A5D6A7, #E8E8ED, #EF9A9A, #C62828); }
.status-line { font-size: 11px; color: var(--text2); display: flex; align-items: center; gap: 5px; cursor: pointer; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); display: inline-block; }
.dot.red { background: var(--danger); }
.dot.yellow { background: var(--warn); }
.provider-health { font-size: 10px; color: var(--text3); white-space: nowrap; flex-shrink: 0; }
.provider-health.health-ok { color: var(--text3); }
.provider-health.health-warn { color: var(--warn); }

.ctrl-label { font-size: 12px; color: var(--text2); white-space: nowrap; flex-shrink: 0; }
.ctrl-group { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.btn-select.active { border-color: var(--text); color: var(--text); }

/* ── Theme toggle button ── */
.theme-btn {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text2); cursor: pointer;
  font-size: 13px; font-family: inherit; min-width: 36px; text-align: center;
  transition: background 0.12s, color 0.12s;
}
.theme-btn:hover { background: var(--surface2); color: var(--text); }

/* ── Hamburger menu ── */
#hm-menu-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
#hm-menu-btn {
  border: none;
  background: transparent;
  padding: 4px 6px;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  color: var(--text2);
  cursor: pointer;
  min-width: unset;
}
#hm-menu-btn:hover { color: var(--text); background: transparent; }
#hm-menu-btn .hm-bar,
#hm-menu-btn .hm-x {
  position: absolute;
  font-size: 24px;
  line-height: 1;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
#hm-menu-btn .hm-x {
  opacity: 0;
  transform: rotate(45deg) scale(0.5);
}
#hm-menu-btn.open .hm-bar {
  opacity: 0;
  transform: rotate(-45deg) scale(0.5);
}
#hm-menu-btn.open .hm-x {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* ── 非アクティブタブ ── */
.tab-btn.tab-disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
#hm-menu-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  flex-direction: column;
  min-width: 190px;
  box-shadow: 0 6px 20px var(--shadow2);
  z-index: 9999;
}
/* 自動更新セクション（メニュー内） */
.hm-refresh-row {
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hm-refresh-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text2);
  font-weight: 500;
}
.hm-refresh-btns {
  display: flex;
  gap: 4px;
}
.hm-refresh-btn {
  flex: 1;
  padding: 5px 2px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: background 0.1s;
  white-space: nowrap;
}
.hm-refresh-btn:hover { background: var(--surface3); }
.hm-refresh-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
#hm-menu-dropdown.open {
  display: flex;
}
.hm-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  min-width: unset;
  transition: background 0.1s;
}
.hm-menu-item:hover { background: var(--surface2); }
.hm-menu-item .hm-icon { font-size: 15px; flex-shrink: 0; width: 18px; text-align: center; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--shadow2);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 20px;
  width: min(700px, 95vw);
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 12px 40px var(--shadow2);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-sym { font-size: 14px; color: var(--text2); font-weight: 400; margin-left: 8px; }
.modal-close {
  cursor: pointer; font-size: 18px; color: var(--text2);
  padding: 2px 7px; border-radius: 4px; line-height: 1.4;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.range-btns { display: flex; gap: 5px; margin-bottom: 14px; flex-wrap: wrap; }
.range-btn {
  padding: 4px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.12s;
}
.range-btn:hover { background: var(--surface3); }
.range-btn.active { background: #007AFF; border-color: #007AFF; color: #fff; }
.chart-loading { text-align: center; padding: 60px 20px; color: var(--text2); font-size: 14px; }
.chart-error { text-align: center; padding: 60px 20px; color: var(--danger); font-size: 14px; }
.chart-stats {
  display: flex; gap: 14px 20px; font-size: 12.5px; color: var(--text2);
  margin-top: 12px; flex-wrap: wrap; align-items: center;
}
.chart-stats strong { font-weight: 600; color: var(--text); }
.chart-stats .pos  strong { color: var(--pos); }  /* プラス=赤 */
.chart-stats .neg  strong { color: var(--neg); }  /* マイナス=緑 */
#chart-svg { display: block; }

/* ── Stock List ── */
#stock-list-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 420px;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
#stock-list-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
#stock-list-wrap::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 3px; }
#stock-list-wrap::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
#stock-list-wrap::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ── Watchlist Table Wrap ── */
/* sticky-top（タイトル＋タブバー）が画面上に居るため、ここを内部スクロールに
   することで thead の position:sticky が wrap 内 top:0 に貼り付き正しく機能する。 */
#watchlist-table-wrap {
  max-height: calc(100dvh - 270px);
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
#watchlist-table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
#watchlist-table-wrap::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 3px; }
#watchlist-table-wrap::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
#watchlist-table-wrap::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

.sl-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-base);
  white-space: nowrap;
  table-layout: auto;
}
.sl-table th {
  padding: 8px 10px;
  text-align: right;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface3);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.sl-table th:first-child { text-align: left; }
.sl-th-center { text-align: center; }
.sl-table th.sort-asc::after  { content: ' ▲'; font-size: 9px; }
.sl-table th.sort-desc::after { content: ' ▼'; font-size: 9px; }
.sl-table td {
  padding: 6px 10px;
  text-align: right;
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--border2);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}
.sl-table td:first-child { text-align: left; }
.sl-table tr:last-child td { border-bottom: none; }
/* ── tr hover (bar stays as background-image, color is background-color) ── */
.sl-table tbody tr:hover { background-color: rgba(142,142,147,0.07); }
