/* 単価逆算ナビ スタイル */
:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #616e7c;
  --line: #d9e2ec;
  --primary: #1d4ed8;
  --primary-weak: #e0e7ff;
  --danger: #b91c1c;
  --c-net: #2563eb;
  --c-expenses: #64748b;
  --c-pension: #0d9488;
  --c-nhi: #16a34a;
  --c-incomeTax: #d97706;
  --c-residentTax: #db2777;
  --c-bizTax: #7c3aed;
  --v-deficit: #dc2626;
  --v-deficit-bg: #fee2e2;
  --v-minimum: #b45309;
  --v-minimum-bg: #fef3c7;
  --v-fair: #15803d;
  --v-fair-bg: #dcfce7;
  --v-comfortable: #1d4ed8;
  --v-comfortable-bg: #dbeafe;
}

* { box-sizing: border-box; }

/* display を指定した要素でも hidden 属性で確実に隠す */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

h1, h2, p { margin: 0; }

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

.small { font-size: 0.85rem; }
.muted { color: var(--muted); }
.strong { font-weight: 700; }

/* ヘッダー */
.site-header {
  background: var(--panel);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: grid;
  gap: 8px;
}
.brand h1 { font-size: 1.4rem; color: var(--primary); }
.tagline { font-size: 0.9rem; color: var(--muted); }
.notice {
  font-size: 0.85rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  padding: 4px 10px;
}
.profile-bar { display: grid; gap: 6px; }
.profile-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.profile-row select, .profile-row input { min-width: 0; flex: 1 1 160px; }
.dirty { font-size: 0.8rem; color: var(--v-minimum); font-weight: 700; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.tabs-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  gap: 4px;
  padding: 0 16px;
  overflow-x: auto;
}
.tabs a {
  flex: 0 0 auto;
  padding: 6px 12px;
  text-decoration: none;
  color: var(--primary);
  border-bottom: 3px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
}
.tabs a:hover, .tabs a:focus { border-bottom-color: var(--primary); }

/* 本体 */
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.step { margin-bottom: 28px; scroll-margin-top: 48px; }
.step > h2 {
  font-size: 1.15rem;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 5px solid var(--primary);
}
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}

/* フォーム */
.field { display: grid; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field label, .field > .label { font-weight: 700; font-size: 0.9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 0.8rem; color: var(--muted); }
input[type="text"], input[type="number"], select, textarea {
  font: inherit;
  font-size: 1rem;
  padding: 7px 9px;
  border: 1px solid #bcccdc;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .tabs a:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 1px;
}
.with-unit { display: flex; align-items: center; gap: 6px; }
.with-unit input { text-align: right; }
.unit { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

.advanced {
  margin-top: 8px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}
.advanced summary { cursor: pointer; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.adv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-top: 8px; }

.btn {
  display: inline-block;
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid #9fb3c8;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: #f0f4f8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--danger); border-color: #fca5a5; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.icon { padding: 4px 10px; }

/* 結果 */
.label { font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.value { font-size: 1.3rem; font-weight: 700; }
.sub-box {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.big-result { margin-bottom: 12px; }
.big { font-size: 2.2rem; font-weight: 800; color: var(--primary); line-height: 1.2; word-break: break-all; }
.warning {
  background: var(--v-deficit-bg);
  color: var(--v-deficit);
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 8px 10px;
  font-weight: 700;
  margin: 8px 0;
}

/* 積み上げ横棒 */
.chart { margin: 8px 0; }
.bar {
  display: flex;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  background: #e5e7eb;
}
.seg { height: 100%; min-width: 0; }
.legend {
  list-style: none;
  padding: 0;
  margin: 6px 0 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.8rem;
}
.legend li { display: flex; align-items: center; gap: 4px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.c-net { background: var(--c-net); }
.c-expenses { background: var(--c-expenses); }
.c-pension { background: var(--c-pension); }
.c-nhi { background: var(--c-nhi); }
.c-incomeTax { background: var(--c-incomeTax); }
.c-residentTax { background: var(--c-residentTax); }
.c-bizTax { background: var(--c-bizTax); }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { color: var(--muted); font-size: 0.8rem; }
.table .num { text-align: right; white-space: nowrap; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.table-wrap { overflow-x: auto; margin-bottom: 8px; }
.items-table td { padding: 4px; }
.items-table input[type="number"] { text-align: right; width: 6.5em; }
.items-table .empty { color: var(--muted); text-align: center; padding: 12px; }

/* 単価カード */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; }
.card.accent { border-color: var(--primary); background: var(--primary-weak); }
.card .value { font-size: 1.35rem; word-break: break-all; }

.facts { margin: 0 0 8px; display: grid; gap: 4px; }
.facts > div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted var(--line); padding: 3px 0; }
.facts dt { color: var(--muted); font-size: 0.9rem; }
.facts dd { margin: 0; font-weight: 700; text-align: right; }

/* 判定 */
.verdict {
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  border: 2px solid;
}
.verdict-icon { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.verdict-label { font-size: 1.2rem; font-weight: 800; }
.verdict.deficit { color: var(--v-deficit); background: var(--v-deficit-bg); border-color: var(--v-deficit); }
.verdict.minimum { color: var(--v-minimum); background: var(--v-minimum-bg); border-color: var(--v-minimum); }
.verdict.fair { color: var(--v-fair); background: var(--v-fair-bg); border-color: var(--v-fair); }
.verdict.comfortable { color: var(--v-comfortable); background: var(--v-comfortable-bg); border-color: var(--v-comfortable); }

.scale-wrap { margin-top: 8px; }
.scale {
  position: relative;
  height: 30px;
  margin: 26px 0 8px;
  border-radius: 6px;
  overflow: visible;
}
.zone { position: absolute; top: 0; height: 100%; }
.zone.deficit { background: var(--v-deficit-bg); border-bottom: 4px solid var(--v-deficit); }
.zone.minimum { background: var(--v-minimum-bg); border-bottom: 4px solid var(--v-minimum); }
.zone.fair { background: var(--v-fair-bg); border-bottom: 4px solid var(--v-fair); }
.zone.comfortable { background: var(--v-comfortable-bg); border-bottom: 4px solid var(--v-comfortable); }
.zone span { position: absolute; left: 4px; top: 4px; font-size: 0.7rem; font-weight: 700; white-space: nowrap; overflow: hidden; max-width: calc(100% - 6px); }
.tick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #334e68; }
.marker {
  position: absolute;
  top: -24px;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
  color: var(--text);
}
.marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text);
}
.scale-legend { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; display: grid; gap: 2px; }
.scale-legend li { display: flex; justify-content: space-between; gap: 8px; }

/* サマリー */
.checks { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.checks legend { font-weight: 700; font-size: 0.9rem; padding: 0 4px; }
.checks label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
textarea { font-family: inherit; resize: vertical; line-height: 1.6; }
.summary-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }

/* フッター */
.site-footer { background: #e4e7eb; border-top: 1px solid var(--line); margin-top: 20px; }
.footer-inner { max-width: 1200px; margin: 0 auto; padding: 16px; }
.footer-inner h2 { font-size: 1rem; margin-bottom: 6px; }
.footer-inner ul { margin: 0 0 12px; padding-left: 1.2em; }
.footer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #102a43;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  z-index: 100;
  max-width: calc(100% - 32px);
  font-size: 0.9rem;
}
.toast.error { background: var(--danger); }

/* レスポンシブ（768px 未満は1カラム） */
@media (max-width: 767px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .adv-grid { grid-template-columns: 1fr; }
  .big { font-size: 1.8rem; }
  .brand h1 { font-size: 1.2rem; }
}
@media (max-width: 420px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .panel { padding: 12px; }
}
