:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --text: #1a1a1a;
    /* #6b7280 は --bg 上で約 4.3:1 となり WCAG AA（4.5:1）未満 */
    --text-muted: #4b5563;
    --border: #e5e7eb;
    /* 旧 #0d9488 は白文字・薄い背景上の文字いずれも AA 未満 */
    --accent: #0f766e;
    --accent-pressed: #115e59;
    --accent-soft: #ccfbf1;
    --danger: #b91c1c;
    --profit: #0f766e;
    --loss: #b91c1c;
    --choice-bg: #f8fafc;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    --radius: 12px;
    --app-max: 520px;
    --header-pad: 14px;
    /* サマリー等のインセット余白（一覧のフルブリード打ち消しにも使う） */
    --view-pad-x: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-h: 44px;

    /*
      一覧UIデザインシステム（ホーム / 銘柄タブ / 銘柄詳細 / 展開パネル共通）
      カード枠なし・フル幅リスト。画面差分はこのトークンを上書きするだけにする。
    */
    --list-pad-x: 16px;
    --list-row-pad-y: 2px;
    --list-row-min-h: 48px;
    --list-font: 0.875rem;
    --list-font-sub: 0.75rem;
    --list-font-head: 0.6875rem;
    --list-font-group: 0.8125rem;
    --list-font-meta: 0.75rem;
    --list-line: 1px solid var(--border);
    --list-row-hover: #f8fafc;
    --list-panel-bg: #f8fafc;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family:
        "Hiragino Sans",
        "Hiragino Kaku Gothic ProN",
        "Noto Sans JP",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* App shell */
.kabu-app {
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    width: min(100%, var(--app-max));
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    transform: translateY(var(--app-offset-y, 0px));
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--border);
}

/* モーダル表示中は translate 追従を止め、背後のスクロール伝播も抑える */
.kabu-app.dialog-open {
    transform: none;
    overscroll-behavior: none;
    touch-action: manipulation;
}

html.kabu-dialog-open,
html.kabu-dialog-open body {
    overflow: hidden;
    overscroll-behavior: none;
}

.kabu-header {
    flex-shrink: 0;
    padding: 8px var(--header-pad) 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.kabu-header__top {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
}

.page-heading {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-align: center;
    line-height: 1.35;
    padding: 0 76px;
}

.kabu-header__actions {
    position: absolute;
    right: -4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 0;
}

.help-open-btn,
.settings-open-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.help-open-btn svg,
.settings-open-btn svg {
    width: 20px;
    height: 20px;
}

.help-open-btn:hover,
.settings-open-btn:hover {
    background: var(--choice-bg);
    color: var(--text);
}

.help-open-btn:focus-visible,
.settings-open-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.page-lead {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.4;
}

/* ホームのサマリー縮小中のみリードを隠す（銘柄タブでは表示のまま） */
.kabu-app:has(.view-home.is-active.is-summary-compact) .page-lead {
    display: none;
}

.kabu-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: var(--bg);
}

.view {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px var(--view-pad-x) 20px;
}

/* 一覧だけ view 左右余白を打ち消し、アプリ幅いっぱいに広げる */
.list-bleed {
    margin-left: calc(-1 * var(--view-pad-x));
    margin-right: calc(-1 * var(--view-pad-x));
}

.view.is-active {
    display: flex;
}

.view-detail {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--bg);
    overflow: hidden;
    padding-bottom: 0;
}

/*
  ホーム / 銘柄タブの責務分離:
  - 上部固定帯（サマリー・注意書き・売却期間・検索・一覧ヘッダ）はスクロールしない
  - .home-body / .stocks-body … 一覧・空状態・ガイド・フッターを縦スクロール
  - .stocks-actions … 下部固定の追加ボタン帯
*/
.view-home,
.view-stocks {
    overflow: hidden;
    padding-bottom: 0;
}

.home-fixed {
    flex-shrink: 0;
    /*
      サマリー本文 1rem に対し注記 0.6875rem（= 11/16）の比を維持。
      コンパクト時も同じ比で追従する。
    */
    --summary-value-size: 1rem;
    --summary-label-size: 0.8125rem;
    --summary-muted-size: 0.875rem;
    --summary-note-size: calc(var(--summary-value-size) * 0.6875);
}

.view-home.is-summary-compact .home-fixed {
    --summary-value-size: 0.8125rem;
    --summary-label-size: 0.6602rem; /* 0.8125 × 0.8125 */
    --summary-muted-size: 0.7109rem; /* 0.8125 × 0.875 */
}

.home-body,
.stocks-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    /*
      フルブリードは overflow を持つこの要素自体に負マージンを当てる。
      .stock-table 側だと overflow-x: hidden にクリップされ、白背景が内側に残る。
    */
    margin-left: calc(-1 * var(--view-pad-x));
    margin-right: calc(-1 * var(--view-pad-x));
}

.view-stocks .search-bar {
    flex-shrink: 0;
}

.stocks-list-header {
    flex-shrink: 0;
    margin-bottom: 6px;
}

.stock-list-scroll {
    /* 親(.home-body / .stocks-body)側でスクロールするため、内側は流すだけ */
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
}

.stocks-actions {
    flex-shrink: 0;
    padding: 10px 0 12px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

/* Summary（カード感を排した線区切り） */
.summary-card {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin-bottom: 8px;
}

#home-summary {
    position: relative;
    padding-right: 36px;
}

.summary-mask-toggle {
    position: absolute;
    top: 0;
    right: -6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: -4px 0 0;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.summary-mask-toggle:hover {
    background: var(--choice-bg);
    color: var(--text);
}

.summary-mask-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.summary-mask-toggle__icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.summary-mask-toggle__icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.disclaimer-note {
    margin: 0 0 10px;
    padding: 0;
    color: var(--text-muted);
    font-size: var(--summary-note-size, 0.6875rem);
    line-height: 1.45;
}

.view-home.is-summary-compact .disclaimer-note {
    display: none;
}

.summary-rows {
    display: block;
}

.view-home.is-summary-compact .summary-rows {
    display: none;
}

.summary-compact {
    display: none;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 6px;
    min-height: 28px;
    padding: 2px 0 4px;
    font-variant-numeric: tabular-nums;
}

.view-home.is-summary-compact .summary-compact {
    display: flex;
}

.view-home.is-summary-compact .summary-mask-toggle {
    top: 50%;
    transform: translateY(-50%);
    margin-top: 0;
}

.summary-compact__cluster {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 6px;
    min-width: 0;
}

.summary-compact__label {
    color: var(--text-muted);
    font-size: var(--summary-label-size, 0.8125rem);
    font-weight: 600;
}

.summary-compact__rate {
    color: var(--text-muted);
    font-size: var(--summary-value-size, 1rem);
    font-weight: 700;
}

.summary-compact__rate .summary-value {
    font-size: inherit;
}

.summary-compact__sep {
    color: var(--text-muted);
    font-size: var(--summary-label-size, 0.8125rem);
    font-weight: 600;
}

.summary-value--holding {
    font-size: var(--summary-muted-size, 0.875rem);
    font-weight: 600;
    color: var(--text);
}

.summary-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
}

.summary-row + .summary-row {
    border-top: 1px solid var(--border);
}

.summary-row--muted .summary-value {
    font-size: var(--summary-muted-size, 0.875rem);
    font-weight: 600;
    color: var(--text);
}

.summary-label {
    color: var(--text-muted);
    font-size: var(--summary-label-size, 0.8125rem);
}

.summary-value {
    font-size: var(--summary-value-size, 1rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.summary-value.is-profit {
    color: var(--profit);
}

.summary-value.is-loss {
    color: var(--loss);
}

.summary-value.is-masked {
    color: var(--text);
    font-weight: 700;
}

.section-title {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: nowrap;
}

.section-title-cluster {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    flex-shrink: 0;
    min-width: 0;
}

.section-title-row .section-title {
    margin-bottom: 0;
    flex-shrink: 0;
}

.favorites-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    min-height: 44px;
    margin: 0;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.favorites-filter-toggle__icon {
    display: inline-flex;
    width: 14px;
    height: 14px;
    color: inherit;
}

.favorites-filter-toggle__icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linejoin: round;
}

.favorites-filter-toggle[aria-pressed='true'] {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #b45309;
}

.favorites-filter-toggle[aria-pressed='true'] .favorites-filter-toggle__icon svg {
    fill: currentColor;
}

.favorites-filter-toggle:hover {
    color: var(--text);
}

.favorites-filter-toggle[aria-pressed='true']:hover {
    color: #92400e;
}

.favorites-filter-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.home-list-header {
    margin-bottom: 6px;
}

/* 売却期間フィルター（ホーム固定帯）
   min-height 44px のタッチ領域内で、キャプション＋期間を自然折り返し。
   カスタム日付は省略（…）せず、幅に応じて折り返す。 */
.period-filter__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    /* 余白まで伸ばさず中身幅に（ホーム／銘柄は section-title-row の space-between で右寄せ） */
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    padding: 4px 2px 4px 4px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: right;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.period-filter__trigger:hover {
    background: var(--choice-bg);
}

.period-filter__trigger:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.period-filter__trigger[aria-expanded='true'] {
    background: var(--choice-bg);
}

.period-filter__text {
    min-width: 0;
    max-width: 100%;
    line-height: 1.25;
    text-align: right;
    /* inline の自然折り返しで「売却期間：日付」を高さ内に収める */
}

.period-filter__caption {
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.period-filter__range {
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.period-filter__chevron {
    flex-shrink: 0;
    align-self: center;
    color: var(--text-muted);
    font-size: 0.625rem;
    line-height: 1;
}

.period-filter__panel {
    width: 100%;
    margin-top: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.period-filter__panel[hidden] {
    display: none !important;
}

.period-filter__option {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.period-filter__option:hover {
    background: var(--choice-bg);
}

.period-filter__option:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.period-filter__option.is-selected {
    background: var(--accent-soft);
    color: var(--accent-pressed);
    font-weight: 700;
}

.period-filter__custom {
    margin-top: 4px;
    padding: 8px 8px 10px;
    border-top: 1px solid var(--border);
}

.period-filter__custom[hidden] {
    display: none !important;
}

.period-filter__custom-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.period-filter__date-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.period-filter__date-input {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 1rem;
}

.period-filter__error {
    margin: 0 0 8px;
    color: var(--danger);
    font-size: 0.75rem;
    line-height: 1.4;
}

.period-filter__error[hidden] {
    display: none !important;
}

@media (min-width: 360px) {
    .period-filter__custom-fields {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

/* Stock table list (home + stocks tab) — カード枠なしのフル幅リスト */
.stock-table {
    flex: 0 0 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: none;
    border-radius: 0;
    border-top: var(--list-line);
    margin-bottom: 0;
}

.view-home .stock-table,
.view-stocks .stock-table {
    /* ブリードは .home-body / .stocks-body 側で行う */
    margin-left: 0;
    margin-right: 0;
}

.stock-table[hidden] {
    display: none !important;
}

.stock-table__head {
    position: sticky;
    top: 0;
    z-index: 1;
    flex-shrink: 0;
    display: grid;
    /* 銘柄列を抑え、売却済み株数／キャッシュ増減率のヘッダが SE 幅でも折り返さないよう配分 */
    grid-template-columns: 1.75rem minmax(0, 0.9fr) minmax(4.25rem, 0.8fr) minmax(5.75rem, 1.25fr);
    gap: 2px 6px;
    align-items: start;
    padding: 8px var(--list-pad-x);
    background: var(--choice-bg);
    border-bottom: var(--list-line);
    border-radius: 0;
    color: var(--text-muted);
    font-size: var(--list-font-head);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

.stock-table__sort-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
    min-width: 0;
    margin: 0;
    padding: 2px 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    line-height: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.stock-table__sort-col.stock-table__num {
    align-items: flex-end;
    text-align: right;
}

.stock-table__sort-col:hover {
    color: var(--text);
}

.stock-table__sort-col:active {
    opacity: 0.75;
}

.stock-table__sort-col[aria-sort='ascending'],
.stock-table__sort-col[aria-sort='descending'] {
    color: var(--text);
}

.stock-table__sort-primary {
    display: inline-flex;
    align-items: baseline;
    gap: 0.25em;
    line-height: 1.25;
    max-width: 100%;
    white-space: nowrap;
}

.stock-table__sort-col[aria-sort='ascending'] .stock-table__sort-primary::after,
.stock-table__sort-col[aria-sort='descending'] .stock-table__sort-primary::after {
    flex-shrink: 0;
    font-size: 0.65em;
    line-height: 1;
    opacity: 0.85;
}

.stock-table__sort-col[aria-sort='ascending'] .stock-table__sort-primary::after {
    content: '▲';
}

.stock-table__sort-col[aria-sort='descending'] .stock-table__sort-primary::after {
    content: '▼';
}

.stock-table__sort-secondary {
    max-width: 100%;
    font-size: var(--list-font-sub);
    font-weight: 500;
    line-height: 1.25;
    color: var(--text-muted);
    white-space: nowrap;
}

.stock-table__line {
    display: grid;
    grid-template-columns: 1.75rem minmax(0, 0.9fr) minmax(4.25rem, 0.8fr) minmax(5.75rem, 1.25fr);
    gap: 2px 6px;
    align-items: baseline;
    min-width: 0;
    width: 100%;
}

.stock-table__fav-spacer {
    display: block;
    width: 1.75rem;
    height: 1px;
}

.stock-table__line + .stock-table__line,
.stock-table__line--sub {
    margin-top: 2px;
}

.stock-table__num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    min-width: 0;
    overflow-wrap: anywhere;
}

.stock-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.stock-row {
    border-bottom: var(--list-line);
}

.stock-row:last-child {
    border-bottom: none;
}

.stock-card {
    display: block;
    width: 100%;
    max-width: 100%;
    text-align: left;
    background: var(--surface);
    border: none;
    border-bottom: var(--list-line);
    border-radius: 0;
    box-shadow: none;
    padding: var(--list-row-pad-y) var(--list-pad-x);
    min-height: var(--list-row-min-h);
    cursor: pointer;
    color: inherit;
    font: inherit;
    overflow: hidden;
}

.stock-card--listed {
    cursor: default;
    overflow: visible;
    border-bottom: none;
}

.stock-card--listed:hover {
    background: var(--list-row-hover);
}

.stock-card:last-child {
    border-bottom: none;
    border-radius: 0;
}

.stock-card--home {
    display: block;
    padding: var(--list-row-pad-y) var(--list-pad-x);
    border-bottom: none;
    overflow: visible;
    min-height: var(--list-row-min-h);
    cursor: default;
}

.stock-card--home:hover,
.stock-row.is-expanded .stock-card--home {
    background: var(--list-row-hover);
}

.stock-card:not(.stock-card--home):not(.stock-card--listed):hover {
    background: var(--list-row-hover);
}

.favorite-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: -10px -12px -10px -14px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.favorite-toggle svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linejoin: round;
}

.favorite-toggle.is-on {
    color: #d97706;
}

.favorite-toggle.is-on svg {
    fill: currentColor;
}

.favorite-toggle:hover {
    color: #b45309;
    background: rgba(217, 119, 6, 0.08);
}

.favorite-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.favorite-toggle--detail {
    width: 44px;
    height: 44px;
    margin: 0 2px 0 -10px;
}

.favorite-toggle--row {
    justify-self: center;
    align-self: center;
    width: 44px;
    height: 44px;
    margin: -14px calc((1.75rem - 44px) / 2);
    border-radius: 8px;
}

.favorite-toggle--row svg {
    width: 16px;
    height: 16px;
}

.stock-card:focus-visible,
.stock-card__hit:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    position: relative;
    z-index: 1;
}

.stock-card__name-cell {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;
}

.stock-card__name-scroll {
    flex: 1 1 auto;
    min-width: 0;
    --name-fade-from: var(--surface);
}

.stock-card--home:hover .stock-card__name-scroll,
.stock-row.is-expanded .stock-card__name-scroll,
.stock-card--listed:hover .stock-card__name-scroll {
    --name-fade-from: var(--list-row-hover);
}

.stock-card__name-scroll.name-scroll-wrap::before,
.stock-card__name-scroll.name-scroll-wrap::after {
    width: 28px;
}

.stock-card__name-cell .stock-card__name-hit {
    flex: 0 0 auto;
    width: max-content;
    max-width: none;
    min-width: 0;
    text-align: left;
}

.stock-card__hit {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: inherit;
    cursor: pointer;
    min-width: 0;
}

.stock-card__hit--sub {
    width: 100%;
}

.stock-card__hit .stock-table__num {
    display: block;
    text-align: right;
}

/* 銘柄名列の右端の鉛筆（okane-log オリジナルカテゴリ編集と同型） */
.stock-card__edit {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: -4px -6px -4px 0;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.stock-card__edit:hover {
    background: var(--choice-bg);
    color: var(--text);
}

.stock-card__edit:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.stock-card__edit-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.stock-card__edit-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.stock-card__name {
    font-size: var(--list-font);
    font-weight: 700;
    line-height: 1.35;
    white-space: nowrap;
}

/* 銘柄タブ一覧は省略表示（ホームは name-scroll） */
.stock-card:not(.stock-card--home):not(.stock-card--listed) .stock-card__name,
.stock-card--listed .stock-card__name {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stock-card__code {
    font-size: var(--list-font-sub);
    color: var(--text-muted);
    line-height: 1.35;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stock-card .stock-table__num {
    font-size: var(--list-font);
    font-weight: 600;
    line-height: 1.35;
}

.stock-card .stock-table__line--sub .stock-table__num,
.stock-card .stock-table__line--sub .stock-card__code {
    font-size: var(--list-font-sub);
    font-weight: 500;
}

.stock-card__pnl.is-profit {
    color: var(--profit);
}

.stock-card__pnl.is-loss {
    color: var(--loss);
}

.home-lots-panel {
    padding: 0;
    background: var(--list-panel-bg);
    border-top: 1px dashed var(--border);
    border-radius: 0;
}

.home-lots-panel[hidden] {
    display: none !important;
}

.home-lots-panel__empty {
    margin: 0;
    padding: var(--list-row-pad-y) var(--list-pad-x);
    font-size: var(--list-font-sub);
    color: var(--text-muted);
}

.home-lot-item--closed-total {
    margin-top: 0;
}

.home-lot-row--closed-total {
    color: var(--text-muted);
}

.home-lot-row__closed-label {
    min-width: 0;
    font-size: var(--list-font-sub);
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.home-lots-broker + .home-lots-broker {
    margin-top: 0;
    padding-top: 0;
    border-top: var(--list-line);
}

.home-lots-broker__title {
    margin: 0;
    padding: 10px var(--list-pad-x) 4px;
    font-size: var(--list-font-group);
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.02em;
    background: var(--list-panel-bg);
}

.home-lots-group + .home-lots-group {
    margin-top: 0;
}

.home-lots-group__title {
    margin: 0;
    padding: 8px var(--list-pad-x) 4px;
    font-size: var(--list-font-meta);
    font-weight: 700;
    color: var(--accent-pressed);
    letter-spacing: 0.02em;
}

.home-lots-group__head,
.home-lot-row {
    display: grid;
    /* 購入金額列を抑え、期間内売却数ヘッダが SE 幅でも折り返さないよう配分 */
    grid-template-columns:
        minmax(0, 0.85fr)
        minmax(3rem, 0.55fr)
        minmax(4.25rem, 0.75fr)
        minmax(4.25rem, 0.85fr);
    gap: 2px 6px;
    align-items: baseline;
    min-width: 0;
    width: 100%;
}

.home-lots-group__head {
    padding: 4px var(--list-pad-x) 6px;
    color: var(--text-muted);
    font-size: var(--list-font-head);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.02em;
    border-bottom: var(--list-line);
}

.home-lots-group__sort-col {
    display: inline-flex;
    align-items: baseline;
    gap: 0.25em;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 2px 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    line-height: inherit;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.home-lots-group__head > span {
    white-space: nowrap;
}

.home-lots-group__sort-col.home-lot-row__shares,
.home-lots-group__sort-col.home-lot-row__date {
    justify-content: flex-end;
    text-align: right;
}

.home-lots-group__sort-col:hover {
    color: var(--text);
}

.home-lots-group__sort-col:active {
    opacity: 0.75;
}

.home-lots-group__sort-col[aria-sort='ascending'],
.home-lots-group__sort-col[aria-sort='descending'] {
    color: var(--text);
}

.home-lots-group__sort-col[aria-sort='ascending']::after,
.home-lots-group__sort-col[aria-sort='descending']::after {
    flex-shrink: 0;
    font-size: 0.65em;
    line-height: 1;
    opacity: 0.85;
}

.home-lots-group__sort-col[aria-sort='ascending']::after {
    content: '▲';
}

.home-lots-group__sort-col[aria-sort='descending']::after {
    content: '▼';
}

.home-lots-group__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.home-lot-item {
    min-width: 0;
    border-bottom: var(--list-line);
}

.home-lot-item:last-child {
    border-bottom: none;
}

.home-lot-item.is-expanded {
    margin-bottom: 0;
    background: var(--list-panel-bg);
}

.home-lot-row-wrap {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
    width: 100%;
    padding: var(--list-row-pad-y) var(--list-pad-x);
    min-height: 32px;
    box-sizing: border-box;
}

.home-lot-row-wrap .home-lot-row {
    flex: 1 1 auto;
    min-width: 0;
}

.home-lot-row {
    padding: 0;
    border: none;
    font-size: var(--list-font-sub);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    line-height: 1.35;
    background: transparent;
    color: inherit;
    text-align: left;
}

button.home-lot-row--hit {
    cursor: pointer;
    border-radius: 0;
    -webkit-tap-highlight-color: transparent;
}

button.home-lot-row--hit:hover,
.home-lot-item.is-expanded > .home-lot-row-wrap {
    background: transparent;
}

.home-lot-row-wrap:has(button.home-lot-row--hit:hover),
.home-lot-item.is-expanded > .home-lot-row-wrap {
    background: rgba(13, 148, 136, 0.06);
}

button.home-lot-row--hit:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.lot-row-actions {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0;
}

.lot-row-edit,
.lot-row-delete {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.lot-row-edit:hover {
    background: var(--choice-bg);
    color: var(--text);
}

.lot-row-edit:active {
    background: #e8eef5;
    color: var(--text);
}

.lot-row-edit:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.lot-row-delete:hover {
    background: #fef2f2;
    color: var(--danger);
}

.lot-row-delete:active {
    background: #fee2e2;
    color: var(--danger);
}

.lot-row-delete:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.lot-row-delete-spacer {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.form-input:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    background: var(--choice-bg);
    color: var(--text-muted);
}

.lot-delete-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.lot-delete-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.home-lot-row__price {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-lot-row__shares,
.home-lot-row__date {
    text-align: right;
    min-width: 0;
}

.home-lots-group__head .home-lot-row__shares,
.home-lots-group__head .home-lot-row__date,
.detail-lots-head .home-lot-row__shares,
.detail-lots-head .home-lot-row__date,
.lot-sells-panel__head .home-lot-row__shares,
.lot-sells-panel__head .home-lot-row__date {
    text-align: right;
}

.lot-sells-panel {
    margin: 0;
    padding: 0 0 6px;
    border-radius: 0;
    background: var(--list-panel-bg);
    border: none;
    border-top: 1px dashed var(--border);
}

.lot-sells-panel__head,
.lot-sell-row {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(3rem, 0.7fr) minmax(4.5rem, 0.9fr);
    gap: 2px 6px;
    align-items: baseline;
    min-width: 0;
    width: 100%;
}

.lot-sells-panel__head {
    padding: 6px var(--list-pad-x) 4px;
    color: var(--text-muted);
    font-size: var(--list-font-head);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

.lot-sells-panel__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.lot-sell-row {
    padding: 8px var(--list-pad-x);
    font-size: var(--list-font-sub);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    line-height: 1.35;
    border-bottom: var(--list-line);
}

.lot-sells-panel__list .lot-sell-row:last-child {
    border-bottom: none;
}

.lot-sells-panel__empty {
    margin: 0;
    padding: 8px var(--list-pad-x);
    font-size: var(--list-font-sub);
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9375rem;
    padding: 32px 12px;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.empty-state[hidden] {
    display: none !important;
}

.empty-state__hint {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.empty-state__notices {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    max-width: 22rem;
    margin-top: 4px;
}

.empty-state__notices[hidden] {
    display: none !important;
}

.empty-state__notices .privacy-note,
.empty-state__notices .disclaimer-legal {
    margin: 0;
}

.empty-cta {
    width: auto;
    min-width: min(100%, 240px);
}

.empty-state--sm {
    padding: 20px var(--list-pad-x);
    font-size: 0.875rem;
}

.home-body .empty-state,
.stocks-body .empty-state {
    flex: 0 0 auto;
    box-sizing: border-box;
    /* 表示領域いっぱいを確保し、その下のフッターへスクロールできるようにする */
    min-height: 100%;
    justify-content: center;
    /* body ブリード後も、空状態は従来どおりインセット余白を維持 */
    padding-left: var(--view-pad-x);
    padding-right: var(--view-pad-x);
}

/* 詳細パネル内の空表示は一覧と同じ左右インセットに揃える（フルブリードはしない） */
.detail-panel > .empty-state {
    margin-left: 0;
    margin-right: 0;
}

/* Search */
.search-bar {
    margin-bottom: 12px;
}

.search-input,
.form-input {
    width: 100%;
    font-size: 1rem;
    line-height: 1.4;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    appearance: none;
}

.search-input:focus,
.form-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

select.form-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Detail */
.detail-header {
    flex-shrink: 0;
    margin-bottom: 12px;
}

.back-btn,
.text-btn {
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    min-height: 44px;
}

.back-btn {
    margin-bottom: 4px;
}

.text-btn {
    flex-shrink: 0;
}

.detail-title-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
}

/* 銘柄名＋鉛筆を一塊に（長い名前は途中で切り、右に期間用の余白を残す） */
.detail-title-cluster {
    display: flex;
    align-items: center;
    gap: 0;
    flex: 0 1 auto;
    min-width: 0;
    /* カスタム日付もホーム同様1行になりやすいよう、期間側に十分な幅を残す */
    max-width: calc(100% - 12.5rem);
}

.detail-title-row .period-filter__trigger {
    /* ホームと同じく幅上限なし。余った幅の中で中身優先・足りなければ折り返し */
    flex: 0 1 auto;
    min-width: 0;
    max-width: none;
    margin-left: auto;
}

.detail-title-row .period-filter__trigger[hidden] {
    display: none !important;
}

.detail-edit-btn {
    width: 44px;
    height: 44px;
    margin: 0 -6px 0 0;
    border-radius: 8px;
}

.detail-header > .period-filter__panel {
    margin-top: 6px;
}

.detail-title-wrap {
    --name-fade-from: var(--bg);
    flex: 0 1 auto;
    min-width: 0;
}

.detail-title-scroll {
    padding-right: 0;
}

.detail-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.35;
    white-space: nowrap;
}

/* Shared: horizontal name scroll + edge fades (no scrollbar) */
.name-scroll-wrap {
    position: relative;
    min-width: 0;
}

.name-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.name-scroll::-webkit-scrollbar {
    display: none;
}

.name-scroll-wrap::before,
.name-scroll-wrap::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 56px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 1;
}

.name-scroll-wrap::before {
    left: 0;
    background: linear-gradient(
        to right,
        var(--name-fade-from, var(--bg)) 0%,
        var(--name-fade-from, var(--bg)) 45%,
        transparent 100%
    );
}

.name-scroll-wrap::after {
    right: 0;
    background: linear-gradient(
        to left,
        var(--name-fade-from, var(--bg)) 0%,
        var(--name-fade-from, var(--bg)) 45%,
        transparent 100%
    );
}

.name-scroll-wrap.can-scroll-left::before,
.name-scroll-wrap.can-scroll-right::after {
    opacity: 1;
}

.detail-tabs {
    flex-shrink: 0;
    display: flex;
    gap: 4px;
    background: var(--choice-bg);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 8px;
}

.detail-tab {
    flex: 1;
    min-height: 40px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}

.detail-tab.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.detail-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.detail-lots-head {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 8px var(--list-pad-x) 8px;
    margin-bottom: 0;
    margin-left: calc(-1 * var(--view-pad-x));
    margin-right: calc(-1 * var(--view-pad-x));
    border-bottom: var(--list-line);
    border-top: var(--list-line);
    background: var(--choice-bg);
    color: var(--text-muted);
    font-size: var(--list-font-head);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

.detail-lots-head .home-lot-row {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    font-size: inherit;
    font-weight: inherit;
}

.detail-sort-col {
    display: inline-flex;
    align-items: baseline;
    gap: 0.25em;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 2px 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    line-height: inherit;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.detail-sort-col.home-lot-row__shares,
.detail-sort-col.home-lot-row__date {
    justify-content: flex-end;
    text-align: right;
}

.detail-sort-col--pnl {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    text-align: right;
    line-height: 1.25;
}

.detail-sort-col:hover {
    color: var(--text);
}

.detail-sort-col:active {
    opacity: 0.75;
}

.detail-sort-col[aria-sort='ascending'],
.detail-sort-col[aria-sort='descending'] {
    color: var(--text);
}

.detail-sort-col[aria-sort='ascending']:not(.detail-sort-col--pnl)::after,
.detail-sort-col[aria-sort='descending']:not(.detail-sort-col--pnl)::after {
    flex-shrink: 0;
    font-size: 0.65em;
    line-height: 1;
    opacity: 0.85;
}

.detail-sort-col[aria-sort='ascending']:not(.detail-sort-col--pnl)::after {
    content: '▲';
}

.detail-sort-col[aria-sort='descending']:not(.detail-sort-col--pnl)::after {
    content: '▼';
}

.detail-sort-primary {
    display: inline-flex;
    align-items: baseline;
    gap: 0.25em;
    max-width: 100%;
    white-space: nowrap;
}

.detail-sort-col--pnl[aria-sort='ascending'] .detail-sort-primary::after,
.detail-sort-col--pnl[aria-sort='descending'] .detail-sort-primary::after {
    flex-shrink: 0;
    font-size: 0.65em;
    line-height: 1;
    opacity: 0.85;
}

.detail-sort-col--pnl[aria-sort='ascending'] .detail-sort-primary::after {
    content: '▲';
}

.detail-sort-col--pnl[aria-sort='descending'] .detail-sort-primary::after {
    content: '▼';
}

.detail-sort-secondary {
    max-width: 100%;
    font-size: var(--list-font-sub);
    font-weight: 500;
    line-height: 1.25;
    color: var(--text-muted);
    white-space: nowrap;
}

.detail-lots-head[hidden] {
    display: none !important;
}

.detail-sells-head {
    align-items: flex-start;
}

.detail-sells-head .sell-lot-row {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    font-size: inherit;
    font-weight: inherit;
}

/*
  詳細一覧のフルブリード:
  負マージンは overflow を持つ .detail-panel の外側（.detail-panels）に当てる。
  .detail-lots 側だと overflow-x: hidden にクリップされて左右が内側に残る。
*/
.detail-panels {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-left: calc(-1 * var(--view-pad-x));
    margin-right: calc(-1 * var(--view-pad-x));
}

.detail-panel {
    display: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    background: var(--surface);
}

.detail-panel.is-active {
    display: block;
}

/* 損益タブは一覧対象外のため、従来どおり view 相当の左右余白を戻す */
.detail-panel[data-detail-panel="pnl"] {
    background: transparent;
    padding-left: var(--view-pad-x);
    padding-right: var(--view-pad-x);
}

.detail-lots {
    padding: 0;
    margin: 0;
    background: var(--surface);
}

.detail-actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 0;
    padding: 10px 0 calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg);
}

/* Lot / sell items */
.lot-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
}

.lot-card__price {
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.lot-card__meta {
    margin-top: 6px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.lot-card__actions {
    margin-top: 8px;
}

.link-danger {
    border: none;
    background: transparent;
    color: var(--danger);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    min-height: 36px;
}

.sell-lot-row {
    flex: 1 1 auto;
    min-width: 0;
    display: grid;
    /* 増減率前提。売却金額を厚めに、損益列は「キャッシュの増減率」が折り返さない程度 */
    grid-template-columns:
        minmax(0, 0.95fr)
        minmax(3rem, 0.5fr)
        minmax(4.5rem, 0.7fr)
        minmax(5.75rem, 1.15fr);
    gap: 2px 6px;
    align-items: center;
    width: 100%;
    padding: 0;
    font-size: var(--list-font-sub);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    line-height: 1.35;
    color: inherit;
}

.sell-lot-row__pnl {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 0;
    min-width: 0;
    text-align: right;
    font-size: var(--list-font-sub);
    line-height: 1.3;
}

.sell-lot-row__gross,
.sell-lot-row__rate {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sell-lot-row__gross.is-profit,
.sell-lot-row__rate.is-profit {
    color: var(--profit);
}

.sell-lot-row__gross.is-loss,
.sell-lot-row__rate.is-loss {
    color: var(--loss);
}

.sell-lot-row--head {
    align-items: start;
    color: var(--text-muted);
    font-size: var(--list-font-head);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

.sell-lot-row--head .sell-lot-row__pnl {
    align-items: flex-end;
    font-size: inherit;
    font-weight: inherit;
    line-height: 1.25;
    letter-spacing: inherit;
}

.sell-lot-row--head .sell-lot-row__pnl > span {
    max-width: 100%;
    white-space: nowrap;
}

.tax-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-pressed);
    font-size: 0.75rem;
    font-weight: 600;
}

/* Bottom nav */
.bottom-nav {
    flex-shrink: 0;
    display: flex;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding-bottom: var(--safe-bottom);
}

.bottom-nav__btn {
    flex: 1;
    min-height: var(--nav-h);
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    line-height: 1.2;
}

.bottom-nav__btn.is-active {
    color: var(--accent);
}

.bottom-nav__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ===================================================
   分析（お金ログのグラフ型：上部クロム固定、本文のみスクロール）
====================================================== */
.view-analysis {
    overflow: hidden;
    padding: 0;
}

.view-analysis.is-active {
    display: flex;
    flex-direction: column;
}

.analysis-chrome {
    flex-shrink: 0;
    padding: 12px var(--view-pad-x) 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 1;
}

.analysis-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 12px var(--view-pad-x) 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.analysis-scale-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
    padding: 3px;
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.analysis-scale-tab {
    flex: 1;
    padding: 7px 6px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}

.analysis-scale-tab.is-active {
    background: var(--bg);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--border);
}

.analysis-scale-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.analysis-period-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 10px;
}

.analysis-period-nav__label {
    margin: 0;
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

/* 〜の前後を折り返し単位にし、途中で「日」だけ落ちるのを防ぐ */
.analysis-period-nav__label-part {
    white-space: nowrap;
}

.analysis-period-nav__btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.analysis-period-nav__btn:hover:not(:disabled) {
    background: var(--list-row-hover);
}

.analysis-period-nav__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.analysis-period-nav__btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.analysis-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 8px;
}

.analysis-empty {
    margin: 8px 0 0;
    padding: 24px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.analysis-empty-inline {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.analysis-hero {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 14px 12px 12px;
}

.analysis-hero__label {
    margin: 0 0 4px;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
}

.analysis-hero__amount {
    margin: 0 0 10px;
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.analysis-hero__amount.is-profit {
    color: var(--profit);
}

.analysis-hero__amount.is-loss {
    color: var(--loss);
}

.analysis-hero__rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.analysis-hero__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.analysis-hero__row-label {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.analysis-hero__row-value {
    font-size: 0.8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.analysis-hero__row-value.is-profit {
    color: var(--profit);
}

.analysis-hero__row-value.is-loss {
    color: var(--loss);
}

.analysis-record__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.analysis-record__head .analysis-section__title {
    margin: 0;
}

.analysis-record__games {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.analysis-record__note {
    margin: -4px 0 12px;
    color: var(--text-muted);
    font-size: 0.6875rem;
    line-height: 1.4;
}

.analysis-record__score {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.analysis-record__stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 10px 6px;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-muted);
}

.analysis-record__stat.is-profit {
    color: var(--profit);
}

.analysis-record__stat.is-loss {
    color: var(--loss);
}

.analysis-record__num {
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.analysis-record__unit {
    font-size: 0.75rem;
    font-weight: 700;
}

.analysis-record__rate-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-top: 2px;
}

.analysis-record__rate-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.analysis-record__rate-value {
    font-size: 1.125rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.analysis-record__hint {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 0.6875rem;
    line-height: 1.4;
}

.analysis-section {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 12px 10px 10px;
}

.analysis-section__title {
    margin: 0 0 10px;
    font-size: 0.8125rem;
    font-weight: 700;
}

.analysis-compare-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 6px;
    height: 150px;
    padding-top: 4px;
}

.analysis-compare-bar {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    min-width: 0;
    height: 100%;
    padding: 4px 2px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
}

.analysis-compare-bar.is-selected {
    background: var(--bg);
}

.analysis-compare-bar:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.analysis-compare-bar:disabled {
    opacity: 0.35;
    cursor: default;
}

.analysis-compare-bar__amount {
    min-height: 0.875rem;
    font-size: 0.5625rem;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
}

.analysis-compare-bar.is-selected .analysis-compare-bar__amount {
    color: var(--text);
    font-weight: 700;
}

.analysis-compare-bar.is-profit .analysis-compare-bar__amount {
    color: var(--profit);
}

.analysis-compare-bar.is-loss .analysis-compare-bar__amount {
    color: var(--loss);
}

.analysis-compare-bar__track {
    display: flex;
    align-items: flex-end;
    width: 100%;
    max-width: 36px;
    flex: 1;
    min-height: 0;
    border-radius: 4px 4px 2px 2px;
    background: transparent;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}

.analysis-compare-bar__fill {
    display: block;
    width: 100%;
    min-height: 0;
    border-radius: 3px 3px 0 0;
    background: var(--text-muted);
}

.analysis-compare-bar.is-profit .analysis-compare-bar__fill {
    background: var(--profit);
}

.analysis-compare-bar.is-loss .analysis-compare-bar__fill {
    background: var(--loss);
}

.analysis-compare-bar__label {
    font-size: 0.6875rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.analysis-compare-bar.is-selected .analysis-compare-bar__label {
    color: var(--text);
    font-weight: 700;
}

.analysis-bars-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    margin: 0 -2px;
    padding: 0 2px 4px;
}

.analysis-bars-scroll--fit {
    overflow-x: hidden;
}

.analysis-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    min-width: max-content;
    height: 140px;
    padding-top: 4px;
}

.analysis-bars--fit {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    gap: 6px;
}

.analysis-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    width: 22px;
    height: 100%;
    padding: 4px 2px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
    flex-shrink: 0;
}

.analysis-bar.is-selected {
    background: var(--bg);
}

.analysis-bars--fit .analysis-bar {
    flex: 1;
    width: auto;
    min-width: 0;
    max-width: none;
}

.analysis-bar:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.analysis-bar__track {
    display: flex;
    align-items: flex-end;
    width: 100%;
    flex: 1;
    min-height: 0;
    border-radius: 4px 4px 2px 2px;
    background: transparent;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}

.analysis-bar__fill {
    display: block;
    width: 100%;
    min-height: 0;
    border-radius: 3px 3px 0 0;
    background: var(--text-muted);
}

.analysis-bar.is-profit .analysis-bar__fill {
    background: var(--profit);
}

.analysis-bar.is-loss .analysis-bar__fill {
    background: var(--loss);
}

.analysis-bar.is-selected .analysis-bar__label {
    color: var(--text);
    font-weight: 700;
}

.analysis-bar__label {
    font-size: 0.6875rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.analysis-bucket-detail {
    margin: 8px 0 0;
    min-height: 1.25rem;
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.analysis-bucket-detail[hidden] {
    display: none;
}

.analysis-pies {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 14px;
}

.analysis-pie__title {
    margin: 0 0 10px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
}

.analysis-pie__body {
    display: flex;
    align-items: center;
    gap: 12px;
}

.analysis-pie__chart {
    position: relative;
    flex-shrink: 0;
    width: 112px;
    height: 112px;
    border-radius: 50%;
}

.analysis-pie__hole {
    position: absolute;
    inset: 26%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border-radius: 50%;
    background: var(--surface);
    text-align: center;
    padding: 4px;
}

.analysis-pie__center-label {
    color: var(--text-muted);
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1;
}

.analysis-pie__center-amount {
    font-size: 0.625rem;
    font-weight: 700;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.analysis-pie__center-amount.is-profit {
    color: var(--profit);
}

.analysis-pie__center-amount.is-loss {
    color: var(--loss);
}

.analysis-pie-legend {
    list-style: none;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.analysis-pie-legend__item {
    min-width: 0;
}

.analysis-pie-legend__btn,
.analysis-pie-legend__row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 4px 2px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
}

.analysis-pie-legend__btn {
    cursor: pointer;
}

.analysis-pie-legend__btn:hover {
    background: var(--list-row-hover);
}

.analysis-pie-legend__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.analysis-pie-legend__swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.analysis-pie-legend__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem;
    font-weight: 600;
}

.analysis-pie-legend__pct {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 2.5rem;
}

.analysis-pie-legend__amount {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 4rem;
}

.analysis-pie--profit .analysis-pie-legend__amount {
    color: var(--profit);
}

.analysis-pie--loss .analysis-pie-legend__amount {
    color: var(--loss);
}

.analysis-stock-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.analysis-stock-item__btn {
    display: block;
    width: 100%;
    padding: 8px 6px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.analysis-stock-item__btn:hover {
    background: var(--list-row-hover);
}

.analysis-stock-item__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.analysis-stock-item__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.analysis-stock-item__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    font-weight: 600;
}

.analysis-stock-item__amount {
    flex-shrink: 0;
    font-size: 0.8125rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.analysis-stock-item__amount.is-profit,
.analysis-stock-item__rate.is-profit {
    color: var(--profit);
}

.analysis-stock-item__amount.is-loss,
.analysis-stock-item__rate.is-loss {
    color: var(--loss);
}

.analysis-stock-item__meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.analysis-stock-bar {
    flex: 1;
    min-width: 0;
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}

.analysis-stock-bar__fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--text-muted);
}

.analysis-stock-bar__fill.is-profit {
    background: var(--profit);
}

.analysis-stock-bar__fill.is-loss {
    background: var(--loss);
}

.analysis-stock-item__rate {
    flex-shrink: 0;
    min-width: 3.5rem;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.analysis-scroll .kabu-footer {
    margin-top: 16px;
    padding-bottom: 16px;
}

/* Footer（各タブのスクロール末尾。ボトムナビ下の固定表示はしない） */
.kabu-footer {
    flex-shrink: 0;
    padding: 16px var(--header-pad) 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    text-align: center;
}

/* SEO / 使い方ガイド（ホームのスクロール末尾・フッター直前） */
.kabu-guide {
    flex-shrink: 0;
    padding: 20px var(--header-pad) 8px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

.kabu-guide__title,
.kabu-guide__heading {
    margin: 0 0 10px;
    font-size: 0.9375rem;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}

.kabu-guide__heading {
    margin-top: 22px;
}

.kabu-guide p {
    margin: 0 0 10px;
    font-size: 0.8125rem;
    line-height: 1.7;
    color: var(--text);
}

.kabu-guide__note {
    color: var(--text-muted) !important;
    font-size: 0.75rem !important;
    line-height: 1.6 !important;
}

.kabu-guide__list,
.kabu-guide__steps {
    margin: 0 0 10px;
    padding-left: 1.25rem;
    font-size: 0.8125rem;
    line-height: 1.7;
    color: var(--text);
}

.kabu-guide__list li + li,
.kabu-guide__steps li + li {
    margin-top: 4px;
}

.kabu-guide__faq {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.kabu-guide__faq-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    overflow: hidden;
}

.kabu-guide__faq-item summary {
    cursor: pointer;
    list-style: none;
    padding: 12px 14px;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text);
}

.kabu-guide__faq-item summary::-webkit-details-marker {
    display: none;
}

.kabu-guide__faq-item summary::after {
    content: '▼';
    float: right;
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 0.625rem;
    line-height: 1.8;
}

.kabu-guide__faq-item[open] summary::after {
    content: '▲';
}

.kabu-guide__faq-item summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.kabu-guide__faq-item p {
    margin: 0;
    padding: 0 14px 12px;
    border-top: none;
    font-size: 0.8125rem;
    line-height: 1.7;
    color: var(--text-muted);
}

.privacy-note {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.disclaimer-legal {
    margin-top: 4px;
    font-size: 0.6875rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.kabu-footer__links {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 8px;
}

.kabu-footer__links a {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-decoration: none;
}

.kabu-footer__links a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* 空状態で注意文言を出しているときは、フッター側の同文言を隠して重複を避ける */
.home-body:has(#home-empty:not([hidden]) .empty-state__notices:not([hidden]))
    .kabu-footer
    .privacy-note,
.home-body:has(#home-empty:not([hidden]) .empty-state__notices:not([hidden]))
    .kabu-footer
    .disclaimer-legal,
.stocks-body:has(#stocks-empty:not([hidden]) .empty-state__notices:not([hidden]))
    .kabu-footer
    .privacy-note,
.stocks-body:has(#stocks-empty:not([hidden]) .empty-state__notices:not([hidden]))
    .kabu-footer
    .disclaimer-legal {
    display: none;
}

.home-body:has(#home-empty:not([hidden]) .empty-state__notices:not([hidden]))
    .kabu-footer__links,
.stocks-body:has(#stocks-empty:not([hidden]) .empty-state__notices:not([hidden]))
    .kabu-footer__links {
    margin-top: 0;
}

/* 詳細表示・キーボード表示中は下部ナビを外して作業領域を確保 */
.kabu-app.detail-open .bottom-nav,
.kabu-app.keyboard-open .bottom-nav {
    display: none;
}

/* Settings */
.settings-overlay {
    position: absolute;
    inset: 0;
    z-index: 40;
    background: rgba(15, 23, 42, 0.4);
}

.settings-sheet {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    width: min(100%, 360px);
    background: var(--surface);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
}

.settings-sheet.is-open {
    transform: translateX(0);
}

.settings-sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.settings-sheet__title {
    font-size: 1.0625rem;
    font-weight: 700;
}

.settings-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.settings-close-btn svg {
    width: 20px;
    height: 20px;
}

.settings-sheet__body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0 24px;
    -webkit-overflow-scrolling: touch;
}

.settings-section {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.settings-section__title {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.settings-section .btn-block + .btn-block {
    margin-top: 8px;
}

.settings-note {
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.65;
    margin-bottom: 10px;
}

.app-toast {
    position: absolute;
    left: 50%;
    top: 50%;
    right: auto;
    bottom: auto;
    z-index: 80;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 22rem;
    padding: 12px 10px 12px 16px;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    line-height: 1.45;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.98);
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

/* dialog（top layer）内でも、そのダイアログ中央に出す */
.form-dialog > .app-toast,
.confirm-dialog > .app-toast {
    position: absolute;
    z-index: 10;
}

.app-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

.app-toast__message {
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
}

.app-toast__action {
    flex: 0 0 auto;
    align-self: center;
    min-height: 36px;
    margin: 0;
    padding: 4px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #5eead4;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
}

.app-toast__action:hover {
    background: rgba(255, 255, 255, 0.1);
}

.app-toast__action:focus-visible {
    outline: 2px solid #5eead4;
    outline-offset: 1px;
}

.app-toast__action[hidden] {
    display: none !important;
}

.app-toast__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: -4px -2px 0 0;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
}

.app-toast__close:hover {
    background: rgba(255, 255, 255, 0.12);
    opacity: 1;
}

.app-toast__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

.sell-attr-fields,
.sell-lot-fieldset {
    position: relative;
}

.sell-attr-fields.is-soft-disabled,
.sell-lot-fieldset.is-soft-disabled {
    opacity: 0.65;
}

.sell-soft-lock {
    position: absolute;
    inset: 0;
    z-index: 2;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: not-allowed;
}

.sell-soft-lock[hidden] {
    display: none !important;
}

.account-list {
    list-style: none;
    margin-bottom: 10px;
}

.account-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
}

.account-item:last-child {
    border-bottom: none;
}

.inline-form {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.inline-form .form-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger {
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-pressed);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--choice-bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #eef2f7;
}

.btn-danger {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.btn-danger:hover {
    background: #fee2e2;
}

.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Dialogs */
.form-dialog,
.confirm-dialog {
    /* position は指定しない（UA の dialog 中央寄せを維持する） */
    border: none;
    border-radius: 16px;
    padding: 0;
    margin: auto;
    width: min(calc(100% - 24px), 440px);
    max-height: min(90dvh, 720px);
    max-height: min(calc(var(--app-height, 100dvh) - 24px), 720px);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
}

/* キーボード表示中の上寄せは JS（visualViewport ピン留め）に任せる */

.form-dialog::backdrop,
.confirm-dialog::backdrop {
    background: rgba(15, 23, 42, 0.45);
    /* 背後へのスクロール伝播を抑える */
    touch-action: none;
    overscroll-behavior: none;
}

.form-dialog__form,
.confirm-form {
    padding: 20px 18px 18px;
    overflow-y: auto;
    max-height: min(90dvh, 720px);
    max-height: min(calc(var(--app-height, 100dvh) - 24px), 720px);
}

/*
  固定フッター付きフォーム:
  dialog 自体に display:flex を当てると iOS Safari で中身が描画されず
  ::backdrop だけ見えることがある（Material Web 等でも同様の報告あり）。
  flex レイアウトは内側の form に閉じ込める。
*/
.form-dialog[open]:has(> .form-dialog__form--fixed-actions) {
    overflow: hidden;
}

.form-dialog__form--fixed-actions {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: 100%;
    max-height: min(90dvh, 720px);
    max-height: min(calc(var(--app-height, 100dvh) - 24px), 720px);
    padding: 0;
    overflow: hidden;
}

.form-dialog__header {
    flex-shrink: 0;
    padding: 20px 18px 0;
    background: var(--surface);
}

.form-dialog__header .form-context {
    margin: 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.form-dialog__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 14px 18px 16px;
}

.form-dialog__form--fixed-actions > .form-dialog__actions {
    flex-shrink: 0;
    margin-top: 0;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.form-dialog h2,
.confirm-dialog h2 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 14px;
}

.form-dialog__header h2 {
    margin-bottom: 8px;
}

.form-context {
    margin: -6px 0 14px;
    --name-fade-from: var(--surface);
}

.form-context__text {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    white-space: nowrap;
    line-height: 1.4;
}

.form-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* 買付・売却フォーム：ラベルと入力欄を横並び */
#buy-form .form-label,
#sell-form .form-label {
    flex-direction: row;
    align-items: center;
    gap: 10px 12px;
}

#buy-form .form-label__text,
#sell-form .form-label__text {
    flex: 0 0 7.25em;
    width: 7.25em;
    line-height: 1.35;
}

#buy-form .form-label .form-input,
#sell-form .form-label .form-input {
    flex: 1;
    min-width: 0;
    width: auto;
}

.form-fieldset {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px 12px;
    margin-bottom: 12px;
}

.form-fieldset legend {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 4px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
}

.radio-option input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.lot-option {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 8px;
    border-radius: 8px;
    cursor: pointer;
}

.lot-option + .lot-option {
    border-top: 1px solid var(--border);
}

.lot-option:hover {
    background: var(--choice-bg);
}

.lot-option input {
    margin-top: 4px;
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.lot-option__body {
    flex: 1;
    min-width: 0;
}

.lot-option__title {
    font-size: 0.9375rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.lot-option__meta {
    margin-top: 2px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.sell-lot-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sell-lot-group--account .sell-lot-group__body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sell-lot-group__heading {
    margin: 0;
    padding: 0 2px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-muted);
}

.sell-lot-group__heading--account {
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    padding-bottom: 4px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--border);
}

.sell-lot-group__heading--tax {
    font-size: 0.6875rem;
    font-weight: 600;
    margin-bottom: 2px;
    letter-spacing: 0.02em;
}

.sell-lot-group--account .sell-lot-group--tax {
    padding-left: 2px;
}

.sell-lot-group__options {
    min-width: 0;
}

.preview-card {
    background: var(--choice-bg);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.form-error,
.field-error {
    color: var(--danger);
    font-size: 0.8125rem;
    margin: -4px 0 12px;
    line-height: 1.4;
}

.field-error[hidden],
.form-error[hidden] {
    display: none !important;
}

.form-dialog__actions,
.confirm-dialog__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

.form-dialog__actions .btn-secondary,
.form-dialog__actions .btn-primary,
.confirm-dialog__actions .btn-secondary,
.confirm-dialog__actions .btn-danger {
    flex: 1;
}

.form-dialog__danger {
    margin-top: 16px;
}

.confirm-dialog__body {
    font-size: 0.9375rem;
    color: var(--text);
    line-height: 1.6;
    margin-bottom: 16px;
    white-space: pre-line;
}

@media (min-width: 560px) {
    :root {
        --view-pad-x: 20px;
        --header-pad: 20px;
    }

    .kabu-header {
        padding-left: var(--header-pad);
        padding-right: var(--header-pad);
    }

    .view {
        padding-left: var(--view-pad-x);
        padding-right: var(--view-pad-x);
    }

    .view-analysis {
        padding-left: 0;
        padding-right: 0;
    }

    .detail-actions {
        flex-direction: row;
    }

    .detail-actions .btn-block {
        flex: 1;
    }

    .home-lots-group__head,
    .home-lot-row {
        grid-template-columns:
            minmax(0, 1fr)
            minmax(3.5rem, 0.55fr)
            minmax(4.5rem, 0.7fr)
            minmax(5rem, 0.85fr);
        gap: 2px 8px;
    }

    .lot-sells-panel__head,
    .lot-sell-row {
        grid-template-columns: minmax(0, 1.2fr) minmax(4rem, 0.7fr) minmax(5.5rem, 0.9fr);
        gap: 2px 10px;
    }

    .sell-lot-row {
        grid-template-columns:
            minmax(0, 1fr)
            minmax(3.5rem, 0.55fr)
            minmax(5rem, 0.75fr)
            minmax(6.5rem, 1.2fr);
        gap: 2px 8px;
    }

    .stock-table__head,
    .stock-table__line {
        grid-template-columns: 1.75rem minmax(0, 1.1fr) minmax(4.5rem, 0.75fr) minmax(6.5rem, 1.15fr);
        gap: 2px 10px;
    }
}
