/*
 * MEGURI — 上質・シンプル・日本的・RPG的・SaaS的
 * 藍(#1c2540)×金(#c9a227)×和紙(#f6f4ee)
 */

:root {
  --ink: #1c2540;
  --ink-deep: #131a30;
  --gold: #c9a227;
  --gold-soft: #e6d290;
  --washi: #f6f4ee;
  --paper: #ffffff;
  --text: #2b3044;
  --text-sub: #565c70;
  --line: #e3e0d6;
  /* リンクの文字色。地の色(--ink)と分けてあるのは、
     game_ui.css が「盤面の外は明るく / 盤面の中は濃く」で入れ替えるため */
  --link: #1c2540;
  --positive: #2c7a4b;
  --negative: #b0413e;
  --warning-bg: #fdf6e3;
  --danger-bg: #fbeeed;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--washi);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.65;
}

a { color: var(--link); }

/* ---- shell ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-deep) 100%);
  color: #d8dcea;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
/* ヘッダーの紋章(script/generate_brand_assets.py が作る meguri-mark.png)。
   画像そのものに藍の角丸の地が入っているので、ここでは大きさだけを決める */
.brand-mark {
  display: block; flex-shrink: 0;
  width: 38px; height: 38px; border-radius: 8px;
}
.brand-name { font-size: 20px; letter-spacing: 0.22em; font-weight: 700; color: #fff; }
.brand-large .brand-mark { width: 52px; height: 52px; font-size: 28px; }
.brand-large .brand-name { font-size: 28px; }

.org-badge {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(201,162,39,0.35);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.org-name { font-weight: 700; color: #fff; }
.org-level { color: var(--gold-soft); font-size: 12.5px; letter-spacing: 0.12em; }
.org-role { font-size: 11px; color: #9aa2ba; letter-spacing: 0.1em; }

.nav { flex: 1; overflow-y: auto; }
.nav-section {
  margin: 14px 6px 4px;
  font-size: 11px; letter-spacing: 0.18em; color: #7d859e;
}
.nav-link {
  display: block; padding: 7px 10px; border-radius: 7px;
  color: #cfd4e4; text-decoration: none; font-size: 13.5px;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 12px; }
.user-name { font-size: 13px; color: #aab1c6; margin-bottom: 6px; }
.logout-btn, .org-switch-btn {
  background: none; border: 1px solid rgba(255,255,255,0.25); color: #cfd4e4;
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; margin-bottom: 6px;
}
.logout-btn:hover, .org-switch-btn:hover { background: rgba(255,255,255,0.1); }

/* min-width: 0 が要る。flex の子は既定で「中身より小さくならない」ので、
   横に広い表（入出金予定など）があるとサイドバーの右へせり出し、ページごと横スクロールする。
   0 にすると .table-wrap（overflow-x: auto）の中だけで横に転がる */
.main { flex: 1; min-width: 0; padding: 26px 34px 60px; max-width: 1160px; }
/* ヘッダー右上のまとまり(全サービス共通: ？ → (🔔) → 🪙コイン → 本人ウィジェット)。KANADE の .topbar-right と同じ 1 行・高さ 38px・間隔 12px。
   MEGURI は和紙の地の上に置くので、KANADE の淡色の地(#f6f9f9)の代わりに白(--paper)、強調色は金(--gold) */
/* 下に余白を取る。ここを詰めると、ページの右上に出る操作ボタン（「＋ 予定を追加」など）が
   本人ウィジェットの真下に貼り付き、ヘッダーと重なって見える */
.main-topbar { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin: -8px 0 16px; }

/* 🪙コイン(KANADE のショップへ)。KANADE の .player-coins と同じ小さなピル */
.kh-coins {
  flex: none; display: inline-flex; align-items: center; white-space: nowrap; line-height: 1.5;
  border-radius: 999px; padding: 1px 8px;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  font-weight: 800; font-size: .74rem; color: #8a5a00; background: #fff7e0; border: 1px solid #f0d488; text-decoration: none;
}
a.kh-coins:hover { border-color: #eec54a; background: #fff1c7; }

/* 本人ウィジェット: 1 行のピル(アイコン・名前・Lv・EXP・在席)。KANADE の .player-chip / .kh-user と同じ形 */
.kh-user { position: relative; flex: 0 1 auto; min-width: 0; }
.kh-user > summary { list-style: none; }
.kh-user > summary::-webkit-details-marker { display: none; }
.kh-user > summary::marker { content: ""; }
.kh-user-button {
  display: flex; align-items: center; gap: 8px; min-width: 0; box-sizing: border-box; padding: 4px 14px 4px 6px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink);
  line-height: 1.5; cursor: pointer; user-select: none;
}
.kh-user-button:hover, .kh-user[open] > .kh-user-button { border-color: var(--gold); }
.kh-user-avatar {
  position: relative; flex: none; width: 28px; height: 28px; border-radius: 50%; box-sizing: border-box;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line);
  background: var(--ink); color: var(--gold-soft); display: inline-flex; align-items: center; justify-content: center;
}
.kh-user-avatar-img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: var(--washi); }
.kh-user-initial { font-weight: 700; font-size: .72rem; line-height: 1; }
/* アイコン右下の点はスマホ(在席の文言を隠したとき)だけ出す */
.kh-avatar-dot {
  display: none; position: absolute; right: -4px; bottom: -4px; width: 10px; height: 10px; box-sizing: border-box;
  border-radius: 50%; border: 2px solid #fff;
}
.kh-user-name { font-weight: 800; font-size: .8rem; color: var(--ink); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kh-user-level {
  flex: none; font-weight: 900; font-size: .78rem; color: #6b5410; background: linear-gradient(135deg, #fff3c2, #ffd95c);
  border: 1px solid #eec54a; border-radius: 999px; padding: 1px 10px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.kh-exp-track {
  flex: none; display: inline-block; width: 74px; height: 8px; box-sizing: content-box; border-radius: 999px;
  background: #e8eef0; border: 1px solid var(--line); overflow: hidden;
}
.kh-exp-fill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #a3e635, #7ed957); }
.kh-presence { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 800; color: var(--text-sub); white-space: nowrap; }
.kh-presence-dot { display: inline-block; flex: none; width: 9px; height: 9px; border-radius: 50%; }

.kh-user-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  width: 220px; max-width: calc(100vw - 16px); box-sizing: border-box; padding: 6px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 14px 32px rgba(19, 26, 48, 0.16);
  display: grid; gap: 2px;
}
.kh-user-menu-form { margin: 0; }
/* .kh-user-menu を前に付けて button[type="submit"] の共通スタイルより優先させる */
.kh-user-menu .kh-user-menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; box-sizing: border-box; padding: 9px 12px;
  border: 0; border-radius: 10px; background: none; color: var(--text); font: inherit; font-size: .86rem; font-weight: 700;
  letter-spacing: normal; text-align: left; text-decoration: none; cursor: pointer;
}
.kh-user-menu .kh-user-menu-item:hover, .kh-user-menu .kh-user-menu-item:focus-visible { background: var(--washi); color: var(--ink-deep); }
.kh-user-menu-section { display: grid; gap: 2px; padding: 4px 0; margin: 2px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.kh-user-menu-heading { padding: 4px 12px 2px; font-size: .7rem; font-weight: 800; color: var(--text-sub); }
.kh-user-menu .kh-presence-option { font-weight: 600; }
.kh-user-menu .kh-presence-option.is-current { font-weight: 800; }
.kh-presence-option-label { flex: 1; }
.kh-presence-check { flex: none; margin-left: auto; color: var(--gold); font-weight: 900; }

@media (max-width: 720px) {
  /* 狭い画面: 名前と在席の文言を隠し、在席はアイコン右下の点で出す(1 行のまま) */
  .main-topbar { gap: 8px; }
  .kh-user-button { gap: 6px; padding: 3px 8px 3px 4px; }
  .kh-user-name, .kh-presence-label, .kh-user-summary .kh-presence { display: none; }
  .kh-avatar-dot { display: inline-block; }
  .kh-user-level { font-size: .72rem; padding: 1px 8px; }
  .kh-coins { font-size: .7rem; padding: 1px 7px; }
  .kh-exp-track { width: 44px; flex: 0 1 44px; min-width: 28px; }
}

/* ---- ヘルプとサポート(KANAME)への「？」。右上のまとまりの先頭で 38px の丸ボタン ---- */
.header-help-link {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 38px; height: 38px; box-sizing: border-box; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper); color: var(--text-sub);
  font-size: 1.05rem; font-weight: 800; line-height: 1; text-decoration: none;
}
.header-help-link:hover { border-color: var(--gold); color: var(--ink-deep); }
.header-help-link-dark { border-color: rgba(255,255,255,0.25); background: none; color: #cfd4e4; }
.header-help-link-dark:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* ---- 管理者メニュー(会社の ADMIN 以上) ---- */
.admin-menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.admin-menu-item {
  display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--text);
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px;
  transition: transform .1s ease, border-color .12s ease, box-shadow .12s ease;
}
.admin-menu-item:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: 0 10px 22px rgba(19, 26, 48, .1); }
.admin-menu-icon { font-size: 1.4rem; flex: none; }
.admin-menu-main { flex: 1; display: grid; gap: 2px; min-width: 0; }
.admin-menu-title { color: var(--ink); letter-spacing: 0.04em; }
.admin-menu-desc { color: var(--text-sub); font-size: 12px; }
.admin-menu-arrow { flex: none; font-weight: 900; color: var(--gold); }

/* ---- auth ---- */
.auth-body { background: linear-gradient(160deg, var(--ink) 0%, var(--ink-deep) 70%); min-height: 100vh; margin: 0; }
.auth-shell { max-width: 420px; margin: 0 auto; padding: 60px 20px; }
.auth-topbar { position: absolute; top: 14px; right: 16px; }
.auth-hero { text-align: center; color: #fff; margin-bottom: 28px; }
.auth-hero .brand { justify-content: center; }
.auth-tagline { color: #aab1c6; letter-spacing: 0.08em; }
.auth-card { background: var(--paper); border-radius: 14px; padding: 28px; box-shadow: 0 18px 50px rgba(0,0,0,0.35); }
.auth-card h1 { margin-top: 0; font-size: 19px; }
.auth-switch { text-align: center; margin-top: 14px; color: #aab1c6; font-size: 13px; }
.auth-switch a { color: var(--gold-soft); }

/* ---- common ---- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 10px 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: 0.04em; }
.page-sub { color: var(--text-sub); font-size: 13px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
/* 盤面(カード)の外に見出しだけ置く画面(クエストなど)があるので、色は --text にする
   (--text は game_ui.css で「盤面の外は明るく / 盤面の中は濃く」入れ替わる。
    カードの中は .card h2 の濃い藍が勝つ) */
.card-title { font-size: 14px; font-weight: 700; margin: 0 0 10px; color: var(--text); letter-spacing: 0.06em; }

.grid { display: grid; gap: 14px; }
/* grid の子は既定で「中身より小さくならない」(min-width: auto)。数字の表のように横に広い
   中身があると 1fr の枠を押し広げ、.main（min-width: 0 で縮む）の外へせり出して、
   ページごと横スクロールする。0 にすると枠のぶんまで縮み、入りきらない中身は
   .table-wrap の中だけで横に転がる。タブレットの帯には同じ指定が入っていたが、
   PC の帯（1025px〜）には無く、1025〜1204px で将来シミュレーションがはみ出していた */
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* 数字の表を 2 つ並べる段（将来シミュレーションの「月別内訳」＋「シナリオ設定」など）。
   横に並べるのは、1 つぶんに 500px（表の桁が読める幅 + カードの内側の余白）が取れるときだけ。
   取れないときは 1 列に落とす。幅を決め打ちした @media ではなく auto-fit にしているのは、
   サイドバーの幅・本文の余白・表の桁数が変わっても勝手に折り返せるようにするため。
   min(100%, 500px) は、画面が 500px より狭いときに枠が画面を超えないようにするための保険。
   （本文の幅は最大 1092px なので、3 列目の空の枠ができることはない） */
.grid-2-tables { grid-template-columns: repeat(auto-fit, minmax(min(100%, 500px), 1fr)); }

.metric-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.metric-label { font-size: 12px; color: var(--text-sub); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.metric-value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric-value.small { font-size: 18px; }
.metric-note { font-size: 12px; color: var(--text-sub); }

.game-term {
  color: var(--gold); font-weight: 700; letter-spacing: 0.08em; font-size: 0.95em;
}
.formal-term { color: var(--text-sub); font-size: 0.9em; }

.amount-positive { color: var(--positive); font-weight: 700; }
.amount-negative { color: var(--negative); font-weight: 700; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { background: #efece3; font-size: 12px; letter-spacing: 0.06em; color: var(--ink); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: none; }
tr.row-planned td { color: #8a80a0; background: #faf8ff; font-style: italic; }
tr.row-carryover td { background: #f3f1e9; font-weight: 700; }
tr.row-total td { font-weight: 700; background: #f3f1e9; }
tr.row-overdue td { background: var(--danger-bg); }

/* 見出しと数字は折り返さない。「差異」が縦 1 文字ずつに潰れたり、
   桁が途中で折れて読めなくなるのを防ぐ。入りきらないときは .table-wrap が横に転がす
   （決算書の入力 .fs-input だけは科目名を折り返して画面に収める。下で戻す） */
table.data th { white-space: nowrap; }
table.data td.num, table.data th.num { white-space: nowrap; }
table.data.fs-input th { white-space: normal; }

/* ---- 表の中の操作列 ----
   1 行の中でボタンと入力欄が縦にばらけないよう、横一列にそろえる。
   いつも押すもの（消込・保存）と、たまに押すもの（編集・取消・削除）は
   縦線で分けて、何をする列なのかを見た目で分かるようにする */
table.data td.col-actions, table.data th.col-actions { white-space: nowrap; }
.row-actions {
  display: flex; align-items: center; justify-content: flex-start;
  gap: 8px; flex-wrap: nowrap;
}
.row-actions-main, .row-actions-sub { display: flex; align-items: center; gap: 6px; margin: 0; }
.row-actions-sub { padding-left: 8px; border-left: 1px solid var(--line); }
.row-actions form, .row-actions-form { display: inline-flex; margin: 0; }
/* 高さをそろえる（入力欄もボタンも 34px） */
.row-actions .btn,
.row-actions input[type="submit"],
.row-actions button[type="submit"],
.row-actions input[type="text"],
.row-actions input[type="date"] {
  min-height: 34px; display: inline-flex; align-items: center; margin: 0;
}
.row-actions input[type="text"], .row-actions input[type="date"] {
  padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; font-family: inherit; font-size: 13px;
}
.input-amount { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.input-date { width: 124px; }
.row-actions-none { color: var(--text-sub); }

/* 入出金予定の列幅。内容は狭くしすぎない（1 文字ずつ折り返さない）。
   日付・状態は折り返さない。口座だけは折り返してよい（「みらい銀行 普通」で 2 行）。
   操作の列が広いので、この表だけ左右の余白を詰めて PC 幅（1280px）に収める */
.table-schedules th, .table-schedules td { padding: 8px 8px; }
.table-schedules .col-desc { min-width: 170px; }
.table-schedules .col-desc-sub { display: block; font-size: 12px; color: var(--text-sub); white-space: nowrap; }
.table-schedules .col-desc .help-text { white-space: nowrap; }
.table-schedules .col-date,
.table-schedules .col-status { white-space: nowrap; }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12.5px; color: var(--text-sub); }
.field input, .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  background: #fff; font-family: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid rgba(201,162,39,0.4); border-color: var(--gold); }

.btn, input[type="submit"], button[type="submit"] {
  display: inline-block;
  background: var(--ink); color: #fff; border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 14px; cursor: pointer; text-decoration: none;
  font-family: inherit; letter-spacing: 0.04em;
}
.btn:hover, input[type="submit"]:hover { background: var(--ink-deep); }
.btn-gold { background: var(--gold); color: var(--ink-deep); font-weight: 700; }
.btn-gold:hover { background: #b8931f; }
.btn-ghost { background: none; border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { background: #efece3; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-danger { background: var(--negative); }

.inline-form { display: inline-block; }

/* ---- flash / alerts ---- */
.flash { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.flash-notice { background: #eaf3ec; border: 1px solid #bcd9c5; color: var(--positive); }
.flash-alert { background: var(--danger-bg); border: 1px solid #e6c2c0; color: var(--negative); }

.alert-banner { border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; font-size: 13.5px; }
.alert-danger { background: var(--danger-bg); border: 1px solid #e6c2c0; color: var(--negative); font-weight: 700; }
.alert-warning { background: var(--warning-bg); border: 1px solid #e8dcae; color: #8a6d1a; }

/* ---- quests ---- */
.quest-card {
  border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 10px; background: var(--paper); padding: 14px 16px; margin-bottom: 12px;
}
.quest-card.cleared { border-left-color: var(--positive); opacity: 0.85; }
.quest-header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.quest-title { font-weight: 700; font-size: 15px; }
.quest-tag { font-size: 11px; letter-spacing: 0.2em; color: var(--gold); font-weight: 700; }
.quest-desc { color: var(--text-sub); font-size: 13px; margin: 4px 0 8px; }
.quest-reward { font-size: 12.5px; color: var(--gold); font-weight: 700; }
.progress-track { height: 8px; background: #ece9df; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); }
.progress-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-sub); margin-top: 3px; }

/* ---- status ---- */
.stat-row { display: grid; grid-template-columns: 190px 1fr 90px; gap: 12px; align-items: center; margin-bottom: 12px; }
.stat-bar { height: 10px; background: #ece9df; border-radius: 5px; overflow: hidden; }
.stat-bar-fill { height: 100%; background: linear-gradient(90deg, var(--ink), #3d4d85); }
.stat-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.level-hero {
  background: linear-gradient(135deg, var(--ink) 0%, #2a3560 100%);
  color: #fff; border-radius: 14px; padding: 22px 26px; margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px;
}
.level-hero .level-num { font-size: 40px; font-weight: 700; color: var(--gold-soft); line-height: 1; }
.level-hero .level-caption { font-size: 12px; letter-spacing: 0.25em; color: #aab1c6; }
.level-powers { display: flex; gap: 22px; flex-wrap: wrap; }
.power { text-align: center; }
.power-value { font-size: 22px; font-weight: 700; color: #fff; }
.power-label { font-size: 11.5px; color: #aab1c6; }
.exp-track { height: 6px; background: rgba(255,255,255,0.18); border-radius: 3px; overflow: hidden; margin-top: 8px; width: 220px; }
.exp-fill { height: 100%; background: var(--gold); }

/* ---- achievements ---- */
.achievement-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.achievement {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--paper);
  display: flex; gap: 10px; align-items: flex-start;
}
.achievement.locked { opacity: 0.45; filter: grayscale(0.6); }
.achievement-icon { font-size: 22px; }
.achievement-name { font-weight: 700; font-size: 13.5px; }
.achievement-desc { font-size: 12px; color: var(--text-sub); }
.achievement-date { font-size: 11px; color: var(--gold); }

/* ---- charts ---- */
.line-chart { width: 100%; height: auto; }
.chart-line { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.chart-dot { fill: var(--gold); stroke: #fff; stroke-width: 1.5; }
.chart-dot-danger { fill: var(--negative); }
.chart-zero-line { stroke: var(--negative); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-line-base { stroke: var(--ink); }
.chart-line-good { stroke: var(--positive); }
.chart-line-bad { stroke: var(--negative); stroke-dasharray: 6 4; }
.legend { display: flex; gap: 18px; font-size: 12.5px; margin: 6px 0; }
.legend-swatch { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 5px; }
.legend-base .legend-swatch { background: var(--ink); }
.legend-good .legend-swatch { background: var(--positive); }
.legend-bad .legend-swatch { background: var(--negative); }
.chart-label { font-size: 10.5px; fill: var(--text-sub); }

/* ---- onboarding ---- */
.steps { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.step {
  padding: 6px 14px; border-radius: 999px; font-size: 12.5px;
  background: #ece9df; color: var(--text-sub);
}
.step.current { background: var(--ink); color: #fff; font-weight: 700; }
.step.done { background: var(--gold-soft); color: var(--ink-deep); }

.onboarding-list { margin: 10px 0; padding: 0; list-style: none; }
.onboarding-list li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; justify-content: space-between; }

/* ---- town ---- */
.town-strip { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; }
.town-item { text-align: center; }
.town-icon { font-size: 26px; display: block; }
.town-count { color: var(--text-sub); font-size: 12px; }
.town-mood { font-weight: 700; }

/* ---- misc ---- */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab { padding: 7px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); text-decoration: none; font-size: 13.5px; color: var(--text); }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* 札は短い言葉しか入らない。折り返すと「期日超 / 過」のように途中で割れて読めなくなるので
   折り返さない（入りきらないときは .table-wrap が横に転がす） */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-pending { background: var(--warning-bg); color: #8a6d1a; }
.badge-fulfilled { background: #eaf3ec; color: var(--positive); }
.badge-canceled { background: #eee; color: #888; }
.badge-draft { background: #eee; color: #666; }
.badge-issued { background: #e8effc; color: #2b5fb0; }
.badge-paid { background: #eaf3ec; color: var(--positive); }
.badge-overdue { background: var(--danger-bg); color: var(--negative); }

.empty-state { color: var(--text-sub); padding: 20px; text-align: center; }
.section-gap { margin-top: 26px; }
.mt-0 { margin-top: 0; }
.help-text { font-size: 12px; color: var(--text-sub); }

/* ---- 決算書・財務分析 ---- */
.fs-section {
  margin: 18px 0 6px; font-size: 13px; font-weight: 700; color: var(--text-sub);
  border-left: 3px solid var(--gold); padding-left: 8px;
}
.fs-input th { font-weight: 600; width: 60%; }
.fs-hint { display: block; font-size: 11.5px; color: var(--text-sub); font-weight: 400; }
.fs-term > summary { font-size: 11.5px; color: var(--text-sub); cursor: pointer; }
.fs-term > p { font-size: 12px; color: var(--text-sub); margin: 4px 0 0; }
.fs-amount { width: 100%; text-align: right; }
.fs-rev-warn td { background: var(--danger-bg); }

.metric-row { border-top: 1px solid var(--line); padding: 12px 0; }
.metric-row:first-of-type { border-top: 0; }
.metric-row-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.metric-row-name { font-weight: 700; flex: 1 1 200px; }
.metric-row-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-row-judge {
  font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap;
}
.judge-good  { color: var(--positive); }
.judge-bad   { color: var(--negative); }
.judge-normal, .judge-unknown { color: var(--text-sub); }
.metric-row-judge.judge-good   { background: #e8f3ec; }
.metric-row-judge.judge-bad    { background: var(--danger-bg); }
.metric-row-judge.judge-normal { background: #eeece6; }
.metric-row-judge.judge-unknown{ background: #f1f0eb; }
.metric-row-comment { margin: 6px 0; }
.metric-row-bench {
  display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-sub);
  background: var(--washi); border-radius: 6px; padding: 6px 10px;
}
.metric-row-vs { color: var(--text); }
.metric-row-term > summary { font-size: 12px; color: var(--text-sub); cursor: pointer; margin-top: 6px; }
.metric-row-term-body {
  font-size: 13px; background: var(--washi); border-radius: 6px; padding: 10px 12px; margin-top: 6px;
}
.metric-row-term-body p { margin: 0 0 8px; }

/* ---- 用語のひとこと説明 ----
   カーソル（スマホはタップ、キーボードはフォーカス）で一言だけ出す。
   詳しい解説は吹き出しの中の「用語の解説を読む」の先に置く。
   吹き出しは position: fixed。表の横スクロールやカードの overflow に切られないようにするため。
   出る位置（画面の端で反対側に寄せる・下が足りなければ上に出す）は shared/_term_hint_script が決める */
.term-hint { display: inline; }
.term-hint-trigger {
  display: inline; margin: 0; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; letter-spacing: inherit; text-align: left; cursor: help;
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.term-hint-trigger:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.term-hint-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 4px; vertical-align: 1px;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--washi); color: var(--text-sub);
  font-size: 10px; font-weight: 700; line-height: 1;
}
.term-hint-bubble {
  position: fixed; z-index: 80; width: max-content;
  max-width: min(280px, calc(100vw - 24px));
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--text);
  box-shadow: 0 10px 26px rgba(19, 26, 48, 0.18);
  font-size: 12.5px; font-weight: 400; font-style: normal; line-height: 1.6;
  text-align: left; white-space: normal;
}
.term-hint-bubble[hidden] { display: none; }
.term-hint-more { display: block; margin-top: 6px; font-size: 12px; font-weight: 700; }

.glossary-short { font-weight: 700; }
.glossary-entry { border-top: 1px solid var(--line); padding: 12px 0; }
.glossary-entry h4 { margin: 0 0 4px; font-size: 15px; }
.glossary-entry p { margin: 0 0 6px; }
.glossary-formula { font-size: 12.5px; color: var(--text-sub); }

@media (max-width: 720px) {
  .metric-row-head { gap: 6px; }
  .metric-row-value { font-size: 17px; }
  .metric-row-bench { gap: 6px; flex-direction: column; }
  .fs-input th { width: 55%; }
}

/* ---- 予算・予実 ----
   表が横に長くなりがちなので、数字が読めることを最優先にする:
   - 科目（いちばん左の列）は横に転がしても貼り付けたままにする。
     どの行を見ているか分からなくなると、数字が読めても意味が分からないため。
   - 月ごとの表は「1か月ぶんだけ」出し、月は上のタブで切り替える。
     12か月 ×（予算・実績・差異）を1枚に並べると 320px はおろか 1280px でも読めない。
   - 良いずれ・悪いずれは色に加えて記号（+ / − / !）でも出す（色だけに頼らない） */

/* 税込・税抜の断り書き。実績は請求書・入出金の税込金額から作っているので、
   予算を税抜で立てると消費税のぶんだけ毎月ずれ続ける。
   注意ではなく前提の説明なので、警告の黄色ではなく地の和紙色で落ち着かせる */
.tax-basis-note { background: var(--washi); border: 1px solid var(--line); }
.tax-basis-note-sub {
  display: block; margin-top: 4px; font-size: 12px; font-weight: 400; color: var(--text-sub);
}

.budget-fy-nav {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px;
}
.budget-fy-current { font-weight: 700; letter-spacing: 0.06em; }
.budget-fy-export { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.budget-prefill { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.budget-prefill .inline-form { display: inline-flex; margin: 0; }

.budget-annual {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 4px 16px; margin-bottom: 12px;
}
.budget-annual .field input { text-align: right; font-variant-numeric: tabular-nums; }

/* 月の切り替えタブ。12個あるので狭い画面では横に転がす（縦に12行積まない） */
.budget-month-tabs {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px;
}
.budget-month-tab {
  flex: none; padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--text); text-decoration: none;
  font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.budget-month-tab.is-current { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 700; }
.budget-month-tab.is-future { color: var(--text-sub); border-style: dashed; }
.budget-month-tab.is-future.is-current { color: #fff; }

/* 数字の色。白・薄い背景のどちらでも本文のコントラスト比 4.5:1 を満たす色を使う */
.budget-good { color: var(--positive); font-weight: 700; }
.budget-bad { color: var(--negative); font-weight: 700; }
.budget-even { color: var(--text); }
.budget-blank { color: var(--text-sub); }

.budget-notable-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 5px; vertical-align: 1px;
  border-radius: 50%; background: var(--negative); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
}

.budget-notable { list-style: none; margin: 0; padding: 0; }
.budget-notable li {
  border-left: 4px solid var(--negative); background: var(--danger-bg);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 8px;
}
.budget-notable li.is-good { border-left-color: var(--positive); background: #eaf3ec; }
.budget-notable-label { display: block; font-weight: 700; }
.budget-notable-body { display: block; font-size: 12.5px; }

/* 貼り付ける列（科目・月）。border-collapse では罫線が消えるので影で代用する */
table.data.budget-variance, table.data.budget-input { overflow: visible; }
table.data.budget-variance th.col-account,
table.data.budget-input th.col-account {
  position: sticky; left: 0; z-index: 2;
  background: #efece3; box-shadow: 1px 0 0 var(--line);
  white-space: normal; text-align: left; font-weight: 600;
}
table.data.budget-variance th.col-account { min-width: 130px; }
table.data.budget-input th.col-account { min-width: 150px; }
table.data.budget-variance tr.row-total th.col-account { background: #f3f1e9; font-weight: 700; }
table.data.budget-variance tr.is-notable td { background: #fdf6e3; }
table.data.budget-variance tr.is-notable th.col-account { background: #f7ecd2; }
table.data.budget-variance tr.is-selected td { background: #f1f4fb; }
table.data.budget-variance tr.is-selected th.col-account { background: #e7ecf8; }

table.data.budget-input tr.budget-group-row th {
  background: var(--ink); color: #fff; font-weight: 700; letter-spacing: 0.06em;
  position: static; box-shadow: none;
}
.budget-amount { width: 104px; text-align: right; font-variant-numeric: tabular-nums; }
table.data.budget-input td { padding: 6px 6px; }
table.data.budget-input input[type="text"] {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; font-family: inherit; font-size: 13px;
}

@media (max-width: 720px) {
  /* 狭い画面: 科目の列を詰め、言い換えの一言は隠す（用語はタップで出る）。
     数字そのものは縮めない（読めなくなるため。入りきらない分は横に転がす） */
  .budget-fy-export { margin-left: 0; }
  table.data.budget-variance th.col-account { min-width: 104px; font-size: 12.5px; }
  table.data.budget-input th.col-account { min-width: 112px; font-size: 12.5px; }
  table.data.budget-input th.col-account .fs-hint { display: none; }
  .budget-amount { width: 92px; }
  table.data.budget-variance th, table.data.budget-variance td { padding: 8px 8px; }
}

/* 絵文字から置き換えたアイコン画像。入れ物の font-size に合わせて文字と同じ大きさにする
   (width / height 属性の px は、読み込み前の場所取り用) */
.ui-icon {
  width: 1em;
  height: 1em;
  object-fit: contain;
  vertical-align: -0.15em;
  flex: none;
}
/* flex の入れ物(見出しの中など)では vertical-align が効かないので中央に置く */
h1 .ui-icon,
h2 .ui-icon,
h3 .ui-icon,
h4 .ui-icon,
button .ui-icon,
a .ui-icon,
label .ui-icon {
  vertical-align: middle;
}

/* ===== スマホ・タブレットで入力欄が勝手に拡大されるのを止める =====
   iOS Safari は、文字が 16px 未満の入力欄をタップするとページ全体を拡大する。
   そのあと絞り込みなどで画面が変わると倍率が戻るため、「拡大 → 縮小」が
   くり返されて文字が打てない、という不具合になっていた。
   確実に止める方法は「16px 以上にする」ことだけ(viewport の user-scalable=no は
   拡大そのものを禁じてしまい、見えにくい人が困るので使わない)。
   1024px 以下だけに効かせるので、PC(1025px〜)の見た目は変わらない。
   :not(#_) は詳細度を id 相当まで上げるための書き方(#_ という id はどこにも無い)。
   これが無いと .field input { font-size: 14px } のようなクラス指定に負ける。
   ボタン・チェックボックス・ラジオ・ファイル選択は拡大の対象外なので触らない。 */
@media (max-width: 1024px) {
  input:not(#_):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
  select:not(#_),
  textarea:not(#_) {
    font-size: 16px;
  }
}
