/* 家計簿の見た目(Windows 版の AppStyles.xaml と同じ配色。スマホ優先、ライト・ダーク対応) */
:root {
    --bg: #F5F6FA; --card: #FFFFFF; --line: #E5E7EB; --text: #111827; --sub: #6B7280;
    --primary: #4F46E5; --primary-soft: #E0E7FF; --primary-deep: #3730A3;
    --income: #10B981; --warning: #F59E0B; --danger: #EF4444; --danger-text: #B91C1C; --sun: #E11D48; --sat: #2563EB;
    --tabbar-h: 64px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root { color-scheme: dark; --bg: #0F1115; --card: #1A1D24; --line: #2A2F3A; --text: #F3F4F6; --sub: #9CA3AF;
            --primary-soft: #2A2F3A; --primary-deep: #A5B4FC; --danger-text: #FCA5A5; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
    -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }

.shell { min-height: 100dvh; }
.content { max-width: 720px; margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.grow { flex: 1; min-width: 0; }
.between { justify-content: space-between; }
.center { text-align: center; }

/* カード */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.hero { background: var(--primary); color: #fff; border: none; border-radius: 20px; padding: 20px; }
.hero .label { color: #DDE3FF; font-size: 14px; }
.hero .amount { font-size: 32px; font-weight: 700; line-height: 1.2; }
.hero .note { color: #DDE3FF; font-size: 12px; }
.title { font-size: 16px; font-weight: 700; margin: 0; }
.caption { color: var(--sub); font-size: 12px; }
.big { font-size: 22px; font-weight: 700; }
.bold { font-weight: 700; }
.income { color: var(--income); } .danger { color: var(--danger); } .warning { color: var(--warning); }
.error-card h2 { margin: 0 0 8px; color: var(--danger); font-size: 18px; }

/* ボタン */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: none;
    border-radius: 12px; padding: 10px 14px; min-height: 40px; cursor: pointer; text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: #fff; font-weight: 700; min-height: 48px; width: 100%; }
.btn.soft { background: var(--primary-soft); color: var(--primary-deep); }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 20px; font-size: 22px; }
.hero .btn.icon { background: rgba(255,255,255,.2); color: #fff; }
.btn.danger-text { background: transparent; color: var(--danger); padding: 6px 8px; min-height: 32px; }
.btn.income-on { background: var(--income); color: #fff; }
.btn.danger-on { background: var(--danger); color: #fff; }

/* 入力欄 */
.field { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line);
    border-radius: 12px; padding: 0 12px; min-height: 44px; }
.field:focus-within { border-color: var(--primary); }
.field input { flex: 1; width: 100%; min-width: 0; border: none; outline: none; background: transparent; padding: 10px 0; font-size: 16px; }
.field.amount input { font-size: 24px; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } /* minmax(0, …): 入力欄の幅で列が広がり、iPhone で画面の外にはみ出さないように */

/* チップ(項目の1タップ選択) */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 8px 16px; cursor: pointer; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* カレンダー */
.week, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.week span { font-size: 12px; color: var(--sub); padding: 4px 0; }
.week .sun, .day.sun .num { color: var(--sun); } .week .sat, .day.sat .num { color: var(--sat); }
.day { border: 2px solid transparent; background: transparent; border-radius: 12px; min-height: 52px; padding: 4px 0;
    display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.day .num { font-size: 14px; }
.day .sum { font-size: 10px; color: var(--danger); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.day.other { opacity: .35; }
.day.today { border-color: var(--primary); } .day.today .num { font-weight: 700; }
.day.selected { background: var(--primary-soft); }

/* 一覧 */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: none; }
.avatar { width: 36px; height: 36px; border-radius: 18px; background: var(--primary-soft); color: var(--primary-deep);
    display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.badge { border-radius: 10px; padding: 4px 8px; font-size: 12px; color: #fff; flex: none; }
.badge.income { background: var(--income); } .badge.expense { background: var(--danger); }
.empty { color: var(--sub); font-size: 12px; padding: 8px 0; }

/* 予算バー */
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > div { height: 100%; background: var(--income); border-radius: 4px; }
.bar.warn > div { background: var(--warning); } .bar.over > div { background: var(--danger); }

/* 下のタブ(iPhone のホームバーを避ける) */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(6, 1fr);
    background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    height: var(--tabbar-h); font-size: 11px; color: var(--sub); text-decoration: none; }
.tab-icon { font-size: 20px; }
.tab.active { color: var(--primary); font-weight: 700; }

/* ---- デザインの見直し 2(design.md D4〜D6) ---- */
html, body { font-variant-numeric: tabular-nums; }
.card { box-shadow: 0 1px 2px rgba(17,24,39,.04), 0 6px 20px rgba(17,24,39,.06); }
.hero { background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%); box-shadow: 0 10px 30px rgba(79,70,229,.35);
    position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
    background: rgba(255,255,255,.08); pointer-events: none; }
@media (prefers-color-scheme: dark) { .card { box-shadow: none; } .hero { box-shadow: 0 10px 30px rgba(0,0,0,.4); } }

/* カレンダー: 支出の濃さ(4段階)、今日は丸、選んだ日は枠 */
.day { border: none; position: relative; }
.day.l1 { background: rgba(239,68,68,.08); } .day.l2 { background: rgba(239,68,68,.16); }
.day.l3 { background: rgba(239,68,68,.26); } .day.l4 { background: rgba(239,68,68,.38); }
.day.l1 .sum, .day.l2 .sum, .day.l3 .sum, .day.l4 .sum { color: var(--text); font-weight: 600; }
.day.selected { background-color: transparent; box-shadow: inset 0 0 0 2px var(--primary); }
.day.selected.l1, .day.selected.l2, .day.selected.l3, .day.selected.l4 { box-shadow: inset 0 0 0 2px var(--primary); }
.day.today .num { background: var(--primary); color: #fff !important; border-radius: 12px; min-width: 24px; padding: 1px 4px; }

/* 項目の色 */
.avatar.colored { color: #fff; }
.dot { width: 10px; height: 10px; border-radius: 5px; display: inline-block; flex: none; }
.chip .dot { margin-right: 6px; vertical-align: middle; }
.chip.on .dot { box-shadow: 0 0 0 2px #fff; }

/* 集計: 内訳のドーナツと凡例 */
.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { width: 128px; height: 128px; border-radius: 50%; flex: none; position: relative; }
.donut::after { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--card); }
.donut .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
    justify-content: center; z-index: 1; font-size: 11px; color: var(--sub); }
.donut .center b { font-size: 15px; color: var(--text); }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend .row { gap: 8px; }
.legend .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- チャット(design.md C1〜C4) ---- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.chip.suggestion { background: var(--primary-soft); color: var(--primary-deep); border-color: transparent; font-size: 13px; }
.messages { display: flex; flex-direction: column; gap: 8px; min-height: 240px;
    max-height: calc(100dvh - 330px - var(--tabbar-h) - env(safe-area-inset-bottom)); overflow-y: auto; }
.msg { display: flex; flex-direction: column; max-width: 80%; align-self: flex-start; gap: 2px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 16px 16px 16px 4px; background: var(--bg); white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.msg.mine .bubble { background: var(--primary); color: #fff; border-radius: 16px 16px 4px 16px; }
.msg .meta { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--sub); }
.btn.tiny { font-size: 11px; min-height: 24px; padding: 2px 4px; }
.composer { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); }

/* ---- TODO(design.md T1〜T4) ---- */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: rgba(255,255,255,.15); border-radius: 12px; padding: 4px; }
.seg { border: none; background: transparent; color: #fff; border-radius: 9px; padding: 8px 0; cursor: pointer; }
.seg.on { background: #fff; color: var(--primary); font-weight: 700; }
.check { width: 30px; height: 30px; border-radius: 15px; border: 2px solid var(--sub); background: transparent;
    color: #fff; flex: none; cursor: pointer; font-size: 16px; line-height: 1; }
.check.on { background: var(--income); border-color: var(--income); }
.todo.done .todo-title { text-decoration: line-through; opacity: .5; }
.tab { font-size: 10px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }
input[type=date]:disabled { opacity: .4; }

/* 画面内のダイアログ(design.md H2) */
.dialog-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
    padding: 24px; background: rgba(15, 17, 21, 0.45); }
.dialog { width: 100%; max-width: 360px; background: var(--card); border-radius: 20px; padding: 20px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25); }
.dialog-title { margin: 0 0 8px; font-size: 17px; }
.dialog-message { margin: 0 0 20px; color: var(--sub); white-space: pre-wrap; line-height: 1.5; }
.dialog-buttons { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-buttons .btn { width: auto; min-width: 88px; min-height: 44px; }
.error-entry { white-space: pre-wrap; word-break: break-all; font-size: 11px; margin: 0; }
