/* ライフプラン — 赤系テーマ */
:root {
  --red: #d0483e;
  --red-dark: #9c2b23;
  --red-pale: #fbe9e6;
  --red-soft: #f3a49d;
  --ink: #33231f;
  --muted: #857069;
  --line: #ecd9d4;
  --bg: #fef4f2;
  --card: #ffffff;
  --danger: #b3261e;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overscroll-behavior: none; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--red-dark); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.app-title { font-size: 19px; font-weight: 700; }

main { padding: 12px 12px 92px; max-width: 640px; margin: 0 auto; }
.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.note { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 8px 0 0; }

.row-between { display: flex; align-items: center; justify-content: space-between; }
.row-gap { display: flex; gap: 8px; margin-top: 10px; }
.grow { flex: 1; }
.year-label { font-size: 14px; color: var(--muted); }
.year-select {
  font-size: 16px; font-weight: 700; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px; background: #fff;
  margin-left: 6px;
}
.text-input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 10px; background: #fff; color: var(--ink);
}
.text-input:focus { outline: 2px solid var(--red); outline-offset: 0; border-color: var(--red); }

.chip-row { display: flex; gap: 8px; margin-top: 10px; }
.chip-row.wrap { flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: 14px;
}
.chip.active { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.chip .dot { color: var(--red-soft); font-size: 10px; }
.chip.active .dot { color: #ffd9d4; }

.add-btn {
  width: 100%; margin-top: 12px; padding: 11px;
  background: var(--red-pale); color: var(--red-dark);
  border: 1.5px dashed var(--red); border-radius: 11px; font-weight: 700; font-size: 15px;
}
.primary-btn {
  background: var(--red); color: #fff; border: none; border-radius: 11px;
  padding: 12px 18px; font-weight: 700; font-size: 15px;
}
.primary-btn:disabled { opacity: .5; }
.primary-btn.block { width: 100%; margin-top: 6px; }
.sub-btn {
  background: #fff; color: var(--ink); border: 1.5px solid var(--line); border-radius: 11px;
  padding: 11px 14px; font-size: 14px;
}
.sub-btn.block { width: 100%; margin-top: 6px; }
.sub-btn.danger-text { color: var(--danger); }
.icon-btn {
  background: var(--red-pale); border: 1px solid var(--line); border-radius: 10px;
  font-size: 18px; padding: 6px 12px;
}

.totals { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.total-box {
  flex: 1 1 30%; background: var(--red-pale); border-radius: 11px; padding: 9px 10px; min-width: 96px;
}
.total-box .t-label { font-size: 11.5px; color: var(--muted); }
.total-box .t-value { font-size: 17px; font-weight: 700; margin-top: 2px; }
.total-box .t-value.neg { color: var(--red-dark); }

.group-title {
  font-size: 13px; font-weight: 700; color: var(--red-dark);
  margin: 14px 0 4px; padding-bottom: 3px; border-bottom: 1px solid var(--line);
}
.kv-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 2px; border-bottom: 1px dotted var(--line); font-size: 14px;
}
.kv-row:last-child { border-bottom: none; }
.kv-row .kv-name { color: var(--ink); }
.kv-row .kv-val { font-weight: 600; white-space: nowrap; }
.kv-row .kv-val.neg { color: var(--red-dark); }
.kv-row.dim .kv-name { color: var(--muted); }

.item-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; text-align: left; background: #fff; border: none; border-bottom: 1px dotted var(--line);
  padding: 9px 2px; font-size: 14px;
}
.item-row:last-child { border-bottom: none; }
.item-row .i-main { min-width: 0; }
.item-row .i-name { font-weight: 600; }
.item-row .i-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.item-row .i-chev { color: var(--muted); }

.year-row {
  display: grid; grid-template-columns: 74px 1fr auto; gap: 6px; align-items: baseline;
  width: 100%; text-align: left; background: #fff; border: none; border-bottom: 1px dotted var(--line);
  padding: 8px 2px; font-size: 13.5px;
}
.year-row:last-child { border-bottom: none; }
.year-row.selected { background: var(--red-pale); border-radius: 8px; }
.year-row .y-year { font-weight: 700; }
.year-row .y-ages { color: var(--muted); font-size: 12px; }
.year-row .y-bal { font-weight: 600; }
.year-row .y-bal.neg { color: var(--red-dark); }
.year-row .y-total { font-weight: 700; text-align: right; }

.gate {
  position: fixed; inset: 0; background: var(--bg); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate[hidden] { display: none; }
.gate-card { text-align: center; max-width: 320px; }
.gate-icon { font-size: 52px; }
.gate-title { font-size: 22px; font-weight: 700; margin: 10px 0 4px; }
.gate-note { color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.gate-error { color: var(--danger); font-size: 13.5px; min-height: 1em; }
.google-btn { display: flex; justify-content: center; margin: 14px 0; }

.page {
  position: fixed; inset: 0; background: var(--bg); z-index: 30; overflow-y: auto;
  padding: 12px 12px 40px;
}
.page[hidden] { display: none; }
.page-head { display: flex; align-items: center; gap: 10px; max-width: 640px; margin: 0 auto 10px; }
.page-head h3 { margin: 0; font-size: 18px; }
.page .card { max-width: 640px; margin-left: auto; margin-right: auto; }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(40, 16, 12, .45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: #fff; width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-head-right { display: flex; align-items: center; gap: 8px; }
.close-btn {
  background: none; border: none; font-size: 19px; color: var(--muted); padding: 4px 8px;
}
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }
.field { display: block; margin-top: 12px; font-size: 13.5px; }
.field > span { display: block; color: var(--muted); margin-bottom: 5px; }
.field-hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.field .money { text-align: right; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar[hidden] { display: none; }
.tab {
  flex: 1; background: none; border: none; padding: 8px 0 7px;
  font-size: 19px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tab span { font-size: 11px; }
.tab.active { color: var(--red-dark); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 999px; padding: 9px 18px; font-size: 13.5px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); white-space: nowrap;
}
.toast[hidden] { display: none; }

.chart-wrap { margin-top: 8px; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.chart-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.empty-note { color: var(--muted); font-size: 13.5px; text-align: center; padding: 14px 0 4px; }
