:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --line: #d9dbde;
  --accent: #1f5fa8;
  --accent-text: #ffffff;
  --danger: #b42318;
  --notice: #eef4fb;
  --inactive: #8a9099;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1e2125;
    --text: #e6e8eb;
    --muted: #a0a6ae;
    --line: #353a40;
    --accent: #6ea8e8;
    --accent-text: #0e1217;
    --danger: #f2877c;
    --notice: #1d2a38;
    --inactive: #737a83;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
a { color: var(--accent); }
header.site {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
header.site .brand { font-weight: 700; color: var(--text); text-decoration: none; }
header.site nav { display: flex; gap: 16px; flex: 1; }
header.site nav a { text-decoration: none; color: var(--muted); }
header.site nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
header.site .me { display: flex; align-items: center; gap: 12px; color: var(--muted); }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 32px 0 12px; }
.flash { background: var(--notice); border: 1px solid var(--line); padding: 8px 12px; border-radius: 4px; }
.error { color: var(--danger); }
.note { color: var(--muted); font-size: 0.9em; }
button, .button {
  display: inline-block; padding: 6px 14px; border-radius: 4px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text); font: inherit; cursor: pointer; text-decoration: none;
}
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
input, select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--text); }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 2px 6px 2px 0; }
form.stack { display: grid; gap: 12px; max-width: 420px; }
form.stack label { display: grid; gap: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 4px; }
label.check { display: inline-flex !important; gap: 4px; margin-right: 12px; }
.login { max-width: 420px; margin: 48px auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 24px; }
.login form.dev { display: grid; gap: 10px; margin-top: 24px; padding-top: 16px; border-top: 1px dashed var(--line); }
.login form.dev label { display: grid; gap: 4px; }
.table-wrap { overflow-x: auto; }
table.list { border-collapse: collapse; width: 100%; background: var(--surface); }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
table.list th { font-weight: 600; color: var(--muted); white-space: nowrap; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.inactive td { color: var(--inactive); }
.tag { display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 0 8px; }
@media (max-width: 640px) {
  table.list { display: block; overflow-x: auto; }
}
/* 帳簿 */
nav.tabs { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 12px; }
nav.tabs .year { font-weight: 700; margin-right: 8px; }
nav.tabs a { text-decoration: none; color: var(--muted); }
nav.tabs a[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom: 2px solid var(--accent); }
.filter { display: grid; gap: 8px; margin-bottom: 12px; }
.filter .months { display: flex; flex-wrap: wrap; gap: 4px; }
.filter .months a { padding: 2px 8px; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; background: var(--surface); }
.filter .months a[aria-current="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.filter form.inline { flex-wrap: wrap; }
table.report tr.group th { background: var(--bg); color: var(--text); padding-top: 12px; }
table.report tr.subtotal td { font-weight: 600; background: var(--notice); }
table.report tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
table.report tr.reversed td, table.report tbody.reversed td { color: var(--inactive); }
table.report tbody.draft td { background: var(--notice); }
table.journal-book tbody { border-bottom: 2px solid var(--line); }
td.nowrap { white-space: nowrap; }
.badge { display: inline-block; font-size: 0.8em; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; margin-left: 4px; color: var(--muted); }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 12px 16px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }
/* 仕訳の入力（1-5） */
button.secondary, .button.secondary { background: var(--surface); color: var(--accent); }
button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.actions form.inline { margin: 0; }
.journal-form .fields { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; }
.journal-form .fields label { display: grid; gap: 4px; }
.journal-form .fields label.wide { flex: 1; min-width: 240px; }
table.entry td { padding: 4px; }
table.entry select, table.entry input { width: 100%; min-width: 7em; }
table.entry input.amount { text-align: right; font-variant-numeric: tabular-nums; min-width: 8em; }
table.entry select[multiple] { min-width: 10em; }
table.entry td:first-child select { min-width: 5em; }
table.entry td:nth-child(2) select { min-width: 14em; }
main:has(form.journal-form) { max-width: 1600px; }
td.dept { min-width: 8em; }
td.tags { min-width: 12em; }
td.tags .tag { margin: 0 4px 4px 0; white-space: nowrap; }
td.tags form.inline { margin: 0; flex-wrap: nowrap; }
td.tags select { max-width: 12em; }
button.secondary.small, td.tags button.secondary { padding: 3px 8px; }
.flash.error ul { margin: 4px 0 0; }
/* マスター（1-4） */
.fixed { display: inline-block; padding: 5px 0; color: var(--muted); }
table.settings td { padding: 4px; }
table.settings input[type="text"] { width: 100%; min-width: 8em; }
table.settings input.short { min-width: 4em; width: 5em; }
/* 月次の状況（1-6） */
.filter .months a.locked::before { content: "🔒"; font-size: 0.8em; margin-right: 2px; }
.filter .months a.reviewed::after { content: " ✓"; color: var(--accent); }
.filter .months a.changed::after { content: " !"; color: var(--danger); font-weight: 700; }
.filter .months a[aria-current="true"]::after { color: inherit; }
.review { display: inline-block; border: 1px solid var(--line); border-radius: 3px; padding: 0 6px; font-size: 0.9em; }
.review.reviewed { border-color: var(--accent); color: var(--accent); }
.review.changed { border-color: var(--danger); color: var(--danger); font-weight: 600; }
.review.none { color: var(--muted); }
table.periods form.inline input[type="text"] { width: 14em; }
.comment { white-space: pre-wrap; }
/* 予算（1-11） */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 12px 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; }
.card-label { color: var(--muted); font-size: 0.85em; }
.card-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card-value.danger { color: var(--danger); }
table.report tr.subgroup td { color: var(--muted); padding-left: 16px; }
table.report tr.alert td { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
table.budget input.amount { width: 9em; text-align: right; font-variant-numeric: tabular-nums; }
ul.warnings { padding-left: 0; list-style: none; }
ul.warnings li { margin: 4px 0; padding: 6px 10px; border-left: 4px solid var(--line); background: var(--surface); }
ul.warnings li.warn { border-left-color: var(--danger); }
ul.warnings li.info { border-left-color: var(--accent); }
.filter-bar { flex-wrap: wrap; margin-bottom: 8px; }
.months-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-width: 900px; }
.months-form label { display: grid; gap: 2px; }
.months-form input.amount { text-align: right; }
table.budget-lines select[multiple] { min-width: 16em; }
input.short { width: 5em; }
/* 活動予算書（印刷） */
.print-doc { background: var(--surface); padding: 16px 24px; }
.doc-title { text-align: center; font-size: 1.3rem; }
.doc-sub { text-align: center; color: var(--muted); }
table.activity-budget { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.activity-budget th, table.activity-budget td { border: 1px solid var(--line); padding: 3px 8px; }
table.activity-budget .num { text-align: right; white-space: nowrap; }
table.activity-budget tr.h1 td { font-weight: 700; }
table.activity-budget tr.h2 td { padding-left: 24px; font-weight: 600; }
table.activity-budget tr.h3 td { padding-left: 40px; }
table.activity-budget td.item { padding-left: 56px; }
table.activity-budget tr.sum td { font-weight: 600; }
@media print {
  header.site, .no-print, .flash { display: none !important; }
  body, .print-doc { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  table.activity-budget th, table.activity-budget td { border-color: #555; }
}
/* 監査ログ（F-26） */
table.audit pre { white-space: pre-wrap; word-break: break-all; max-width: 520px; font-size: 0.85em; background: var(--bg); padding: 6px; margin: 2px 0; }
/* 取込（1-8） */
table.kv { border-collapse: collapse; background: var(--surface); margin: 8px 0 16px; }
table.kv th, table.kv td { border-bottom: 1px solid var(--line); padding: 6px 12px; text-align: left; vertical-align: top; }
table.kv th { color: var(--muted); font-weight: 600; white-space: nowrap; }
table.kv td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tr.draft td { background: var(--notice); }
table.list tr.reversed td { color: var(--inactive); }
table.report tr.item td { color: var(--muted); font-size: 0.92em; }
.picker { position: relative; min-width: 9rem; }
.picker input { width: 100%; }
.picker-list { position: absolute; z-index: 20; min-width: 100%; max-height: 16rem; overflow: auto; background: var(--surface, white); border: 1px solid var(--border, #aaa); box-shadow: 0 3px 8px #0002; }
.picker-list [role="option"] { padding: .4rem .6rem; cursor: pointer; }
.picker-list [aria-selected="true"], .picker-list [role="option"]:hover { background: var(--bg-hover, #e8eef5); }
.picker-list small { color: var(--muted, #666); }
/* 規則・CSV の読み方の一覧（設定）：状態とボタン、口座は折り返さない */
table.rules td:last-child, table.profiles td:last-child, table.rules td:nth-child(3), table.profiles td:nth-child(4) { white-space: nowrap; }
table.profiles input[name="name"] { width: 16em; }
