/* 全站統一的現代財務介面：柔和中性色、單一綠色主色與一致圓角。 */

:root {
  --paper: #F3F6F4;
  --paper-card: #FFFFFF;
  --rule: #DCE5DF;
  --ink: #183029;
  --ink-soft: #61746C;
  --accent: #276B52;
  --accent-strong: #1D5842;
  --accent-soft: #E5F1EB;
  --negative: #A33A4A;
  --over-limit: #B3401F;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --serif: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  --shadow: 0 10px 30px rgba(28, 67, 52, 0.07);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background: radial-gradient(circle at 10% 0%, #E9F2ED 0, transparent 34%), var(--paper);
  background-color: var(--paper);
  min-height: 100vh;
  padding: 0 0 60px 0;
}

header.masthead {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 28px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
header.masthead h1 {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}
header.masthead p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.view-mode-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper-card);
  white-space: nowrap;
}
.view-mode-control > span { padding: 0 8px; color: var(--ink-soft); font-size: 0.8rem; }
.view-mode-btn {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.view-mode-btn:hover { color: var(--ink); background: var(--accent-soft); }
.view-mode-btn.active { color: #fff; background: var(--accent); }
.simple-mode-hint { display: none; }

/* 結論模式是獨立的閱讀介面，不只是把 details 關起來。 */
body[data-view-mode="simple"] .simple-mode-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 14px 0 4px;
  padding: 11px 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.86rem;
}
body[data-view-mode="simple"] .editor-only,
body[data-view-mode="simple"] .edit-card,
body[data-view-mode="simple"] .detail-card,
body[data-view-mode="simple"] .detail-only,
body[data-view-mode="simple"] .wage-detail-card { display: none !important; }
body[data-view-mode="simple"] .card {
  padding: 18px;
  margin: 10px 0;
  box-shadow: 0 5px 18px rgba(28, 67, 52, 0.05);
}
body[data-view-mode="simple"] .summary-block { margin-bottom: 0; }
body[data-view-mode="simple"] .conclusion-card > h2 { margin: 0 0 10px; font-size: 1.15rem; }
body[data-view-mode="simple"] #health-results > h3:not(:first-child) { margin: 18px 0 8px; font-size: 0.95rem; }
body[data-view-mode="simple"] #allocation-dashboard > .compact-settings { display: none; }
body[data-view-mode="simple"] .estimator-controls {
  margin: 10px 0 14px;
  padding: 10px 12px;
  background: var(--accent-soft);
}
body[data-view-mode="simple"] #estimator-body .estimator-field-grid,
body[data-view-mode="simple"] #estimator-body .estimator-option-grid,
body[data-view-mode="simple"] #estimator-body .setup-steps,
body[data-view-mode="simple"] #estimator-body .student-loan-toggle,
body[data-view-mode="simple"] #estimator-body .student-loan-plan > .section-heading,
body[data-view-mode="simple"] #estimator-body .student-loan-plan > details,
body[data-view-mode="simple"] #estimator-body .student-loan-plan > .notice { display: none; }
body[data-view-mode="simple"] #estimator-body .student-loan-plan {
  padding: 0;
  border: 0;
  background: transparent;
}
body[data-view-mode="simple"] #estimator-body > .result-block,
body[data-view-mode="simple"] #wage-body > .result-block {
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 16px;
  background: linear-gradient(145deg, #F5FAF7, var(--accent-soft));
}
body[data-view-mode="simple"] #estimator-body .result-block details { display: none; }
body[data-view-mode="simple"] .wage-source-card > :not(.health-grid) { display: none; }
body[data-view-mode="simple"] #wage-body > .notice { display: none; }

nav.tabs {
  display: flex;
  gap: 8px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 28px;
}
.tab-btn {
  font-family: var(--serif);
  font-size: 0.95rem;
  padding: 9px 17px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 999px;
}
.tab-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  box-shadow: 0 4px 12px rgba(39, 107, 82, 0.18);
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px 48px;
}
main, .tab-panel, .card, #allocation-dashboard { min-width: 0; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 22px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}

.field {
  display: inline-flex;
  flex-direction: column;
  margin: 5px 10px 5px 0;
  font-size: 0.85rem;
  vertical-align: top;
}
.field.wide { min-width: 240px; }
.field label { color: var(--ink-soft); margin-bottom: 3px; }
.field input, .field select {
  font-family: var(--mono);
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: #fff;
}
.field input:focus, .field select:focus, .goal-picker select:focus, .goal-picker input:focus { outline: 3px solid rgba(39, 107, 82, 0.13); border-color: var(--accent); }
.readonly-value { min-height: 38px; padding: 9px 10px; border: 1px solid var(--rule); border-radius: 9px; background: var(--accent-soft); }

.btn {
  font-family: var(--serif);
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
}
.btn.small { padding: 7px 11px; font-size: 0.8rem; }
.btn.danger { background: var(--negative); }
.btn.primary { font-weight: bold; }
.btn:hover { background: var(--accent-strong); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { padding: 10px 9px; border-bottom: 1px solid var(--rule); text-align: left; font-size: 0.88rem; }
th { color: var(--ink-soft); font-weight: 600; border-bottom: 1px solid var(--rule); }

.mono { font-family: var(--mono); }
.mono.big { font-size: 1.3rem; }
.neg { color: var(--negative); }
.over { color: var(--over-limit); font-weight: bold; }

.summary-block { margin-bottom: 22px; }
.summary-block.highlight { background: linear-gradient(145deg, #EDF6F1, #E3F0E9); padding: 16px; border-radius: 12px; }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.dashboard-card h2 { margin: 0 0 6px; font-size: 1.25rem; }
.dashboard-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.dashboard-summary .summary-block { margin-bottom: 0; }
.dashboard-mini-card { min-width: 0; padding: 13px 14px; border: 1px solid var(--rule); border-radius: 11px; background: linear-gradient(145deg, #F7FBF9, var(--accent-soft)); }
.dashboard-mini-card h3 { margin: 0 0 7px; padding: 0 0 5px; font-size: 0.88rem; }
.dashboard-mini-value { margin: 8px 0 5px; font-size: 1.12rem; font-weight: 700; overflow-wrap: anywhere; }
.dashboard-mini-card .notice { margin: 0; font-size: 0.76rem; }
.dashboard-mini-card.negative-card { border-color: #E8D7DA; background: #FCF6F7; }
.dashboard-mini-card.watch-card { border-color: #EADFC8; background: #FCF9F2; }
.dashboard-mini-value.watch { color: var(--over-limit); }
.dashboard-mini-card.missing-card { border-style: dashed; background: #FAFBFA; }
.summary-card-setting-row { display: grid; grid-template-columns: auto minmax(140px, 1fr) minmax(170px, 1.2fr) auto; gap: 8px; align-items: center; margin: 8px 0; }
.summary-card-setting-row input[type="text"], .summary-card-setting-row select { width: 100%; min-height: 36px; padding: 7px 9px; border: 1px solid var(--rule); border-radius: 9px; background: #fff; color: var(--ink); }
.compact-settings { border-top: 1px solid var(--rule); padding: 10px 0; }
.compact-settings summary { cursor: pointer; color: var(--accent); font-weight: 650; }
.goal-picker { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(130px, 180px) minmax(130px, 170px); gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.goal-picker select, .goal-picker input[type="month"], .compact-settings select { min-height: 38px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 9px; background: #fff; font-family: var(--serif); }
.badge { display: inline-block; margin-left: 7px; padding: 1px 6px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 0.72rem; }
/* 分配表：左側 3px 色條＝狀態（沿用主色綠／超限橙／負值紅），不足的列加極淡底色 */
.allocation-table td:first-child { border-left: 3px solid transparent; }
.allocation-row.level-ok td:first-child { border-left-color: var(--accent); }
.allocation-row.level-watch td:first-child { border-left-color: var(--over-limit); }
.allocation-row.level-short td:first-child { border-left-color: var(--negative); }
.allocation-row.level-short { background: rgba(161, 62, 69, 0.05); }
.allocation-label { font-weight: 600; }
.allocation-account { margin-top: 2px; font-size: 0.78rem; color: var(--ink-soft); }
.allocation-amount { white-space: nowrap; }
.allocation-status { font-size: 0.86rem; line-height: 1.5; }
/* 原因類別：跟 .badge 同形狀，顏色依狀態 */
.status-tag { display: inline-block; margin-right: 6px; padding: 0 7px; border-radius: 10px; font-size: 0.72rem; font-weight: 500; vertical-align: 1px; }
.status-tag.tag-watch { background: #FCF1EA; color: var(--over-limit); }
.status-tag.tag-short { background: #FCF0F2; color: var(--negative); }
.allocation-status.status-short { color: var(--negative); }
.allocation-status.status-watch { color: var(--over-limit); }
.allocation-status.status-none { color: var(--ink-soft); }
/* 結論一行粗體，原因與參考數字小字灰色，一眼分出主旨與因果 */
.allocation-status .status-headline { font-weight: 600; }
.allocation-status .status-detail { font-size: 0.8rem; color: var(--ink-soft); }
/* 目標時間：填法選單與數值並排 */
.target-time { display: flex; gap: 6px; }
.target-time select { flex: 0 0 auto; }
.target-time input { flex: 1 1 auto; min-width: 0; }
.estimate-notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; margin: 0 0 12px; padding: 10px 14px; border: 1px solid #EADFC8; border-radius: 10px; background: #FCF9F2; font-size: 0.88rem; }
.estimate-notice p { margin: 0; flex: 1 1 280px; }
/* 首頁結論（結論模式）：一句結論、分配長條、生活費滑桿、緊急預備金進度、要做的事 */
.home-overview { display: grid; gap: 10px; }
.home-overview p { margin: 0; }
.home-sample { font-size: 0.85rem; color: var(--over-limit); display: flex; align-items: center; gap: 8px; }
.home-headline { font-size: 1.35rem; font-weight: 700; }
.home-overview.level-short .home-headline { color: var(--negative); }
.home-overview.level-watch .home-headline { color: var(--over-limit); }
.home-daily { color: var(--ink-soft); }
.home-bar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: var(--rule); }
.home-bar span { min-width: 3px; }
.seg-fixed { --seg: #8A9A92; }
.seg-living { --seg: #4F9A7A; }
.seg-saving { --seg: var(--accent-strong); }
.seg-spare { --seg: #C9DDD2; }
.seg-short { --seg: var(--negative); }
.home-bar span { background: var(--seg); }
.home-bar .seg-short { background: repeating-linear-gradient(45deg, var(--negative) 0 4px, #E9C3C9 4px 8px); }
.home-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; list-style: none; font-size: 0.85rem; }
.home-legend li::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 2px; background: var(--seg); }
.home-slider, .home-progress { display: grid; gap: 4px; font-size: 0.9rem; }
.home-slider input, .home-progress progress { width: 100%; accent-color: var(--accent); }
.home-actions { margin: 0; padding-left: 1.3em; }
.home-actions li { margin: 4px 0; }
.home-ok { color: var(--accent); }
body[data-view-mode="detailed"] .simple-only { display: none !important; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; }
.health-critical, .health-risk { color: var(--negative); }
.health-watch { color: var(--over-limit); }
.health-healthy, .health-strong { color: var(--accent); }
.savings-issues { margin: 14px 0; padding: 12px 14px; border: 1px solid #E8D7DA; border-radius: 10px; background: #FCF6F7; color: var(--negative); font-size: 0.86rem; }
.savings-issues ul { margin: 7px 0 0; padding-left: 20px; }
.savings-strengths { margin: 14px 0; padding: 12px 14px; border: 1px solid #CBE3D6; border-radius: 10px; background: #F2FAF6; color: var(--accent-strong); font-size: 0.86rem; }
.savings-strengths ul { margin: 7px 0 0; padding-left: 20px; }
.summary-block h3 { margin: 0 0 8px; font-size: 1rem; border-bottom: 1px solid var(--rule); padding-bottom: 4px; }

.result-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); }
.result-block p { margin: 6px 0; }

/* 成本試算沿用全站設計系統，欄位、清單與結果只在此區調整版面。 */
.estimator-shell { overflow: hidden; }
.estimator-controls { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 14px 0 20px; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 12px; background: #FAFCFB; }
.estimator-controls .field { margin: 0; }
.scenario-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: -8px 0 18px; }
.control-check { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; color: var(--ink-soft); font-size: 0.86rem; cursor: pointer; }
.estimator-field-grid, .estimator-option-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 14px 0; }
.estimator-field { display: flex; width: 100%; margin: 0; min-width: 0; }
.estimator-field input, .estimator-field select { width: 100%; }
.estimator-option-grid .estimator-field > span { color: var(--ink-soft); margin-bottom: 3px; }
#estimator-body input:not([type="checkbox"]), #estimator-body select { min-height: 38px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 9px; background: #fff; font-family: var(--mono); color: var(--ink); }
#estimator-body input:focus, #estimator-body select:focus { outline: 3px solid rgba(39, 107, 82, 0.13); border-color: var(--accent); }
.estimator-items-table { min-width: 520px; }
.estimator-items-table input { width: 100%; }
.estimator-items-table td:nth-child(2) { width: 34%; }
.estimator-items-table td:last-child { width: 1%; white-space: nowrap; }
.estimator-section { margin: 12px 0; padding: 10px 14px; border: 1px solid var(--rule); border-radius: 12px; background: #FAFCFB; }
#estimator-body > .result-block { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 18px; margin-top: 18px; padding: 16px; border: 1px solid var(--rule); border-radius: 12px; background: linear-gradient(145deg, #F5FAF7, var(--accent-soft)); }
#estimator-body > .result-block details { grid-column: 1 / -1; }
.period-block h4 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.period-block h4 > input { flex: 1 1 180px; }
.student-loan-plan { margin-top: 18px; background: #F8FBF9; }
.student-loan-plan a { color: var(--accent); font-weight: 650; }
.student-loan-summary { margin: 14px 0; }
.student-loan-summary .summary-block { margin-bottom: 0; }
.loan-overview-home { margin: 14px 0; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--accent-soft); }
.loan-overview-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-top: 1px solid rgba(39, 107, 82, 0.16); }
.loan-overview-row p { margin: 3px 0 0; }
.setup-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; padding: 0; list-style: none; counter-reset: setup; }
.setup-steps li { counter-increment: setup; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 10px; background: #fff; color: var(--ink-soft); font-size: 0.84rem; }
.setup-steps li::before { content: counter(setup); display: inline-grid; place-items: center; width: 21px; height: 21px; margin-right: 7px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 0.75rem; }
.student-loan-toggle { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0; padding: 13px 14px; border: 1px solid var(--accent); border-radius: 11px; background: var(--accent-soft); cursor: pointer; }
.student-loan-toggle input { margin-top: 3px; }
.student-loan-toggle span { display: grid; gap: 3px; }
.student-loan-toggle small { color: var(--ink-soft); }
.mortgage-stress { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 11px; background: #fff; }
.mortgage-stress span { padding: 5px 9px; border-radius: 999px; background: var(--paper); color: var(--ink-soft); font-family: var(--mono); font-size: 0.8rem; }

.formula {
  background: #fff;
  border: 1px solid var(--rule);
  padding: 10px;
  font-size: 0.85rem;
  white-space: pre-wrap;
  border-radius: 10px;
}

.period-block { margin: 14px 0; padding: 14px; background: #fff; border: 1px solid var(--rule); border-radius: 12px; }
.period-block h4 { margin: 0 0 6px; }

.notice { color: var(--ink-soft); font-size: 0.85rem; margin-bottom: 12px; overflow-wrap: anywhere; }

.achievability { background: var(--accent-soft); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; margin-top: 12px; }
.achievability p { margin: 4px 0; }
.period-block.leave { opacity: 0.6; background: repeating-linear-gradient(45deg, #fff, #fff 8px, var(--rule) 8px, var(--rule) 9px); }
.inline-check { font-size: 0.8rem; font-weight: normal; color: var(--ink-soft); }

.toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.section-heading h3 { margin: 0 0 4px; }
.section-heading .notice { margin: 0 0 12px; }
.source-field { min-width: min(360px, 100%); }
.linked-note { margin: 4px 0 16px; padding: 10px 12px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-strong); font-size: 0.86rem; }
details > summary { cursor: pointer; padding: 5px 0; font-weight: 600; }

/* 固定項目卡片：收合時一行看懂（名稱・方式・每月金額・下次繳款），展開才編輯 */
.flow-card { padding: 0; }
.flow-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; padding: 14px 18px; list-style-position: inside; }
.flow-name { font-weight: 700; }
.flow-tag { padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 0.8rem; font-weight: 600; }
.flow-tag.warn { background: #FBE9E7; color: var(--over-limit); }
.flow-amount { margin-left: auto; font-weight: 700; }
.flow-amount.negative { color: var(--negative); }
.flow-amount.positive { color: var(--accent-strong); }
.flow-next { flex-basis: 100%; color: var(--ink-soft); font-size: 0.82rem; font-weight: normal; }
.flow-body { padding: 0 18px 16px; }
.flow-sub { margin: 10px 0 0; padding: 8px 12px; border: 1px solid var(--rule); border-radius: 10px; }
.flow-result, .income-result { margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 0.88rem; }
.flow-result p, .income-result p { margin: 2px 0; }
.basis-picker { display: inline-flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.basis-option { display: inline-flex; flex-direction: column; padding: 6px 12px; border: 1px solid var(--rule); border-radius: 9px; background: #fff; cursor: pointer; font-size: 0.85rem; }
.basis-option input { position: absolute; opacity: 0; pointer-events: none; }
.basis-option span { color: var(--ink-soft); font-size: 0.75rem; }
.basis-option.active { border-color: var(--accent); background: var(--accent-soft); }
.basis-option:focus-within { outline: 3px solid rgba(39, 107, 82, 0.25); }
.income-fields { display: flex; flex-wrap: wrap; }
.income-field small { margin-top: 2px; color: var(--ink-soft); font-size: 0.75rem; }
.input-unit { display: flex; align-items: center; gap: 6px; }
.input-unit input { width: 120px; }
.input-unit span { color: var(--ink-soft); font-size: 0.8rem; white-space: nowrap; }
.income-formula { font-family: var(--mono); overflow-wrap: anywhere; }
.income-net strong { font-size: 1.1rem; color: var(--accent-strong); }
.income-sub, .income-hint { color: var(--ink-soft); font-size: 0.8rem; }
.income-hint { margin: 4px 0 0; }
.big-check { margin-right: 12px; }
.bracket-choice { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; }
.pay-schedule { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pay-chip { padding: 2px 8px; border: 1px solid var(--rule); border-radius: 7px; background: #fff; font-size: 0.8rem; }
.fee-row { align-items: center; }

footer.io-bar {
  max-width: 1224px;
  margin: 24px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
footer.io-bar span { color: var(--ink-soft); font-size: 0.85rem; }
.storage-status { flex: 1 0 100%; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin-top: 8px; padding: 13px 15px; border: 1px solid var(--rule); border-radius: 11px; background: var(--paper-card); color: var(--ink-soft); }
.storage-status strong { color: var(--ink); }
.storage-status small { grid-column: 1 / -1; line-height: 1.55; }
.storage-status.failed #storage-status-text { color: var(--negative); }
.storage-location-button { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }
.save-indicator { position: fixed; right: 16px; bottom: 16px; z-index: 30; display: flex; align-items: center; gap: 8px; max-width: min(430px, calc(100vw - 32px)); padding: 9px 12px; border: 1px solid var(--rule); border-radius: 999px; background: rgba(255, 253, 248, 0.96); box-shadow: 0 5px 20px rgba(50, 43, 35, 0.13); color: var(--ink-soft); font-size: 0.78rem; backdrop-filter: blur(8px); }
.save-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--positive); }
.save-indicator.failed .save-dot { background: var(--negative); }
.file-binding-row { align-items: center; }
.file-binding-name { overflow-wrap: anywhere; color: var(--ink); }

@media (max-width: 720px) {
  header.masthead { align-items: flex-start; flex-direction: column; gap: 12px; }
  header.masthead, nav.tabs, main { padding-left: 16px; padding-right: 16px; }
  main { width: 100vw; max-width: 100vw; overflow: hidden; }
  .tab-panel, .card { width: 100%; max-width: 100%; }
  footer.io-bar { margin-left: 16px; margin-right: 16px; }
  nav.tabs { overflow-x: auto; }
  .card { padding: 17px; border-radius: 12px; }
  .dashboard-card { width: 100%; max-width: 100%; overflow: hidden; contain: inline-size; }
  #allocation-dashboard { width: 100%; max-width: 100%; overflow: hidden; }
  .health-grid { grid-template-columns: 1fr; }
  .flow-amount { margin-left: 0; }
  .dashboard-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-card-setting-row { grid-template-columns: 1fr; align-items: stretch; padding-bottom: 10px; border-bottom: 1px solid var(--rule); }
  .goal-picker { grid-template-columns: 1fr; }
  /* 手機：每列堆疊成「用途｜金額」一行、狀態佔滿下一行；色條移到整列左側 */
  table.allocation-table, table.allocation-table tbody { display: block; }
  table.allocation-table thead { display: none; }
  table.allocation-table tr { display: grid; grid-template-columns: 1fr auto; border-left: 3px solid transparent; border-bottom: 1px solid var(--rule); }
  table.allocation-table td { border-bottom: none; }
  table.allocation-table td:first-child { border-left: none; }
  table.allocation-table .allocation-amount { text-align: right; }
  table.allocation-table .allocation-status { grid-column: 1 / -1; padding-top: 0; }
  .allocation-row.level-ok { border-left-color: var(--accent); }
  .allocation-row.level-watch { border-left-color: var(--over-limit); }
  .allocation-row.level-short { border-left-color: var(--negative); }
  .estimator-controls { align-items: stretch; }
  .estimator-controls .field, .estimator-controls .control-check { width: 100%; }
  .scenario-actions .btn { flex: 1 1 140px; }
  .estimator-field-grid, .estimator-option-grid { grid-template-columns: 1fr; }
  .setup-steps { grid-template-columns: 1fr; }
  .loan-overview-row { align-items: stretch; flex-direction: column; }
}

/* 全站元件規格：所有分頁共用同一套表單、結果、狀態與互動呈現。 */
:root {
  --radius-sm: 10px;
  --focus-ring: 0 0 0 3px rgba(39, 107, 82, 0.14);
  --space-section: 16px;
}

button, input, select, textarea { font: inherit; }
button, select, input[type= checkbox], input[type=radio] { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--focus-ring); }

h2, h3, h4 { color: var(--ink); }
h2 { letter-spacing: -0.01em; }
.card { padding: 20px; margin: var(--space-section) 0; }

.field input, .field select, .field textarea,
.goal-picker select, .goal-picker input[type=month],
.compact-settings select,
.summary-card-setting-row input[type=text], .summary-card-setting-row select,
#estimator-body input:not([type=checkbox]), #estimator-body select {
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--paper-card);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus,
.goal-picker select:focus, .goal-picker input:focus,
.compact-settings select:focus,
.summary-card-setting-row input[type=text]:focus, .summary-card-setting-row select:focus,
#estimator-body input:focus, #estimator-body select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.field input:disabled, .field select:disabled, #estimator-body input:disabled, #estimator-body select:disabled { background: var(--paper); color: var(--ink-soft); cursor: not-allowed; }

.btn { min-height: 40px; border-radius: var(--radius-sm); box-shadow: 0 2px 5px rgba(28, 67, 52, 0.08); transition: background .15s ease, transform .15s ease, box-shadow .15s ease; }
.btn.small { min-height: 36px; border-radius: 9px; }
.btn:hover { box-shadow: 0 4px 10px rgba(28, 67, 52, 0.14); }
.btn.danger:hover { background: #842F3D; }
.btn:focus-visible { box-shadow: var(--focus-ring), 0 2px 5px rgba(28, 67, 52, 0.08); }
/* 二選一切換（帳本的帳戶核對／逐筆記帳）：沒選中的一顆改成外框，看得出目前在哪個模式 */
.btn[aria-pressed="false"] { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.btn[aria-pressed="false"]:hover { background: transparent; }

.summary-block { margin-bottom: 0; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--paper-card); }
.summary-block.highlight { border-color: #CBE3D6; }
.summary-block h3 { margin-bottom: 8px; }
.health-grid, .dashboard-summary { align-items: stretch; }
.dashboard-mini-card { padding: 14px 16px; border-radius: 12px; }

.result-block, .achievability, .estimator-section, .period-block, .loan-overview-home, .mortgage-stress, .linked-note, .student-loan-toggle {
  border-radius: 12px;
}
.result-block { padding: 16px; border: 1px solid var(--rule); background: var(--paper-card); }
.formula { margin: 8px 0 0; border-radius: var(--radius-sm); background: var(--paper); line-height: 1.6; }
.notice { line-height: 1.55; }

.compact-settings { padding: 12px 0; }
.compact-settings summary, details > summary { min-height: 36px; padding: 8px 0; color: var(--accent); }
.compact-settings summary:focus-visible, details > summary:focus-visible { outline: none; border-radius: 6px; box-shadow: var(--focus-ring); }

.table-scroll { border-radius: var(--radius-sm); }
table { margin-top: 12px; }
th { background: var(--paper); white-space: nowrap; }
tbody tr:hover { background: rgba(229, 241, 235, 0.52); }
tbody tr:last-child td { border-bottom: 0; }

.savings-issues, .savings-strengths { border-radius: 12px; line-height: 1.55; }
.loan-overview-home { margin: var(--space-section) 0; padding: 16px; }
.estimator-controls, .estimator-section { background: #FAFCFB; }

@media (max-width: 720px) {
  .card { padding: 16px; }
  .btn { min-height: 42px; }
  .btn.small { min-height: 38px; }
  .dashboard-summary { gap: 8px; }
  .dashboard-mini-card { padding: 12px; }
  th, td { padding: 9px 8px; }
}
.trend-chart { width: 100%; height: auto; }

/* 帳本預測帳目：實際金額欄位與確認按鈕同一格 */
#ledger-table-body .confirm-amount { width: 7em; margin-right: 4px; }
#ledger-table-body td .badge { margin-left: 4px; }
