/* 現金出納帳システム */
:root {
  --bg: #f6f5f1; --paper: #ffffff; --ink: #1f2328; --sub: #6a6f76; --line: #e3e1da; --line2: #efede7;
  --accent: #1f5f8b; --accent-ink: #fff; --in: #1d6b3a; --out: #9b2c2c;
  --warn-bg: #fff6d6; --warn: #8a5a00; --warn-line: #f0d27a; --danger: #b42318;
  --ok-bg: #e8f5ec; --err-bg: #fdecea; --info-bg: #e8f1f8;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif; }
a { color: var(--accent); }
h1, h2 { line-height: 1.3; }
h1 small, h2 small { font-size: .6em; color: var(--sub); font-weight: normal; margin-left: .5em; }
h2 { font-size: 18px; margin: 28px 0 10px; }

/* ヘッダー */
header.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  background: #1c2b36; color: #fff; padding: 0 18px; height: 52px; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand small { display: block; font-size: 12px; font-weight: normal; opacity: .7; margin-top: -3px; }
nav.main { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
nav.main a { color: #cfd8df; text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
nav.main a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.main a.on { background: rgba(255,255,255,.15); color: #fff; }
.badge { display: inline-block; background: #f0b429; color: #3b2a00; border-radius: 10px; font-size: 13px;
  font-weight: 700; padding: 0 7px; margin-left: 5px; }
.me { display: flex; gap: 6px; }
details.menu { position: relative; }
details.menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 6px; color: #cfd8df; white-space: nowrap; }
details.menu summary::-webkit-details-marker { display: none; }
details.menu summary::after { content: " ▾"; font-size: 12px; }
details.menu[open] summary { background: rgba(255,255,255,.15); color: #fff; }
details.menu > div { position: absolute; right: 0; top: 38px; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 200px; padding: 6px; }
details.menu > div a, details.menu > div .linklike { display: block; padding: 8px 10px; color: var(--ink); text-decoration: none;
  border-radius: 6px; width: 100%; text-align: left; }
details.menu > div a:hover, details.menu > div .linklike:hover { background: var(--bg); }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; }

main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }
main.narrow { max-width: 640px; }
h1.page { font-size: 24px; margin: 4px 0 12px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint { color: var(--sub); font-size: 14.5px; margin: 6px 0 12px; }
.sum { margin: 4px 0 10px; }

/* メッセージ */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); border-color: #bfe3cb; }
.flash.error { background: var(--err-bg); border-color: #f5c2bd; }
.flash.info { background: var(--info-bg); border-color: #c4dbee; }

/* ボタン */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 6px; font: inherit;
  text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9c6bc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { height: 30px; font-size: 15px; }
.btn.warn { background: #f0b429; border-color: #e0a210; color: #3b2a00; font-weight: 600; }
.btn.wide { width: 100%; height: 42px; }

/* 絞り込み */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; font-size: 14px; color: var(--sub); gap: 2px; }
.filters label.grow { flex: 1; min-width: 180px; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 15px; height: 36px; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #d4d1c8; border-radius: 6px;
  padding: 0 10px; height: 36px; min-width: 0; }
textarea { height: auto; padding: 8px 10px; width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,95,139,.25); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { height: auto; }

/* 表 */
.scroll { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; background: var(--paper); font-size: 15px; }
.scroll table.grid { border: 0; }
table.grid th { background: #f1efe9; color: #4a4f55; font-weight: 600; text-align: left; padding: 7px 8px;
  border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.grid th.unit { font-weight: normal; font-size: 13px; color: var(--sub); }
table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line2); vertical-align: top; }
table.grid tbody tr:hover td { background: #fbfaf7; }
.r { text-align: right; font-variant-numeric: tabular-nums; }
td.in { color: var(--in); } td.out { color: var(--out); } td.bal { font-weight: 600; }
.nowrap { white-space: nowrap; }
tr.carry td { background: #f7f6f2; font-weight: 600; color: #4a4f55; }
tr.pre td { color: #8a8f96; }
tr.needs-check td { background: var(--warn-bg) !important; }
tr.needs-check td:first-child { box-shadow: inset 3px 0 0 #f0b429; }
tr.inactive td { color: #9a9ea4; }
td.empty, .empty:not(button) { text-align: center; color: var(--sub); padding: 24px !important; }
.memo { font-size: 13.5px; color: var(--sub); }
.cno { display: inline-block; min-width: 22px; font-size: 13px; color: var(--sub); margin-right: 4px; }
.tag { font-size: 12.5px; background: #e8eef3; color: #34536b; border-radius: 4px; padding: 0 5px; margin-left: 5px; }
.ck { display: inline-block; font-size: 13px; font-weight: 700; background: #f0b429; color: #3b2a00; border-radius: 4px;
  padding: 0 6px; margin-right: 6px; cursor: help; }
.ck::before { content: "【"; } .ck::after { content: "】"; }
td.note { color: var(--warn); }

/* 行の操作 */
.acts { display: flex; gap: 4px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.acts form { margin: 0; }
.icon { display: inline-block; font: inherit; font-size: 14px; padding: 3px 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); border-radius: 5px; text-decoration: none; cursor: pointer; line-height: 1.4; }
.icon:hover { border-color: #b9b5aa; }
.icon.danger { color: var(--danger); }
.icon.flagged { background: #f0b429; border-color: #e0a210; color: #3b2a00; }
.icon.pending { background: #fdecea; border-color: #f5c2bd; color: var(--danger); font-weight: 600; }   /* 削除の申請中 */
details.pop { position: relative; }
details.pop summary { list-style: none; }
details.pop summary::-webkit-details-marker { display: none; }
.pop-body { position: absolute; right: 0; top: 28px; z-index: 10; width: 280px; background: #fff; border: 1px solid var(--warn-line);
  border-radius: var(--radius); box-shadow: 0 10px 24px rgba(0,0,0,.14); padding: 10px; white-space: normal; text-align: left; }
.pop-body form { display: flex; flex-direction: column; gap: 8px; }
.note-show { margin: 0 0 8px; font-size: 14.5px; }

/* カード・フォーム */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }
.card h1 { font-size: 21px; margin: 0 0 14px; }
.card h2 { margin-top: 0; }
.card.login { margin-top: 10vh; }
.card.login h1 small { display: block; margin: 4px 0 0; }
.form, .card > form { display: flex; flex-direction: column; gap: 12px; }
.form label, .card > form > label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: #3f444a; font-weight: 600; }
.form label .sub { font-weight: normal; color: var(--sub); font-size: 13.5px; }
.form input, .form select { width: 100%; font-weight: normal; }
.form input.big { height: 44px; font-size: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.form input.money { text-align: right; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: inline-flex; border: 1px solid #d4d1c8; border-radius: 6px; overflow: hidden; height: 36px; }
.seg label { flex-direction: row !important; margin: 0; }
.seg input { position: absolute; opacity: 0; width: 0; }
.seg span { display: flex; align-items: center; padding: 0 16px; cursor: pointer; font-weight: normal; }
.seg input:checked + span { background: var(--accent); color: #fff; font-weight: 600; }
.inline { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
label.check { flex-direction: row !important; align-items: center; gap: 6px; font-weight: normal !important; }
.linkbox { background: var(--info-bg); border: 1px solid #c4dbee; border-radius: var(--radius); padding: 10px 12px; }
.linkbox p { margin: 0 0 6px; font-size: 15px; }
.rate { color: var(--accent); font-weight: 600; margin: 0; }
fieldset.bill { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 12px; }
fieldset.bill legend { font-size: 14.5px; color: var(--sub); padding: 0 6px; }
.actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.actions .btn.primary { min-width: 140px; }
.meta { font-size: 13.5px; color: var(--sub); margin: -6px 0 0; }

/* ホーム */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; text-decoration: none; color: var(--ink);
  display: flex; flex-direction: column; gap: 2px; }
.tile:hover { border-color: #c9c6bc; }
.tile span { font-size: 14.5px; color: var(--sub); }
.tile b { font-size: 26px; font-variant-numeric: tabular-nums; }
.tile b small { font-size: 14px; font-weight: normal; margin-left: 3px; color: var(--sub); }
.tile em { font-style: normal; font-size: 14px; color: var(--sub); }
.tile.alert { background: var(--warn-bg); border-color: var(--warn-line); }
.tile.alert.zero { background: var(--paper); border-color: var(--line); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }

/* 管理 */
.inline-form { display: flex !important; flex-direction: row !important; flex-wrap: wrap; align-items: flex-end; gap: 10px !important; }
.inline-form label { display: flex; flex-direction: column; font-size: 14px; color: var(--sub); gap: 2px; }
.inline-form label.grow { flex: 1; min-width: 200px; }
.inline-form label.check { color: var(--ink); height: 36px; }
.inline-edit { display: flex; gap: 6px; margin: 0; }
.inline-edit input { flex: 1; height: 30px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--ink); background: var(--paper); border: 1px solid var(--line); }
.tabs a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pwbox { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.pwbox code { font-size: 20px; background: #fff; padding: 2px 8px; border-radius: 4px; border: 1px solid var(--warn-line); }

@media (max-width: 760px) {
  header.top { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  nav.main { order: 3; flex-basis: 100%; }
  main { padding: 14px 12px 40px; }
  .two { grid-template-columns: 1fr; }
  .pop-body { width: 240px; }
}
@media print {
  header.top, .filters, .acts, .btn, .hint { display: none !important; }
  body { background: #fff; } .scroll { border: 0; }
}

/* 調整 */
table.grid th.r { text-align: right; }
.form input[type=checkbox], .form input[type=radio] { width: auto; }
.form label.check { white-space: nowrap; }
.line-top { display: flex; justify-content: space-between; align-items: center; margin-top: -6px; }
input.auto { background: #f4f3ee; color: #6a6f76; }
.code-in { flex: 0 0 80px !important; width: 80px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
tr.sub td { border-top: 0; }
[hidden] { display: none !important; }

/* 表の縦線 */
table.grid th, table.grid td { border-right: 1px solid var(--line); }
table.grid th:last-child, table.grid td:last-child { border-right: 0; }
table.grid thead tr + tr th { border-top: 1px solid var(--line); }
/* 権限 */
.perms { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.perms label { display: flex; flex-direction: row; align-items: center; gap: 5px; white-space: nowrap; font-size: 16px; }
.perms label.all { font-weight: 700; }
.perm-row td { vertical-align: middle; }
td.acts { white-space: nowrap; }
td.acts form, td.acts button { display: inline-block; margin: 0 2px 0 0; }
.unpaid { display: inline-block; font-size: 13px; font-weight: 700; color: #9b2c2c; background: #fdecea; border-radius: 4px; padding: 0 6px; }
td.w11 { min-width: 11em; } td.w12 { min-width: 12em; } td.w7 { min-width: 7em; }

/* 一覧から月を直接入力 */
td.mc { white-space: nowrap; }
td.mc .mc-in { height: 30px; padding: 0 6px; font-size: 14px; width: 130px; }
td.mc .mc-x { font-size: 13px; margin-left: 4px; color: #6a6f76; cursor: pointer; }
td.mc .mc-ok { display: block; font-size: 12px; color: #6a6f76; min-height: 1em; }
td.mc .mc-ok.done { color: #1d6b3a; } td.mc .mc-ok.bad { color: #b42318; }
.st { display: inline-block; font-size: 13px; font-weight: 700; border-radius: 4px; padding: 0 6px; white-space: nowrap; }
.st.none { background: #fdecea; color: #9b2c2c; } .st.short { background: #fff6d6; color: #8a5a00; }
.st.over { background: #fdecea; color: #9b2c2c; } .st.done { background: #e8f5ec; color: #1d6b3a; } .st.fee { background: #e8f1f8; color: #1f5f8b; }
.rlist { font-size: 13px; } .rlist div { white-space: nowrap; }
.receipt { border-bottom: 1px dashed var(--line); padding-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.receipt-top { display: flex; justify-content: space-between; align-items: center; }
td .acts + .acts { margin-top: 4px; }
td.actcol { min-width: 250px; }
td.actcol .acts { justify-content: flex-end; flex-wrap: wrap; }
.report-list { margin: 0; padding-left: 1.2em; line-height: 1.8; }
/* 見出しは枠の中央 */
table.grid th, table.grid th.r { text-align: center; vertical-align: middle; }
label.muted { opacity: .55; }
input.no-in { max-width: 160px; }
.field .sub { font-weight: normal; color: var(--sub); font-size: 13.5px; }

/* 科目の下の補助科目 */
.subacc { font-size: 13.5px; color: var(--sub); line-height: 1.3; }
.subacc::before { content: "└ "; color: #b5b2a8; }
/* 請求の選択（必要な時だけ出す） */
.bill-q .bill-off { margin: 4px 0 0; }
[hidden] { display: none !important; }
/* 一覧の月・日付ボタン */
button.pick { font: inherit; font-size: 14px; line-height: 1.2; min-width: 120px; height: 32px; padding: 0 8px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
button.pick::after { content: "▾"; color: var(--sub); }
.bill-on .sub { display: block; margin-top: 4px; }
button.pick.empty { color: var(--sub); padding: 0 8px !important; text-align: left; }
td[data-kind="paid"] button.pick.empty { color: var(--out); font-weight: 600; }
button.pick:disabled { opacity: .5; cursor: default; }
/* 月・日付を選ぶ小さな画面 */
.picker { position: absolute; z-index: 50; background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 10px; width: 264px; font-size: 15px; }
.picker button { font: inherit; border: 1px solid transparent; background: none; border-radius: 6px; cursor: pointer; color: var(--ink); }
.picker button:hover { background: var(--line2); }
.picker button.on { background: var(--accent); color: #fff; font-weight: 600; }
.pk-head { display: flex; align-items: center; gap: 2px; margin-bottom: 8px; }
.pk-head b { flex: 1; text-align: center; }
.pk-head button { padding: 2px 8px; color: var(--sub); }
.pk-months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.pk-months button { padding: 8px 0; }
.pk-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.pk-days .dw { font-size: 12.5px; color: var(--sub); padding: 2px 0; }
.pk-days .dw:first-child { color: var(--out); }
.pk-days button { padding: 5px 0; }
.pk-foot { display: flex; justify-content: space-between; margin-top: 8px; border-top: 1px solid var(--line2); padding-top: 6px; }
.pk-foot button { color: var(--accent); padding: 3px 8px; }

/* 請求書PDF */
ul.files { list-style: none; padding: 0; margin: 4px 0 6px; font-weight: normal; }
ul.files li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line2); }
ul.files .rm { margin-left: auto; color: var(--danger); font-size: 14px; }
label.drop { display: block; border: 2px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; cursor: pointer;
  font-weight: normal; color: var(--sub); background: #fbfaf7; }
label.drop { position: relative; }
/* ブラウザの「Choose Files」（英語）を見せず、上に透明で重ねる（押す・ドラッグはそのまま使える） */
label.drop input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
label.drop .btn { display: inline-block; margin-bottom: 6px; pointer-events: none; }
label.drop span#droptext { display: block; }
label.drop.over { border-color: var(--accent); background: var(--info-bg); }
label.drop.has { border-color: var(--in); color: var(--in); }
td.pdfs .icon { margin-right: 4px; }

.warn-s { font-size: 12.5px; color: var(--out); font-weight: 600; white-space: nowrap; }

/* 試用版の帯（環境変数 KEIRI_DEMO=1 の時だけ。base.html） */
.demo-band { background: #fff3cd; color: #6b4e00; border-bottom: 1px solid #f0d78c; padding: 8px 16px; text-align: center; font-weight: 700; }

/* 一覧の表（sheet）：Excel のように見出しの行を固定する。表の中で縦・横にスクロール（横のスクロールバーがいつも見える） */
main:not(.narrow) { max-width: none; }
.scroll.sheet { overflow: auto; max-height: calc(100vh - var(--top-h, 52px) - 16px); }
/* 文字の欄が細く折り返しすぎないように（横に広げて、はみ出す分は表の中で横スクロール） */
.scroll.sheet table.grid td:not(.r):not(.nowrap):not(.memo) { min-width: 7.5em; }
.scroll.sheet table.grid thead th { position: sticky; top: 0; z-index: 3; box-shadow: inset 0 -1px 0 var(--line); }
/* 上へ・下へのボタン（画面の右下） */
.jump { position: fixed; right: 18px; bottom: 18px; z-index: 30; display: flex; flex-direction: column; gap: 8px; }
.jump button { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--accent);
  box-shadow: 0 4px 14px rgba(0,0,0,.16); font: 700 18px/1 system-ui, sans-serif; cursor: pointer; }
.jump button:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.jump button span { display: block; font-size: 11px; font-weight: 600; margin-top: 2px; }
@media print { .jump { display: none !important; } .scroll.sheet { max-height: none; overflow: visible; } }
.pager { display: flex; align-items: center; gap: 12px; margin: 12px 0; }   /* 変更履歴のページ送り */
