:root {
  --navy: #1f3a5f; --navy-2: #2b4f7e; --accent: #d97706; --accent-2: #f59e0b;
  --bg: #f4f6f9; --card: #fff; --line: #e2e6ec; --text: #1c2430; --muted: #6b7684;
  --in: #0f8a5f; --out: #c2410c; --danger: #dc2626; --warn: #b45309; --ok: #15803d;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--navy-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ── レイアウト ── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #dbe4f0; padding: 14px 10px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 16px; color: #fff; padding: 6px 10px 14px; letter-spacing: .02em; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: #9fb3cc; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; color: #dbe4f0; text-decoration: none; margin-bottom: 2px; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav a .badge { margin-left: auto; }
.side .me { margin-top: auto; padding: 10px; font-size: 12px; color: #b8c7db; border-top: 1px solid rgba(255,255,255,.12); }
.side .me b { color: #fff; display: block; }
.side .me button { margin-top: 6px; }
.main { padding: 18px 22px 80px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.mobile-top { display: none; align-items: center; justify-content: space-between; background: var(--navy); color: #fff; margin: -12px -12px 12px; padding: 10px 14px; font-weight: 700; }
.mobile-top small { font-weight: 400; color: #b8c7db; margin-left: 6px; font-size: 11px; }
.mobile-top button { background: rgba(255,255,255,.15); color: #fff; border: 0; }
.bulkbar[hidden] { display: none; }

/* ── モバイル ── */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); flex-direction: row; z-index: 30; overflow-x: auto; }
  .brand, .side .me { display: none; }
  .nav { display: flex; gap: 2px; width: 100%; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 10px; min-width: 56px; flex: 1; text-align: center; white-space: nowrap; }
  .nav a .ico { font-size: 18px; }
  .nav a .badge { margin: 0; position: absolute; transform: translate(14px,-4px); }
  .main { padding: 12px 12px 90px; }
  .mobile-top { display: flex; }
  .filters label { flex: 1 1 42%; }
  .filters label > input, .filters label > select { width: 100%; }
  .topbar h1 { font-size: 18px; }
}

/* ── 部品 ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .sub { font-weight: 400; color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11px; color: var(--muted); }
.kpi.warn .v { color: var(--warn); } .kpi.bad .v { color: var(--danger); } .kpi.good .v { color: var(--ok); }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: #f7f9fc; }
.btn.p { background: var(--navy); border-color: var(--navy); color: #fff; } .btn.p:hover { background: var(--navy-2); }
.btn.a { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.d { color: var(--danger); border-color: #f3c2c2; }
.btn.s { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #e9eef5; color: #3a4a60; white-space: nowrap; line-height: 1.5; }
.badge.new { background: #fee2e2; color: #991b1b; } .badge.classified { background: #fef3c7; color: #92400e; }
.badge.documented { background: #dcfce7; color: #166534; } .badge.confirmed { background: #dbeafe; color: #1e40af; }
.badge.flag { background: #fde68a; color: #7c2d12; } .badge.q { background: #ede9fe; color: #5b21b6; }
.badge.unpaid { background: #fee2e2; color: #991b1b; } .badge.partial { background: #fef3c7; color: #92400e; } .badge.paid { background: #dcfce7; color: #166534; }
.badge.role-admin { background: #1f3a5f; color: #fff; } .badge.role-accounting { background: #d97706; color: #fff; } .badge.role-advisor { background: #0f766e; color: #fff; }
.amt { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.in { color: var(--in); } .out { color: var(--out); }
.muted { color: var(--muted); } .small { font-size: 12px; } .tiny { font-size: 11px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 10px; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
input[type=text], input[type=number], input[type=date], input[type=month], input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; min-width: 0; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd3ee; border-color: var(--navy-2); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.form label > * { font-size: 14px; color: var(--text); }
.form .full { grid-column: 1 / -1; }
.form .inline { flex-direction: row; align-items: center; }

/* ── テーブル ── */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-weight: 600; color: var(--muted); font-size: 12px; background: #f9fafc; white-space: nowrap; position: sticky; top: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f5f8fc; }
.tbl tr.sel td { background: #eef4ff; }
.tbl td.desc { max-width: 380px; overflow-wrap: anywhere; }
.tbl tfoot td { font-weight: 700; background: #f9fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.compact th, .tbl.compact td { padding: 4px 6px; }

/* ── 明細のカード表示(スマホ) ── */
.txn-list { display: flex; flex-direction: column; gap: 6px; }
.txn { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; cursor: pointer; }
.txn:hover { border-color: #b9c8dd; }
.txn.sel { background: #eef4ff; border-color: #8fb0dc; }
.txn .d { font-size: 12px; color: var(--muted); white-space: nowrap; }
.txn .desc { grid-column: 2; overflow-wrap: anywhere; }
.txn .amt { grid-column: 3; font-weight: 700; font-size: 15px; }
.txn .meta { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--muted); align-items: center; }
.txn .chk { grid-row: 1 / 3; align-self: center; }

/* ── モーダル ── */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 20px 10px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 760px; box-shadow: 0 20px 60px rgba(0,0,0,.25); margin: auto 0; }
.modal.wide { max-width: 1000px; }
.modal .mh { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; border-radius: 12px 12px 0 0; z-index: 1; }
.modal .mh h3 { margin: 0; font-size: 16px; }
.modal .mb { padding: 14px 16px; }
.modal .mf { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: #fff; }
.x { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.section { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; }
.section h4 { margin: 0 0 8px; font-size: 13px; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.section h4 .sub { font-weight: 400; color: var(--muted); font-size: 11px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; flex-wrap: wrap; }
.item .grow { flex: 1; min-width: 120px; }
.item.cand { border-style: dashed; background: #fff; }
.comment { padding: 8px 10px; border-radius: 8px; background: #f6f8fb; margin-bottom: 6px; }
.comment .who { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.comment.resolved { opacity: .6; }
.comment .body { white-space: pre-wrap; margin-top: 3px; }
.bulkbar { position: sticky; bottom: 0; background: var(--navy); color: #fff; padding: 8px 12px; border-radius: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; z-index: 10; }
.bulkbar select { padding: 5px; }
#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
#toast div { background: #1c2430; color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); animation: fade 3.5s forwards; }
#toast div.err { background: var(--danger); }
@keyframes fade { 0% { opacity: 0; transform: translateY(6px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
.login { max-width: 380px; margin: 60px auto; }
.login .brand2 { text-align: center; margin-bottom: 18px; }
.login .brand2 h1 { margin: 0; color: var(--navy); font-size: 22px; }
.login input { width: 100%; margin-bottom: 10px; }
.login .btn { width: 100%; padding: 10px; }
.err-msg { color: var(--danger); font-size: 13px; margin: 6px 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--text); font-size: 13px; }
.tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.bar { height: 8px; background: #e9eef5; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--in); }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; min-width: 0; }
.chart .col .bars { display: flex; gap: 2px; align-items: flex-end; height: 100px; width: 100%; justify-content: center; }
.chart .col .bars i { display: block; width: 40%; max-width: 18px; border-radius: 3px 3px 0 0; }
.chart .col .bars i.i { background: var(--in); } .chart .col .bars i.o { background: var(--out); }
.chart .col .lab { font-size: 10px; color: var(--muted); white-space: nowrap; }
.help { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 12px; font-size: 12px; color: #78350f; margin-bottom: 10px; }
.flag-none { display: none; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-row .btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.mapping { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.mapping label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; }
.dropzone { border: 2px dashed #b9c8dd; border-radius: 10px; padding: 20px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone:hover { background: #f5f8fc; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.doc-ico { width: 44px; height: 44px; border-radius: 6px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 20px; background: #f6f8fb; }
.pl-table td.cat { font-weight: 700; background: #f3f6fa; }
.pl-table td.sub { padding-left: 22px; }
.summary-line { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-bottom: 8px; }
.summary-line b { font-variant-numeric: tabular-nums; }

/* ── 印刷 ── */
@media print {
  .side, .topbar .actions, .filters, .bulkbar, .no-print, .mobile-top { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; font-size: 11px; }
  .tbl th, .tbl td { padding: 3px 5px; }
  .modal-bg { position: static; background: none; padding: 0; } .modal { box-shadow: none; max-width: none; }
  .modal .mh, .modal .mf { display: none; }
}
.slip { max-width: 640px; margin: 0 auto; padding: 20px; border: 1px solid #333; font-size: 13px; }
.slip h2 { text-align: center; margin: 0 0 6px; }
.slip .meta { display: flex; justify-content: space-between; margin-bottom: 10px; }
.slip table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.slip th, .slip td { border: 1px solid #555; padding: 5px 8px; }
.slip th { background: #f0f0f0; text-align: left; width: 45%; }
.slip td { text-align: right; font-variant-numeric: tabular-nums; }
.slip .total td { font-weight: 700; font-size: 15px; }
