/* ------------------------------------------------------------------
   配色トークン。ライト／ダークとも「選んだ値」で、自動反転はしない。
   data-theme（画面のトグル）が OS 設定より優先される。
------------------------------------------------------------------ */
:root {
  color-scheme: light;

  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px rgba(11, 11, 11, 0.04);

  /* 状態色（好調・不調）。必ず記号や語と併記して、色だけに意味を持たせない */
  --good: #0ca30c;
  --critical: #d03b3b;
  --tone-up: #006300;
  --tone-down: #b8302f;
  --warn-bg: #fdf3e3;
  --warn-border: #f0d5a8;
  --info-bg: #eef4fd;
  --info-border: #cfe0f7;

  /* カテゴリカル配色（アカウント・銘柄）。順番は固定で、循環させない */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --shadow: none;

    --good: #0ca30c;
    --critical: #d03b3b;
    --tone-up: #0ca30c;
    --tone-down: #e66767;
    --warn-bg: #2a2418;
    --warn-border: #4a3f28;
    --info-bg: #16202e;
    --info-border: #26364c;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --shadow: none;

  --good: #0ca30c;
  --critical: #d03b3b;
  --tone-up: #0ca30c;
  --tone-down: #e66767;
  --warn-bg: #2a2418;
  --warn-border: #4a3f28;
  --info-bg: #16202e;
  --info-border: #26364c;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

/* ------------------------------------------------------------------ 基本 */

* { box-sizing: border-box; }

/* hidden 属性は必ず効かせる。ブラウザ既定の [hidden]{display:none} は詳細度 0-1-0 で、
   .cards{display:grid} のようなクラス指定に負けて表示されたままになる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 17px; letter-spacing: 0.01em; }
h2 { font-size: 14px; letter-spacing: 0.02em; }

.muted { color: var(--text-muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 650; }

.tone-up { color: var(--tone-up); }
.tone-down { color: var(--tone-down); }
.tone-flat { color: var(--text-secondary); }

/* 再取得中は前の描画を薄く保つ（スケルトンでちらつかせない） */
body.is-loading .page { opacity: 0.62; transition: opacity 0.12s ease; }
.page { transition: opacity 0.2s ease; }

/*
 * 取得中にヘッダーの下端を流れる線。
 * 何割終わったかは分からない（外部 API 待ち）ので、進捗ではなく
 * 「動いている」ことだけを示す。位置はヘッダーの境界線に重ねる。
 */
.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  background: var(--surface-2);
}

.progress::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  background: var(--series-1);
  animation: pc-progress 1.1s ease-in-out infinite;
}

@keyframes pc-progress {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* 動きを減らす設定では、流さずに帯を出したままにする */
@media (prefers-reduced-motion: reduce) {
  .progress::after { animation: none; left: 0; width: 100%; opacity: 0.5; }
}

/*
 * 取得が長引くときだけ出す膜。線と違って「いま何をしているか」を言葉で示す。
 * <dialog> なので位置は既定の中央、背面は ::backdrop で暗くする。
 * 既定の枠・余白・背景は中身のピルに任せるので、ここで消しておく。
 */
.loadveil {
  border: 0;
  padding: 0;
  max-width: none;
  background: transparent;
  color: var(--text-primary);
  overflow: visible;
}

/* showModal が <dialog> 自身にフォーカスを移すので、そのままだと四角い枠が浮く。
   ここは押すところが無い（見せるだけの膜）ので、輪郭は出さない */
.loadveil:focus,
.loadveil:focus-visible { outline: none; }

/* .modal::backdrop（0.42）より薄くする。取得中は body.is-loading で
   本文が 0.62 まで落ちているので、同じ濃さを重ねると沈みすぎる */
.loadveil::backdrop { background: rgba(0, 0, 0, 0.22); }

/* 輪を左に、文言と補足を右に積む。補足が出ないうちは 1 行のまま */
.loadveil__box {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 460px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  font-size: 13px;
  font-weight: 600;
}

.loadveil__lines {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.loadveil__spinner {
  width: 15px;
  height: 15px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--series-1);
  animation: pc-spin 0.8s linear infinite;
}

@keyframes pc-spin { to { transform: rotate(360deg); } }

/* いつもより長引いたときだけ入る一言。空のうちは行を作らない */
.loadveil__hint {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-muted);
}

.loadveil__hint:empty { display: none; }

/* 動きを減らす設定では回さず、輪だけ出しておく */
@media (prefers-reduced-motion: reduce) {
  .loadveil__spinner { animation: none; }
}

/* ------------------------------------------------------------------ ヘッダ */

/* 操作と表示条件をまとめた固定ヘッダー。フィルタは下のすべてに効くので、
   ページを下まで見ている途中でも切り替えられるよう、一緒に貼り付けておく。

   広い画面ではタイトル・フィルタ・操作が 1 行に並ぶ。入り切らなくなると
   .filters の flex-basis を割るので、フィルタだけが次の行へ落ちる。 */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px 16px;
  padding: 10px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* 左右を同じだけ伸ばして、間に挟まれたフィルタを中央に置く。
   flex-basis を 0 にすると余白が左右へ等分され、中身の幅の差に引きずられない。
   ただし min-width: auto があるので、片側が中身より狭くはならない
   （操作ボタンのほうがタイトルより広いぶん、中央から少し左に寄る） */
.topbar__title { flex: 1 1 0; display: flex; align-items: center; gap: 8px; }
.topbar__actions { flex: 1 1 0; justify-content: flex-end; }

.topbar__sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar__actions { display: flex; gap: 8px; align-items: center; }
.topbar__title h1 { white-space: nowrap; }

/* ロゴ。線は currentColor なので、配色を切り替えても文字と同じ色で付いてくる */
.topbar__logo {
  width: 22px;
  height: 22px;
  flex: none;
  color: var(--text-primary);
}

/* ------------------------------------------------------------------ ページ */

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ------------------------------------------------------------------ フィルタ行 */

/* ヘッダーの中央。伸ばさない（伸ばすと中央でなく左詰めになる）。
   入り切らない分は横に流す */
.filters {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px 18px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }
.filters__group { display: flex; align-items: center; gap: 8px; flex: none; }

.filters__label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ヘッダーの中では折り返さない（行が二重になると sticky が縦を食う） */
.filters .chips { flex: none; flex-wrap: nowrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.chip:hover { background: var(--surface-2); }

.chip.is-on {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
  font-weight: 600;
}

.chip:not(.is-on) { opacity: 0.55; }

.chip__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  margin-right: 2px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
}

.segmented__btn {
  padding: 5px 12px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  /* 縮めない。狭い画面で潰れると「1ヶ月」が 1 文字ずつ縦に折り返してしまう */
  flex: none;
  white-space: nowrap;
}

.segmented__btn:last-child { border-right: 0; }
.segmented__btn:hover { background: var(--surface-2); }

.segmented__btn.is-on {
  background: var(--text-primary);
  color: var(--surface-1);
  font-weight: 600;
}

.segmented--sm .segmented__btn { padding: 3px 10px; font-size: 12px; }

/* ------------------------------------------------------------------ ボタン */

.btn {
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  /* 縮めない。ヘッダーで縮められると「銘柄を / 追加」と 2 行に割れる */
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .chip:focus-visible, .segmented__btn:focus-visible,
.swatch:focus-visible, .suggest__item:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--text-primary);
  color: var(--surface-1);
  border-color: var(--text-primary);
  font-weight: 600;
}

.btn--primary:hover { opacity: 0.86; background: var(--text-primary); }
.btn--danger { color: var(--tone-down); border-color: var(--tone-down); }
.btn--danger:hover { background: var(--warn-bg); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn--sm { padding: 3px 10px; font-size: 12px; }
.btn--icon { width: 34px; padding: 6px 0; text-align: center; }

.btn:disabled { cursor: default; opacity: 0.65; }
.btn:disabled:hover { background: var(--surface-1); }

/* ------------------------------------------------------------------ お知らせ */

.alert {
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 8px;
}

.alert--warn { background: var(--warn-bg); border-color: var(--warn-border); }
.alert--info { background: var(--info-bg); border-color: var(--info-border); }

/* ------------------------------------------------------------------ サマリー */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat__label { font-size: 12px; color: var(--text-muted); }

.stat__value {
  font-size: 26px;
  font-weight: 620;
  line-height: 1.25;
  margin-top: 2px;
  letter-spacing: -0.01em;
}

.stat__sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat--up .stat__value, .stat--up .stat__sub { color: var(--tone-up); }
.stat--down .stat__value, .stat--down .stat__sub { color: var(--tone-down); }

/* ------------------------------------------------------------------ カード枠 */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

/* 見出しと補足をひとまとまりにして左へ。card__head は space-between なので、
   これをやらないと 3 つ目の要素が真ん中に置かれてしまう */
.card__headline {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.card__hint { font-size: 12px; color: var(--text-muted); }
.card__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 16px;
}

/* グリッドの子は既定が min-width:auto なので、中の表の幅にそのまま押し広げられて
   ページごと横に溢れる。0 にして .table-scroll 側で横スクロールさせる */
.grid-2 > * { min-width: 0; }

/* 右側を出さないとき（アカウントが 1 つのとき）は 1 カラムにする */
.grid-2--single { grid-template-columns: 1fr; }

/* ------------------------------------------------------------------ チャート */

.chart-box { width: 100%; }

.pc-chart__svg { display: block; width: 100%; height: auto; }
.pc-chart__svg:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.pc-chart__tick { font-size: 11px; font-variant-numeric: tabular-nums; }
.pc-chart__endlabel { font-size: 11px; font-weight: 650; }

.pc-chart__note {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.pc-chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 6px;
}

.pc-legend__item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }

.pc-legend__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.pc-chart__empty, .empty {
  margin: 0;
  padding: 28px 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* 構成比（銘柄別）の資産クラス絞り込み。選んだクラスが全体の何 % かを末尾に添える */
.composition-classes { align-items: center; margin-bottom: 14px; }
.composition-classes .muted { font-size: 12px; margin-left: 2px; }

.pc-donut { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.pc-donut__svg { flex: none; }
.pc-donut__seg { transition: opacity 0.12s ease; cursor: pointer; }
.pc-donut__seg.is-dim { opacity: 0.4; }
.pc-donut__seg:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

.pc-donut__total { font-size: 17px; font-weight: 650; }
.pc-donut__sub { font-size: 10.5px; }

.pc-donut__legend { flex: 1 1 220px; min-width: 200px; display: flex; flex-direction: column; gap: 3px; }

.pc-donut__row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto 52px;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  padding: 2px 0;
}

.pc-donut__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pc-donut__namesub { font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.pc-donut__value { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.pc-donut__pct { font-variant-numeric: tabular-nums; text-align: right; color: var(--text-muted); }

.pc-spark__svg { display: block; width: 100%; height: auto; }
.pc-spark__empty { color: var(--text-muted); font-size: 12px; padding: 12px 0; }

.pc-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
  max-width: 280px;
}

.pc-tooltip.is-visible { opacity: 1; }
.pc-tooltip__title { font-weight: 650; margin-bottom: 4px; }

.pc-tooltip__row {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.pc-tooltip__row b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* その日の前日比。金額の右にぶら下げる */
.pc-tooltip__delta {
  min-width: 6.2em;
  font-size: 11px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.pc-tooltip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

/* ------------------------------------------------------------------ 銘柄カード */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 12px;
}

.cards .empty { grid-column: 1 / -1; }

/* 資産クラスの見出し（グリッド全幅にまたがる） */
.cards__group {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0 -2px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 650;
}

.cards__group:first-child { margin-top: 0; }
.cards__groupcount { font-weight: 400; font-size: 11.5px; color: var(--text-muted); }

.cards__groupsum {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.cards__groupgain { font-size: 12px; font-variant-numeric: tabular-nums; }

.hcard {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 13px;
  background: var(--surface-1);
  display: flex;
  flex-direction: column;
}

.hcard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
}

/* 持ち主。複数人で持っている銘柄は横に並べ、入り切らなければ折り返す */
.hcard__accounts {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-width: 0;
}

.hcard__account { display: inline-flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.hcard__accountmore { color: var(--text-muted); }

.hcard__type {
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 10.5px;
}

.hcard__symbol { font-size: 17px; font-weight: 680; margin-top: 6px; letter-spacing: 0.01em; }

.hcard__name {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hcard__error { font-size: 11.5px; color: var(--tone-down); margin-top: 4px; }

.hcard__price { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.hcard__pricevalue { font-size: 18px; font-weight: 620; font-variant-numeric: tabular-nums; }

.delta { font-size: 12px; font-weight: 620; font-variant-numeric: tabular-nums; }
.hcard__pricetag { font-size: 10.5px; color: var(--text-muted); }

/*
 * 表示通貨に直した前日比。上の率は建値通貨なので、円で見ていると
 * 符号が逆になることがある（株価が上がった日に円高だと円建てでは減る）。
 * 換算が起きている銘柄にだけ出る。
 */
.hcard__dayfx { margin-top: 3px; font-size: 11px; font-variant-numeric: tabular-nums; }

.hcard__spark { margin-top: 6px; }
.hcard__period { font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }

.hcard__facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 8px 0 0;
  font-size: 12.5px;
}

.hcard__facts dt { color: var(--text-muted); }
.hcard__facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.hcard__memo {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

/* 口座種別ごとの内訳 */
.hcard__lots {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.hcard__lotscap { font-size: 10.5px; color: var(--text-muted); margin-bottom: 3px; }

.hcard__lot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  padding: 3px 4px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 11.5px;
  text-align: left;
  cursor: pointer;
}

.hcard__lot:hover { background: var(--surface-2); }
.hcard__lot:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.hcard__lotname { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 複数人で持っている銘柄の内訳行に付く持ち主の色。文字と同じ行に収める */
.hcard__lotname .chip__dot { margin-right: 5px; }
.hcard__lotqty { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.hcard__lotgain { font-variant-numeric: tabular-nums; }

.hcard__edit {
  align-self: flex-end;
  margin-top: auto;
  font-size: 11.5px;
  padding: 3px 8px;
}

/* ------------------------------------------------------------------ 表 */

.table-scroll { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}

.table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11.5px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--axis);
  background: var(--surface-1);
}

.table th.num { text-align: right; }
.table td { padding: 6px 10px; border-bottom: 1px solid var(--grid); }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num { font-variant-numeric: tabular-nums; }
.table tfoot td { border-bottom: 0; border-top: 1px solid var(--axis); font-weight: 620; }
.table--compact td, .table--compact th { padding: 5px 8px; }
.table__note { font-size: 11.5px; color: var(--text-muted); margin: 8px 0 0; }

/* ------------------------------------------------------------------ ダイアログ */

.modal {
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 0;
  background: var(--surface-1);
  color: var(--text-primary);
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal::backdrop { background: rgba(0, 0, 0, 0.42); }
.modal__form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal__title { font-size: 15px; }
.modal__lead { margin: 0; font-size: 12px; color: var(--text-muted); }
.modal__actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.modal__spacer { flex: 1; }

.modal__error {
  margin: 0;
  font-size: 12.5px;
  color: var(--tone-down);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 7px 10px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 12px; color: var(--text-secondary); }
.field__hint { margin: 0; font-size: 11.5px; color: var(--text-muted); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 130px; }
.field--narrow { flex: 0 0 110px; }

.input {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  width: 100%;
}

.input:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

.input--sm { width: auto; padding: 5px 8px; font-size: 13px; }

/* 年を選んでいるときは、期間タブの代わりにこちらが有効だと分かるようにする */
.input--sm.is-on {
  background: var(--text-primary);
  color: var(--surface-1);
  border-color: var(--text-primary);
  font-weight: 600;
}
.search { display: flex; gap: 8px; }
.search .input { flex: 1; }

.suggest {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  max-height: 210px;
  overflow-y: auto;
  background: var(--surface-1);
}

.suggest__item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-bottom: 1px solid var(--grid);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.suggest li:last-child .suggest__item { border-bottom: 0; }
.suggest__item:hover { background: var(--surface-2); }
.suggest__item strong { flex: none; min-width: 74px; }
.suggest__item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest__item em { flex: none; color: var(--text-muted); font-style: normal; font-size: 11px; }

/* ---- 銘柄をまとめて追加 ---- */

/* 入れ方の切り替え。ダイアログの中では内容ぶんの幅に留める */
#add-mode-tabs { align-self: start; }

/* 貼り付けた内容と、その解釈を並べて見るので、通常のダイアログより広くする */
.modal--wide { width: min(720px, calc(100vw - 32px)); }

.textarea {
  min-height: 128px;
  max-height: 36vh;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); }
.check input { accent-color: var(--series-1); }

.prompt {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.prompt__summary { list-style: none; cursor: pointer; font-size: 12.5px; color: var(--text-secondary); }
.prompt__summary::-webkit-details-marker { display: none; }
.prompt__summary::before { content: '▸ '; }
.prompt[open] .prompt__summary::before { content: '▾ '; }
.prompt[open] .prompt__summary { margin-bottom: 8px; }
.prompt .field__hint { margin-bottom: 8px; }

.prompt__text {
  margin: 0 0 8px;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  background: var(--surface-2);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

/* 貼り付けた内容をどう解釈したか。登録前にここで確かめてもらう */
.bulkprev {
  display: flex;
  flex-direction: column;
  max-height: 30vh;
  overflow-y: auto;
  font-size: 12px;
}

.bulkprev:empty { display: none; }
.bulkprev__head { margin: 0 0 4px; font-size: 11.5px; color: var(--text-muted); }

.bulkrow {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px solid var(--grid);
}

.bulkrow:last-child { border-bottom: 0; }
.bulkrow__main { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulkrow__tag { flex: none; font-size: 11px; color: var(--text-muted); }
.bulkrow--skip { opacity: 0.55; }
.bulkrow--bad { color: var(--tone-down); }

.acclist { display: flex; flex-direction: column; gap: 8px; }

.accrow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.accrow .input { flex: 1 1 150px; }
.swatches { display: flex; gap: 3px; }

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch.is-on { border-color: var(--text-primary); }

/* ------------------------------------------------------------------ 画面幅 */

/* 3 つを 1 行に並べるには 1425px 前後（タイトル 157 + フィルタ 897 + 操作 315 + 余白）が要る。
   それより狭いときはタイトルと操作を上、フィルタを下に分ける（order で並べ替えるだけ）。
   閾値を刻んでおかないと「上がタイトルとフィルタ、下が操作だけ」という半端な形になる */
@media (max-width: 1439px) {
  .topbar__actions { order: 0; }
  .filters { order: 1; flex: 1 1 100%; }
}

@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .topbar, .page { padding-left: 14px; padding-right: 14px; }
  .stats { grid-template-columns: 1fr; }
  .filters { gap: 14px; padding-bottom: 2px; }
  .chip, .segmented, .input--sm { flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------------------------ サイトフッター */

/* ------------------------------------------------------------------ 広告枠 */

/*
 * 本文とフッターの間に 1 枠だけ。本文カラムと幅を揃える。
 * min-height を置いているのは、読み込まれた瞬間にフッターが下へ飛ぶのを防ぐため
 * （枠が空のときは PHP 側で要素ごと出さないので、この高さは確保されない）。
 */
.adslot {
  max-width: 1320px;
  margin: 8px auto 0;
  padding: 0 24px;
  min-height: 120px;
}

.adslot__label,
.adslot__note {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
}

.adslot__label { margin-bottom: 4px; }
.adslot__note { margin-top: 4px; }

/* 本文の途中に入る枠は .page の中なので、左右の余白は親に任せる */
.page > .adslot {
  max-width: none;
  margin: 0;
  padding: 0;
}

/* ------------------------------------------------------------------ 紹介リンク */

/*
 * 広告と違い、文脈の中に置く。目立たせすぎず、かといって隠さない。
 * PR 表記は景表法のステマ規制で必須。小さく添えるのではなく先頭に置く。
 */
.promo {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.7;
}

.promo__pr {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
}

.promo a { color: var(--series-1); }
.promo__placeholder { color: var(--text-muted); text-decoration: underline dashed; }

/* 画像バナーの場合。狭い画面でははみ出させず、幅に合わせて縮める */
.promo--banner { text-align: center; }
.promo--banner .promo__pr { display: block; width: fit-content; margin: 0 auto 8px; }
.promo--banner img { display: block; margin: 0 auto; max-width: 100%; height: auto; }

/* CSP を script-src / style-src とも 'self' に保つため、インライン style を置かない。
   ここは元々 HTML の style 属性で書いていたもの */
.adsbygoogle--block { display: block; }
.pc-crosshair { cursor: crosshair; }
.topbar__home { color: inherit; text-decoration: none; }

/* ロゴと名前をまとめてトップへのリンクにする。押せることが分かるよう下線を出す */
.topbar__brand { display: flex; align-items: center; gap: 8px; }
.topbar__brand:hover h1 { text-decoration: underline; }

.promo__bannerbox {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  margin: 0 auto;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-muted);
  font-size: 12px;
}

/* 配置の確認用。実際の広告が入ると、この箱の代わりに同じ場所へ表示される */
.adslot__preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 250px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
}

.sitefoot {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sitefoot__links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: center;
}

.sitefoot a { color: inherit; }
.sitefoot a:hover { color: var(--text-primary); }

/* ------------------------------------------------------------------ 文書ページ（規約など） */

.doc {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

.doc h1 { font-size: 20px; margin-bottom: 4px; }
.doc h2 {
  font-size: 15px;
  margin: 28px 0 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.doc h2:first-of-type { border-top: 0; padding-top: 0; }

/* h2 の中の小見出し。h2 と違って区切り線は引かず、間隔だけで括る */
.doc h3 { font-size: 14px; margin: 20px 0 4px; }

.doc p, .doc li { line-height: 1.85; }
.doc p { margin: 8px 0; }
.doc ul, .doc ol { margin: 8px 0; padding-left: 1.4em; }
.doc li { margin: 4px 0; }

/* 使い方で出てくるティッカーなど。地の文と見分けが付けばよい */
.doc code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
}

.doc__meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 24px;
}

.doc__note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 16px 0;
}

.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}
.doc th, .doc td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.doc th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }

@media (max-width: 620px) {
  .sitefoot, .doc, .adslot { padding-left: 14px; padding-right: 14px; }
}

/* ------------------------------------------------------------------ 狭い画面の調整 */

@media (max-width: 620px) {
  .topbar { gap: 10px; }
  .topbar__title h1 { font-size: 15px; }

  /* 登録データのボタン群は横に流して、はみ出したらスクロールさせる */
  .card__actions {
    flex-wrap: wrap;
    gap: 6px;
  }
}

/* ホーム画面から起動したときは、上下の安全領域を避ける */
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .sitefoot { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
}

/* ------------------------------------------------------------------ 同期ダイアログ */

.syncbox {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.7;
}

.syncbox--warn { border-color: var(--series-2); }
.syncbox--ok { border-color: var(--series-3); }
.syncbox__row { display: flex; justify-content: space-between; gap: 12px; }
.syncbox__row + .syncbox__row { margin-top: 4px; }
.syncbox__label { color: var(--text-muted); }

#f-sync-mycode, #f-sync-handoff-code, #f-sync-handoff {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

/* 手動で同期したときの結果。説明文と地続きだと、押した結果だと気づけない */
.syncnote {
  margin: 8px 0 0;
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  font-size: 13px;
  color: var(--text-secondary);
}

/*
 * 引き継ぎコードの QR。
 * 画面が暗い配色でも明暗を反転させない（反転した QR は読めない端末が多い）ため、
 * 枠ごと白のまま置く。
 */
.qrbox {
  width: 200px;
  max-width: 100%;
  margin: 10px auto;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  line-height: 0;
}

.qrbox:empty { display: none; }

/* ------------------------------------------------------------------ 同期ボタン（topbar） */

.btn--sync { display: inline-flex; align-items: center; gap: 6px; }

.btn__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--text-muted);
}
.btn__dot--ok   { background: var(--series-3); }               /* 同期済み */
.btn__dot--warn { background: var(--series-2); }               /* 未送信・ロック中 */
.btn__dot--busy { background: var(--series-1); animation: pc-pulse 1s ease-in-out infinite; }

@keyframes pc-pulse { 50% { opacity: 0.25; } }

/* 競合したときの選択肢 */
.alert__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn--sm { padding: 4px 10px; font-size: 12px; }

@media (max-width: 620px) {
  /* topbar に 3 つ目のボタンが入るので、同期はアイコンだけにする */
  .btn--sync .btn__text { display: none; }
  .btn--sync::before { content: '⇅'; }
  .btn--sync { padding-left: 8px; padding-right: 8px; }
}

/* ------------------------------------------------------------------ 補助表示 */

/* サマリーの直下。数字がいつ時点で、何を前提にした値かを示す */
.datameta {
  margin: -8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}



/* ------------------------------------------------------------------ その他メニュー（topbar） */

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }

.menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  padding: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 30;
  display: flex;
  flex-direction: column;
}

.menu__item {
  appearance: none;
  background: none;
  border: 0;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font: inherit;
  color: var(--text-primary);
  cursor: pointer;
}
.menu__item:hover { background: var(--surface-2); }

.menu__sep { border: 0; border-top: 1px solid var(--border); margin: 4px 6px; }

/* 「銘柄を追加」の ＋ は狭い画面でラベルの代わりに使う */
.btn--add { display: inline-flex; align-items: center; gap: 4px; }
.btn__plus { font-weight: 700; }

@media (max-width: 620px) {
  /* topbar のボタンはアイコンだけにして 1 行に収める */
  .btn--add .btn__text { display: none; }
  .btn--add { padding-left: 9px; padding-right: 9px; }
}

/* ------------------------------------------------------------------ 初回の案内 */

.modal--onboard { width: min(520px, calc(100vw - 32px)); }

.onboard__step { display: flex; flex-direction: column; gap: 12px; }

/* 今どこにいるか。三段しかないので、番号を書かずに帯の色だけで示す */
.steps { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; }
.steps__item { flex: 1; height: 3px; border-radius: 2px; background: var(--border); }
.steps__item.is-on { background: var(--text-primary); }

.onboard__list {
  margin: 0;
  padding-left: 1.15em;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.onboard__list li { line-height: 1.55; }

/* 保存先の話と再表示の案内。読み飛ばされると困るので、地の文から浮かせる */
.onboard__note {
  margin: 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* ------------------------------------------------------------------ QR の読み取り */

.scan { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }

/*
 * カメラの映像。縦横比は端末によって違うので、枠のほうを正方形にして中身を切り抜く。
 * 画面いっぱいに広げない（同期ダイアログの中に収める）。
 */
.scan__view {
  position: relative;
  overflow: hidden;
  width: min(320px, 100%);
  margin: 8px auto 0;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #000;
  aspect-ratio: 1 / 1;
}
.scan__view video { width: 100%; height: 100%; object-fit: cover; display: block; }

/* 中央に狙いを示す枠。どこに向ければよいかが分かる */
.scan__frame {
  position: absolute;
  inset: 18%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

/* ------------------------------------------------------------------ 記事 */

/* いまどこにいるか。記事は検索から直接来るので、上位への道を必ず出す */
.crumb {
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.crumb a { color: var(--text-secondary); }

/* 見出しの直後に置く導入文。本文より少し大きくして、読むかどうかを判断させる */
.article__lead {
  margin: 16px 0 28px;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.9;
}

/* 一覧 */
.article__list { margin: 24px 0 0; padding: 0; list-style: none; }
.article__list > li {
  padding: 18px 0;
  border-top: 1px solid var(--border);
}
.article__list > li:last-child { border-bottom: 1px solid var(--border); }

.article__title {
  font-size: 16px;
  font-weight: 650;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 1.6;
}
.article__title:hover { text-decoration: underline; }
.article__excerpt { margin: 6px 0 4px; color: var(--text-secondary); font-size: 13px; }
.article__date { margin: 0; color: var(--text-muted); font-size: 12px; }

/*
 * 記事の末尾。読み終えた人の行き先を用意しないと、そこで終わってしまう。
 * 本文と地続きに見えないよう、色を変えて区切る。
 */
.article__cta {
  margin: 40px 0 8px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.article__cta p { margin: 0 0 10px; }
.article__cta p:last-child { margin-bottom: 0; }

.article__more { margin: 12px 0 0; padding: 0; list-style: none; }
.article__more li { padding: 12px 0; border-top: 1px solid var(--border); }
.article__more a { display: block; font-weight: 600; }
.article__more .muted { display: block; margin-top: 3px; font-size: 12.5px; }
