/* 家計簿の改善・カレンダー(予定)・スマホと PC の画面(design.md K2・K5・K7・K8) */

/* ---- 入力のモーダル: スマホは下から出るシート ---- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
    background: rgba(15, 17, 21, .45); animation: fade .15s ease-out; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; background: var(--card);
    border-radius: 20px 20px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, .2); animation: rise .2s ease-out; }
.sheet:focus { outline: none; }
.sheet-head { margin-bottom: 8px; touch-action: none; cursor: move; }
.sheet-body { gap: 12px; }
.btn.plain-icon { background: transparent; font-size: 24px; width: 40px; height: 40px; padding: 0; color: var(--sub); }
/* ---- 行の編集ボタン(RowEditButton): 「…」 ---- */
.row-menu-btn { width: 44px; min-width: 44px; height: 44px; padding: 0; background: transparent; font-size: 22px; color: var(--sub); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
.item.small { padding: 6px 0; font-size: 13px; }

/* ---- 家計簿: その月の支出(日ごと) ---- */
.day-group + .day-group { margin-top: 8px; }
.day-head { padding: 10px 0 2px; border-bottom: 1px solid var(--line); }

/* ---- 集計: 月・年、横棒、推移、全支出 ---- */
.segmented.two { grid-template-columns: repeat(2, 1fr); }
.hbar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.hbar > div { height: 100%; border-radius: 3px; }
.trend { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; align-items: end; height: 150px; }
.trend.days31 { gap: 2px; }
.trend-col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.trend-bar { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.trend-bar > div { width: 100%; min-height: 2px; border-radius: 4px 4px 0 0;
    background: linear-gradient(180deg, #7C3AED 0%, #4F46E5 100%); }
.trend-label { font-size: 10px; color: var(--sub); white-space: nowrap; }
.trend.days31 .trend-col:not(:nth-child(5n+1)) .trend-label { visibility: hidden; }
.cmp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.cmp-list { display: flex; flex-direction: column; gap: 12px; }
.cmp-line { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.cmp-value { text-align: right; min-width: 80px; }
.bud-nums { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.bud-budget-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bud-breakdown { overflow-wrap: anywhere; }
.expense-row .date { width: 56px; flex: none; }
.badge-soft { font-size: 10px; padding: 1px 6px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-deep); margin-left: 4px; }

/* ---- カレンダー(予定): 予定と TODO の点 ---- */
.marks { display: flex; gap: 2px; justify-content: center; min-height: 6px; }
.mark { width: 6px; height: 6px; border-radius: 3px; display: inline-block; }
.mark.ev { background: var(--primary); } .mark.td { background: var(--warning); }
.caption .mark { margin: 0 3px 0 6px; vertical-align: middle; }
.time-pill { flex: none; min-width: 52px; text-align: center; font-size: 12px; padding: 4px 6px; border-radius: 10px;
    background: var(--primary-soft); color: var(--primary-deep); font-weight: 600; }
.time-pill.todo-pill { background: rgba(245, 158, 11, .15); color: #B45309; }

/* ---- タブ: スマホは下に7つ。PC 用の名前は隠す ---- */
.tabbar { grid-template-columns: repeat(5, 1fr); }
.tabbar .brand { display: none; }
.tab { font-size: 9px; white-space: nowrap; letter-spacing: -.02em; }
.env-badge { position: fixed; top: 6px; right: 8px; z-index: 20; font-size: 11px; padding: 2px 8px; border-radius: 10px;
    background: var(--warning); color: #fff; font-weight: 700; }

/* ---- PC(幅 900px 以上): タブは左の縦の一覧、内容は広く、カードを横に並べる ---- */
@media (min-width: 900px) {
    :root { --side-w: 220px; }
    .tabbar { top: 0; right: auto; width: var(--side-w); display: flex; flex-direction: column; gap: 4px;
        border-top: none; border-right: 1px solid var(--line); padding: 20px 12px; }
    .tabbar .brand { display: block; font-weight: 800; font-size: 16px; color: var(--primary); padding: 4px 12px 16px; }
    .tab { flex-direction: row; justify-content: flex-start; gap: 12px; height: 44px; padding: 0 12px;
        border-radius: 12px; font-size: 14px; }
    .tab.active { background: var(--primary-soft); color: var(--primary-deep); }
    .tab-icon { font-size: 18px; }
    .content { max-width: none; margin-left: var(--side-w); margin-right: auto; padding: 28px 32px 40px; }
    .page-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
    .composer { bottom: 8px; }
    .messages { max-height: calc(100dvh - 300px); }
    .sheet-backdrop { align-items: center; }
    .sheet { border-radius: 20px; padding: 20px; max-width: 480px; }
}

/* ---- 家族・予定の持ち主(design.md S9・S10) ---- */
.member-tag { font-size: 10px; color: #fff; padding: 1px 6px; border-radius: 8px; margin-left: 4px; vertical-align: middle; }
.segmented.plain { background: var(--bg); }
.segmented.plain .seg { color: var(--text); }
.segmented.plain .seg.on { background: var(--primary); color: #fff; }
select { font: inherit; color: var(--text); background: transparent; border: none; width: 100%; padding: 10px 0; outline: none; }
select option, select optgroup { background-color: var(--card); color: var(--text); }

/* 家計簿の中の切り替え(入力・集計・項目と予算・固定収支。design.md N5) */
.subnav { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 12px; }
.subnav .seg { text-align: center; text-decoration: none; font-size: 13px; white-space: nowrap; }

/* 2段の行(固定収支・一括払い。design.md W1・W2)。ほかの .item は変えない */
.item.two-tier { flex-direction: column; align-items: stretch; gap: 6px; }
.two-tier .tier-main { display: flex; align-items: center; gap: 12px; }
.two-tier .row-name { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.two-tier .row-period { min-width: 0; overflow-wrap: anywhere; }
.two-tier .row-amount { flex: none; white-space: nowrap; }
.two-tier .tier-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.two-tier .tier-actions select,
.two-tier .tier-actions input:not([type="checkbox"]) { flex: 1 1 8em; min-width: 0; width: auto; }
.two-tier .tier-actions button,
.two-tier .tier-actions label,
.nowrap { flex: none; white-space: nowrap; }

/* 1段の行(design.md UX22)。列は修飾のクラスの --ol-cols で決める。出ない値の所は空の要素を置いて、左端をそろえる */
.item.one-line { display: grid; grid-template-columns: var(--ol-cols, minmax(0, 1fr) auto 44px); align-items: center;
    column-gap: 8px; padding: 2px 0; min-height: 44px; }
.one-line > * { min-width: 0; }
.one-line .row-name,
.one-line .row-memo,
.one-line .row-cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.one-line .row-period,
.one-line .row-amount,
.one-line .row-kind { white-space: nowrap; overflow: visible; text-overflow: clip; }
.one-line .row-amount { text-align: right; }
/* 色の丸・名前・メモ・金額・「…」(入力の支出) */
.item.one-line.ol-expense { --ol-cols: 28px minmax(0, 1fr) minmax(0, 1fr) auto 44px; }
/* 色の丸・名前・メモ・期間・金額・「…」(月の支出) */
.item.one-line.ol-month { --ol-cols: 28px minmax(0, 1fr) minmax(0, 1fr) auto auto 44px; }
/* 名前・期間・金額・「…」(固定枠(入力)・買い物・家族など) */
.item.one-line.ol-slot { --ol-cols: minmax(0, 1fr) auto auto 44px; }
/* 区分・名前・期間・項目名・金額・「…」(固定収支・一括払い・固定枠) */
.item.one-line.ol-fixed { --ol-cols: auto minmax(0, 1fr) auto minmax(0, 8em) auto 44px; }
/* 名前・期間・項目名・金額・「…」(一括払い) */
.item.one-line.ol-inst { --ol-cols: minmax(0, 1fr) auto minmax(0, 8em) auto 44px; }
/* 色の丸・名前・期間・枠名・金額・「…」(予算の枠・項目) */
.item.one-line.ol-budget { --ol-cols: 28px minmax(0, 1fr) auto minmax(0, 8em) auto 44px; }
/* 名前・入っている項目・期間・年間予算・「…」(予算の枠) */
.item.one-line.ol-frame { --ol-cols: minmax(0, 1fr) minmax(0, 1fr) auto auto 44px; }
/* チェック・品名・「…」(買い物) */
.item.one-line.ol-todo { --ol-cols: auto minmax(0, 1fr) 44px; }
/* 時刻・題・持ち主・メモ・「…」(予定) */
.item.one-line.ol-schedule { --ol-cols: auto minmax(0, 1fr) auto minmax(0, 1fr) 44px; }
/* 丸・名前・使用中・「…」(家族) */
.item.one-line.ol-member { --ol-cols: 36px minmax(0, 1fr) auto 44px; }

.chips .chip { min-height: 44px; }

/* 6件目の直し(design.md Y1〜Y5) */
.entry-row .tier-actions { justify-content: flex-end; }
.two-tier .row-memo { flex: 1 1 10em; min-width: 0; overflow-wrap: anywhere; }
.donut-wrap { flex-wrap: wrap; }
.legend { flex: 1 1 220px; }
.legend .name { overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }
[tabindex="-1"]:focus { outline: none; box-shadow: none; }
.save-continue,
.save-continue + .btn.primary { flex: 1 1 0; width: auto; min-height: 48px; font-size: 16px; white-space: nowrap; }
.chips.wrap { flex-wrap: wrap; overflow-x: visible; }
.chips.wrap .chip { flex: 0 1 auto; max-width: 100%; overflow-wrap: anywhere; }

/* 7件目の直し: 固定収支の行の3つの段(design.md Z1〜Z4) */
.fixed-row .tier-actions,
.bill-row .tier-actions,
.inst-row .tier-actions { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; }
.tier-settings { display: grid; align-items: center; column-gap: 8px; }
.inst-row .tier-settings { grid-template-columns: max-content max-content minmax(0, 1fr); grid-template-areas: "repeats endlabel end"; }
.fixed-row .tier-settings { grid-template-columns: max-content minmax(0, 1fr); grid-template-areas: "startlabel start" "endlabel end"; row-gap: 6px; }
.tier-settings label:has(.row-repeats) { grid-area: repeats; }
.tier-settings .row-start-label { grid-area: startlabel; }
.tier-settings .row-start { grid-area: start; width: 100%; min-width: 0; }
.tier-settings .row-end-label { grid-area: endlabel; }
.show-ended { align-self: flex-start; font-size: 15px; }
.tier-settings .row-end { grid-area: end; width: 100%; min-width: 0; }
.tier-category { width: 100%; }
.tier-category select { width: 100%; min-width: 0; }
.tier-buttons { display: grid; grid-auto-flow: column; justify-content: end; column-gap: 8px; align-items: center; }
.inst-row .tier-buttons { grid-template-columns: max-content max-content max-content; grid-template-areas: "renew edit del"; }
.fixed-row .tier-buttons,
.bill-row .tier-buttons { grid-template-columns: max-content max-content; grid-template-areas: "edit del"; }
.bill-row .tier-settings { grid-template-columns: max-content minmax(0, 1fr); grid-template-areas: "endlabel end"; }
.bill-amount-line .caption { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.tier-buttons .renew { grid-area: renew; }
.tier-buttons .edit-amount,
.tier-buttons .bill-amounts { grid-area: edit; }
.tier-buttons .row-delete { grid-area: del; }
.field-label { font-size: 14px; color: var(--sub); }
.add-head { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

/* 押せる要素は 44px 以上(design.md UX。完了条件110)。行の部品は左端をそろえる(完了条件111) */
.btn { min-height: 44px; min-width: 44px; }
.btn.icon,
.btn.plain-icon { width: 44px; height: 44px; border-radius: 22px; }
.btn.danger-text { min-height: 44px; }
.btn.tiny { min-height: 44px; min-width: 44px; }
.check { width: 44px; height: 44px; border-radius: 22px; }
.seg { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
a.btn,
a.seg { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
label:has(input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.item.one-line { justify-items: start; }
.item.one-line > .row-amount { justify-self: end; }
.item.one-line > .row-menu-btn { justify-self: end; }

/* 年月・日付を選ぶ部品(design.md「年月・日付を選んで入れる」処理の流れ 7。押せる高さ 44px 以上) */
.ym-field { display: flex; flex-wrap: nowrap; gap: 8px; align-items: center; }
.ym-field > .field { flex: 1 1 0; min-width: 0; }
.ym-field select { min-height: 44px; }
.date-button { min-height: 44px; min-width: 44px; width: 100%; justify-content: flex-start; font: inherit; color: var(--text); cursor: pointer; text-align: left; }
.date-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.date-week { text-align: center; font-size: 14px; color: var(--sub); }
.date-grid button { min-height: 44px; min-width: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.date-grid button.other { opacity: 0.5; }
.date-grid button.selected { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 行の年間予算の期間(design.md 28件目 処理の流れ7)。期間ごとに金額と期間を並べ、終了は薄い色 */
.budget-periods { display: flex; flex-direction: column; align-items: flex-end; }
.budget-period { display: inline-flex; gap: 6px; align-items: baseline; white-space: nowrap; }
.budget-period.ended { opacity: 0.6; }

/* 行の編集・並べ替え・その他収入(design.md 29件目 処理の流れ5)。押せる高さは 44px 以上 */
.modal-danger { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; display: flex; justify-content: flex-start; }
.modal-danger .btn.danger-text { color: var(--danger-text); }
.move-btn { width: 44px; height: 44px; min-width: 44px; padding: 0; font-size: 18px; color: var(--sub); background: transparent; }
.move-btn-gap { display: inline-block; width: 44px; height: 44px; flex: none; }
.drag-handle { display: inline-flex; align-items: center; justify-content: center; width: 44px; min-width: 44px; height: 44px; color: var(--sub); cursor: grab; touch-action: none; user-select: none; }
.sorting-row { opacity: 0.85; z-index: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
/* つまみ・色の丸・名前・期間・予算グループ名・年間予算・上へ・下へ・「…」(項目の行。並べ替えができる) */
.item.one-line.ol-budget.ol-sortable { --ol-cols: 44px 28px minmax(0, 1fr) auto minmax(0, 8em) auto 44px 44px 44px; position: relative; }
.month-income-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 44px; gap: 8px; align-items: center; min-height: 44px; }
.month-income-row .row-cat,
.month-income-row .row-memo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.month-income-row .row-amount { color: var(--income); white-space: nowrap; text-align: right; }

/* モーダルの下の1行(design.md 31件目 処理の流れ8)。2つのボタンを同じ幅で横に並べ、375px でも折り返さない */
.modal-actions { display: flex; flex-wrap: nowrap; gap: 8px; align-items: stretch; }
.modal-actions > .btn { flex: 1 1 0; width: auto; min-width: 0; min-height: 48px; font-size: 16px; white-space: nowrap; }
.modal-actions > .btn.modal-delete { color: var(--danger-text); }

/* 項目の行・予算グループの行の列のそろえ(design.md 33件目 処理の流れ3・5・F104)。auto を使わず、子に grid-area を付ける */
.row-budget { display: flex; justify-content: flex-end; min-width: 0; }
.row-budget > .row-cat { max-width: 100%; }
.item.one-line.ol-budget.ol-sortable {
    grid-template-columns: 44px 28px minmax(0, 1fr) 15em 44px 44px 44px;
    grid-template-areas: "handle dot name budget up down menu";
}
.ol-budget > .drag-handle { grid-area: handle; }
.ol-budget > .dot { grid-area: dot; }
.ol-budget > .row-name { grid-area: name; }
.ol-budget > .row-budget { grid-area: budget; }
.ol-budget > .move-up { grid-area: up; }
.ol-budget > .move-down { grid-area: down; }
.ol-budget > .row-menu-btn { grid-area: menu; }
.item.one-line.ol-frame {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 15em 44px;
    grid-template-areas: "name members budget menu";
}
.ol-frame > .row-name { grid-area: name; }
.ol-frame > .row-members { grid-area: members; }
.ol-frame > .row-budget { grid-area: budget; }
.ol-frame > .row-menu-btn { grid-area: menu; }
@media (max-width: 599px) {
    .item.one-line.ol-budget.ol-sortable {
        grid-template-columns: 44px 28px minmax(0, 1fr) 44px 44px 44px;
        grid-template-areas: "handle dot name up down menu" "handle dot budget budget budget budget";
    }
    .item.one-line.ol-frame {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
        grid-template-areas: "name name menu" "members budget menu";
    }
}

/* 固定収支の行の列のそろえ(design.md 33件目 処理の流れ4・5・F111)。auto を使わず、子に grid-area を付ける */
.item.one-line.ol-fixed {
    grid-template-columns: 3.5em minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) 9em 44px;
    grid-template-areas: "kind name period cat amount menu";
}
.ol-fixed > .row-kind { grid-area: kind; }
.ol-fixed > .row-name { grid-area: name; }
.ol-fixed > .row-period { grid-area: period; }
.ol-fixed > .row-cat { grid-area: cat; }
.ol-fixed > .row-amount { grid-area: amount; }
.ol-fixed > .row-menu-btn { grid-area: menu; }
@media (max-width: 599px) {
    .item.one-line.ol-fixed {
        grid-template-columns: 3.5em minmax(0, 1fr) 9em 44px;
        grid-template-areas: "kind name amount menu" "kind period cat menu";
    }
}
