/* =====================================================================
   固定費ダイエット — ビジュアルアイデンティティ「請求明細書 × 圧縮ゲージ」
   題材接地: 毎月の請求明細／契約／メーター。"ダイエット"=固定費の圧縮。
   AIデフォルト(dark+emerald同型クローン)を排除し、本アプリ固有の見た目に。
   - 冷涼なオフィス用紙(#eef1f5)＋ink navy＋official blue＋数字はタブ揃え等幅。
   - 明細の罫線・行末リーダードット・右寄せ金額＝請求書の語彙。
   - signature: 見直し率で年額バーが横に圧縮される「圧縮ゲージ」。
   ===================================================================== */

:root {
  --paper:      #eef1f5;   /* オフィス用紙(冷色・cream回避) */
  --paper-2:    #e3e8ef;
  --sheet:      #ffffff;   /* 明細シート面 */
  --ink:        #16233b;   /* 文字(ink navy) */
  --ink-soft:   #56657d;
  --ink-faint:  #8b97a8;
  --rule:       #d3dae3;   /* 細罫 */
  --rule-strong:#16233b;
  --accent:     #1f63d6;   /* official blue(emerald回避) */
  --accent-ink: #14418f;
  --save:       #0e7a5f;   /* 減額・節約の数字だけに使う緑 */
  --seal:       #b4392b;   /* 朱印(ダイエット印) */
  --gold:       #9a6b16;

  --sans: "BIZ UDPGothic", "Yu Gothic", YuGothic, "Hiragino Kaku Gothic ProN",
          "Meiryo", system-ui, sans-serif;
  --mono: "SFMono-Regular", "Consolas", "Roboto Mono", "DejaVu Sans Mono",
          ui-monospace, monospace;

  --maxw: 760px;
  --r: 4px;                /* 角丸は控えめ(書類感) */
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(22,35,59,0.035) 31px 32px),
    var(--paper);
  line-height: 1.7;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.container { width: min(100% - 40px, var(--maxw)); margin-inline: auto; }

/* 数字は常にタブ揃え等幅(明細の要) */
.amount, .result-total-amount, .saving-amount, .sticky-total,
.compound-table td, .item-price-badge, .gauge-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ===== Header (letterhead) ===== */
.site-header {
  background: var(--ink);
  color: var(--paper);
  border-bottom: 3px solid var(--accent);
}
.site-header .container {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 14px 0;
}
.site-logo {
  font-weight: 800; font-size: 1.2rem; letter-spacing: 0.04em;
}
.site-logo::before {
  content: "明細 No.0001 ／ ";
  font-family: var(--mono); font-weight: 400; font-size: 0.7rem;
  color: var(--accent); letter-spacing: 0.08em; margin-right: 2px;
}
.site-tagline { color: #b7c4da; font-size: 0.82rem; }

/* ===== Hero (thesis, not big-number template) ===== */
.hero {
  width: min(100% - 40px, var(--maxw)); margin: 40px auto 28px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-top: 6px solid var(--ink);
  border-radius: var(--r);
  padding: 34px 30px 30px;
  position: relative;
  box-shadow: 0 1px 0 rgba(22,35,59,0.04), 0 18px 40px -28px rgba(22,35,59,0.4);
}
.hero::before {
  content: "STATEMENT OF FIXED COSTS";
  position: absolute; top: 14px; right: 18px;
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.22em;
  color: var(--ink-faint);
}
.hero-title {
  margin: 4px 0 14px; font-size: clamp(1.7rem, 5.4vw, 2.5rem);
  font-weight: 800; line-height: 1.28; letter-spacing: 0.005em;
}
.hero-title .accent {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.12em;
  text-decoration-color: rgba(31,99,214,0.35);
}
.hero-subtitle { margin: 0 0 22px; color: var(--ink-soft); font-size: 0.98rem; }
.btn-hero {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; text-decoration: none;
  font-weight: 800; font-size: 1rem;
  padding: 13px 26px; border-radius: var(--r);
  border: 1px solid var(--accent-ink);
  box-shadow: 0 2px 0 var(--accent-ink);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn-hero::after { content: "→"; font-family: var(--mono); }
.btn-hero:hover { transform: translateY(-1px); }
.btn-hero:active { transform: translateY(1px); box-shadow: 0 0 0 var(--accent-ink); }

/* ===== Section labels ===== */
.selection-section { margin-bottom: 28px; }
.section-label {
  font-weight: 800; font-size: 1.12rem; margin: 8px 0 6px;
  padding-bottom: 8px; border-bottom: 2px solid var(--rule-strong);
  display: flex; align-items: baseline; gap: 10px;
}
.section-label::before {
  content: "▸"; color: var(--accent); font-size: 0.9em;
}
.section-help { color: var(--ink-soft); font-size: 0.86rem; margin: 0 0 18px; }
.section-help strong { color: var(--ink); }

/* ===== Item grid as invoice line-items ===== */
.category-section {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  margin-bottom: 16px;
  overflow: hidden;
}
.category-title {
  margin: 0; padding: 9px 16px;
  font-size: 0.8rem; font-weight: 800; letter-spacing: 0.08em;
  color: var(--ink-soft);
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
  text-transform: none;
}
.chips-grid { display: block; }

/* one invoice line per item */
.item-card { border-bottom: 1px dashed var(--rule); }
.item-card:last-child { border-bottom: none; }
.item-card.selected { background: #f3f7ff; }

.item-label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; margin: 0;
}
.item-label input[type="checkbox"] {
  width: 19px; height: 19px; accent-color: var(--accent);
  cursor: pointer; flex: none;
}
.item-text { display: grid; gap: 1px; min-width: 0; }
.item-name { font-weight: 700; font-size: 0.98rem; }
.item-note { color: var(--ink-faint); font-size: 0.76rem; }
/* leader dots between name and amount */
.item-price-badge {
  justify-self: end; white-space: nowrap;
  color: var(--ink-soft); font-size: 0.82rem;
  position: relative; padding-left: 4px;
}
.item-card.selected .item-name { color: var(--accent-ink); }

/* edit row */
.edit-row {
  padding: 0 16px 14px 47px;
  background: #f3f7ff;
}
.edit-row.hidden { display: none; }
.edit-field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.edit-label { font-size: 0.82rem; color: var(--ink-soft); font-weight: 700; }
.edit-input {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  width: 130px; padding: 8px 10px; font-size: 1rem; text-align: right;
  border: 1px solid var(--rule); border-bottom: 2px solid var(--ink-soft);
  border-radius: var(--r); background: #fff; color: var(--ink);
}
.edit-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-bottom-color: var(--accent); }
.edit-input.invalid { border-color: var(--seal); border-bottom-color: var(--seal); background: #fdf3f2; }
.edit-unit { font-size: 0.85rem; color: var(--ink-soft); }
.edit-error { width: 100%; color: var(--seal); font-size: 0.78rem; font-weight: 700; }
.edit-error.hidden { display: none; }

/* ===== Sticky bar (invoice subtotal) ===== */
#sticky-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px clamp(16px, 5vw, 40px);
  border-top: 3px solid var(--accent);
  box-shadow: 0 -10px 30px -16px rgba(0,0,0,.5);
}
#sticky-bar.hidden { display: none; }
.sticky-info { display: flex; flex-direction: column; line-height: 1.3; }
.sticky-count { font-size: 0.74rem; color: #9fb1cc; letter-spacing: 0.04em; }
.sticky-total { font-size: 1.18rem; font-weight: 800; }
.btn-diagnose {
  background: var(--accent); color: #fff; border: 1px solid var(--accent-ink);
  font-weight: 800; font-size: 1rem; padding: 12px 22px;
  border-radius: var(--r); cursor: pointer; box-shadow: 0 2px 0 var(--accent-ink);
  transition: transform .08s ease, opacity .15s ease;
}
.btn-diagnose:hover:not(:disabled) { transform: translateY(-1px); }
.btn-diagnose:disabled { opacity: .4; cursor: not-allowed; }
body.sticky-active { padding-bottom: 84px; }

/* ===== Result ===== */
#result-section { margin: 8px 0 50px; }
#result-section.hidden { display: none; }

.result-card {
  background: var(--sheet); border: 1px solid var(--rule);
  border-top: 6px solid var(--accent);
  border-radius: var(--r); padding: 26px 24px; margin-bottom: 22px;
  position: relative;
  box-shadow: 0 18px 44px -30px rgba(22,35,59,.5);
}
.result-label { margin: 0; font-size: 0.8rem; color: var(--ink-soft); letter-spacing: 0.04em; }
.result-total-heading {
  margin: 2px 0 2px; font-size: 0.84rem; color: var(--ink-soft);
  display: flex; align-items: center; gap: 8px;
}
.result-total-heading::before { content: "合計"; font-weight: 800; color: var(--ink); }
.result-total-amount {
  font-size: clamp(2.6rem, 10vw, 4rem); font-weight: 800; line-height: 1.05;
  color: var(--ink); letter-spacing: -0.01em;
}
.result-type-box {
  margin-top: 18px; padding: 14px 16px; background: var(--paper);
  border: 1px solid var(--rule); border-left: 4px solid var(--seal);
  border-radius: var(--r);
}
.result-type-label { margin: 0; font-size: 0.74rem; color: var(--ink-soft); }
.result-type-name {
  margin: 2px 0 4px; font-size: 1.5rem; font-weight: 800; color: var(--seal);
  letter-spacing: 0.02em;
}
.result-type-body { margin: 0; font-size: 0.9rem; color: var(--ink-soft); }

/* section blocks within result */
.saving-section, .bought-section, .compound-section, .cta-section, .share-section {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r);
  padding: 22px 22px; margin-bottom: 18px;
}
.saving-section h3, .bought-section h3, .compound-section h3,
.cta-section h3, .share-section h3 {
  margin: 0 0 6px; font-size: 1.1rem; font-weight: 800;
  padding-bottom: 8px; border-bottom: 1px solid var(--rule);
}
.saving-help, .compound-lead { color: var(--ink-soft); font-size: 0.86rem; margin: 8px 0 14px; }
.compound-lead strong { color: var(--ink); }

/* ===== Rate selector (見直し率) ===== */
.rate-selector { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.rate-btn {
  flex: 1 1 0; min-width: 64px;
  font-family: var(--mono); font-weight: 700; font-size: 1rem;
  padding: 11px 8px; cursor: pointer;
  background: #fff; color: var(--ink-soft);
  border: 1px solid var(--rule); border-radius: var(--r);
  transition: all .12s ease;
}
.rate-btn:hover { border-color: var(--accent); color: var(--accent); }
.rate-btn.is-active {
  background: var(--accent); color: #fff; border-color: var(--accent-ink);
  box-shadow: 0 2px 0 var(--accent-ink);
}

/* ===== Signature: compression gauge (画面の主役) ===== */
.gauge {
  margin: 4px 0 22px;
  padding: 18px 18px 16px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--save);
  border-radius: var(--r);
  box-shadow: 0 14px 32px -26px rgba(22,35,59,0.45);
}
.gauge-caption {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.9rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 10px;
}
.gauge-caption .gauge-num { font-size: 1.15rem; font-weight: 800; color: var(--ink); }
.gauge-track {
  display: flex; height: 76px; width: 100%;
  border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden;
  background: repeating-linear-gradient(45deg, #fafbfd 0 8px, #f1f4f8 8px 16px);
}
.gauge-kept {
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: flex-start;
  padding-left: 14px; white-space: nowrap; overflow: hidden;
  transition: width .6s cubic-bezier(.22,.61,.36,1);
}
.gauge-kept #gauge-kept-label {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.05rem; font-weight: 800;
}
.gauge-cut {
  background: repeating-linear-gradient(45deg, var(--save) 0 9px, #0c6b53 9px 18px);
  color: #fff; display: flex; align-items: center; justify-content: flex-end;
  padding-right: 14px; font-weight: 700; white-space: nowrap; overflow: hidden;
  transition: width .6s cubic-bezier(.22,.61,.36,1);
}
.gauge-cut #gauge-cut-label {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.15rem; font-weight: 800;
}
.gauge-legend {
  display: flex; gap: 16px; margin-top: 10px; font-size: 0.76rem; color: var(--ink-soft);
  flex-wrap: wrap;
}
.gauge-legend .k::before, .gauge-legend .c::before {
  content: ""; display: inline-block; width: 11px; height: 11px;
  border-radius: 2px; margin-right: 5px; vertical-align: -1px;
}
.gauge-legend .k::before { background: var(--ink); }
.gauge-legend .c::before { background: var(--save); }

/* gauge hero line: 圧縮できた額を主役級に */
.gauge-hero {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px;
  margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--rule);
}
.gauge-hero .saving-amount-label { font-size: 0.92rem; color: var(--ink-soft); }
.gauge-hero .saving-amount-label strong { color: var(--accent); font-family: var(--mono); }
.gauge-hero .saving-amount {
  font-size: clamp(2.4rem, 11vw, 3.6rem); font-weight: 800; color: var(--save); line-height: 1;
}
.gauge-hero .saving-amount::before { content: "−"; margin-right: 2px; }
.gauge-hero .saving-amount-suffix { font-size: 0.9rem; color: var(--ink-soft); }

.saving-note { font-size: 0.76rem; color: var(--ink-faint); margin: 12px 0 0; }

/* ===== Bought (浮く目安額でできること) ===== */
.bought-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.bought-item {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r);
  padding: 12px 14px; display: grid; gap: 3px;
}
.bought-name { font-size: 0.82rem; color: var(--ink-soft); }
.bought-val { font-family: var(--mono); font-size: 1.3rem; font-weight: 800; color: var(--gold); }
.bought-empty { font-size: 0.9rem; color: var(--ink-soft); }
.bought-disclaimer { font-size: 0.74rem; color: var(--ink-faint); margin-top: 10px; }

/* ===== Compound (ledger table) ===== */
#compound-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.compound-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.compound-table th, .compound-table td {
  padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.compound-table thead th {
  font-size: 0.74rem; color: var(--ink-soft); font-weight: 800;
  border-bottom: 2px solid var(--rule-strong); background: var(--paper-2);
}
.compound-table th:first-child, .compound-table td:first-child {
  text-align: left; font-family: var(--sans); font-weight: 700;
}
.compound-table .td-muted { color: var(--ink-soft); }
.compound-table .td-fv { color: var(--save); font-weight: 800; }
.compound-table tbody tr:last-child td { border-bottom: none; }
.disclaimer { font-size: 0.76rem; color: var(--ink-faint); margin: 14px 0 0; line-height: 1.6; }
.disclaimer strong { color: var(--ink-soft); }

/* ===== CTA ===== */
.affiliate-note {
  font-size: 0.78rem; color: var(--ink-soft); background: var(--paper);
  border: 1px solid var(--rule); border-left: 4px solid var(--gold);
  border-radius: var(--r); padding: 12px 14px; margin: 8px 0 14px;
}
.btn-cta {
  background: #fff; color: var(--ink-soft); border: 1px dashed var(--ink-faint);
  font-weight: 700; padding: 12px 20px; border-radius: var(--r); cursor: not-allowed;
  font-size: 0.95rem;
}

/* ===== Share ===== */
#share-card-preview {
  display: none; width: 100%; max-width: 520px; height: auto;
  border: 1px solid var(--rule); border-radius: var(--r); margin: 4px 0 16px;
}
#share-panel { display: grid; gap: 9px; }
#share-panel.hidden { display: none; }
.share-btn {
  font-family: var(--sans); font-weight: 700; font-size: 0.95rem;
  padding: 12px 16px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--rule); background: #fff; color: var(--ink);
  transition: transform .08s ease, filter .12s ease;
}
.share-btn:hover { transform: translateY(-1px); }
.share-btn.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent-ink); box-shadow: 0 2px 0 var(--accent-ink); }
.share-btn.btn-secondary { background: var(--paper); }
.share-btn.btn-x { background: #14171a; color: #fff; border-color: #000; }
.share-btn.btn-line { background: #06c755; color: #fff; border-color: #05a648; }
.share-variant-chooser {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--rule);
}
.share-variant-label { width: 100%; margin: 0; font-size: 0.8rem; color: var(--ink-soft); font-weight: 700; }
.btn-variant {
  padding: 6px 14px; font-size: 0.85rem; border-radius: 999px;
  border: 1px solid var(--rule); background: #fff; color: var(--ink-soft); cursor: pointer;
}
.btn-variant.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.share-variant-preview {
  width: 100%; margin-top: 8px; padding: 10px 12px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r);
  font-size: 0.82rem; color: var(--ink-soft); white-space: pre-wrap;
}
.share-image-notice, .share-image-hint { font-size: 0.78rem; color: var(--ink-faint); margin: 4px 0 0; }

/* ===== Retry ===== */
.retry-wrap { text-align: center; margin-top: 20px; }
.btn-retry {
  background: none; border: 1px solid var(--ink-soft); color: var(--ink-soft);
  font-weight: 700; padding: 11px 26px; border-radius: var(--r); cursor: pointer;
}
.btn-retry:hover { border-color: var(--ink); color: var(--ink); }

/* ===== Footer ===== */
.site-footer { background: var(--ink); color: #c2cee0; margin-top: 40px; padding: 36px 0 26px; font-size: 0.84rem; }
.footer-inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 22px; }
.footer-block h4 { margin: 0 0 7px; color: #fff; font-size: 0.92rem; }
.footer-block p { margin: 0; color: #9fb1cc; line-height: 1.7; }
.footer-block a { color: #7fb0ff; }
.footer-bottom {
  margin-top: 24px; padding-top: 16px; border-top: 1px solid #2a3a55;
  display: flex; flex-direction: column; gap: 4px; color: #8295b2; font-size: 0.76rem;
}

/* ===== focus & motion ===== */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ===== responsive ===== */
@media (max-width: 560px) {
  .site-header .container { flex-direction: column; align-items: flex-start; gap: 2px; }
  .item-label { grid-template-columns: auto 1fr; }
  .item-price-badge { grid-column: 2; justify-self: end; }
  .edit-row { padding-left: 16px; }
  #sticky-bar { padding: 10px 16px; }
}
