:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1f2933; --sub: #616e7c; --line: #d9dee4; --line2: #eef0f3;
  --accent: #1f6f8b; --accent-ink: #fff; --accent-soft: #e3f0f5; --warn: #b54708; --danger: #b42318; --ok: #157347;
  --input: #fffdf2; --calc: #f2f7fa; --head: #f7f8fa;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* レイアウト */
.shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.top { grid-column: 1 / 3; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--accent); color: #fff; }
.top .brand { font-weight: 700; font-size: 16px; letter-spacing: .04em; }
.top .ym { display: flex; align-items: center; gap: 6px; margin-left: 12px; }
.top .ym select, .top .ym input { border: 0; border-radius: 6px; padding: 5px 8px; color: var(--ink); }
.top .ym .lbl { font-size: 13px; opacity: .9; }
.top .spacer { flex: 1; }
.top .who { font-size: 13px; opacity: .95; }
.top button { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.nav { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 0 30px; }
.nav h4 { margin: 14px 16px 4px; font-size: 11px; color: var(--sub); font-weight: 600; letter-spacing: .08em; }
.nav a { display: block; padding: 7px 16px 7px 20px; color: var(--ink); text-decoration: none; font-size: 13.5px; border-left: 3px solid transparent; }
.nav a:hover { background: var(--line2); }
.nav a.on { background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.main { overflow: auto; padding: 18px 22px 60px; }
.navtoggle { display: none; }

h1.pt { font-size: 20px; margin: 0 0 4px; }
.pdesc { color: var(--sub); font-size: 13px; margin: 0 0 14px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
.bar .grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }

/* ボタン */
.btn { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* タブ */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 2px solid var(--accent); margin-top: 8px; }
.tabs button { border: 1px solid var(--line); border-bottom: 0; background: #e9ecef; padding: 7px 12px; border-radius: 7px 7px 0 0; cursor: pointer; font-size: 13px; }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 表 */
.tw { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 0 0 8px 8px; max-height: calc(100vh - 250px); }
.tw.r { border-radius: 8px; }
table.g { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
table.g th { position: sticky; top: 0; background: var(--head); z-index: 2; font-weight: 600; font-size: 12px; color: #3e4c59; padding: 6px 6px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line2); white-space: nowrap; text-align: center; }
table.g td { padding: 2px 4px; border-bottom: 1px solid var(--line2); border-right: 1px solid var(--line2); white-space: nowrap; }
table.g tr:hover td { background: #fafcff; }
table.g td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.g td.calc { background: var(--calc); text-align: right; font-variant-numeric: tabular-nums; padding: 2px 8px; color: #243b53; }
table.g td.calc.strong { font-weight: 700; }
table.g .fix { position: sticky; left: 0; background: #fff; z-index: 1; width: 52px; min-width: 52px; max-width: 52px; }
table.g th.fix { z-index: 3; background: var(--head); }
table.g .fix2 { position: sticky; left: 52px; background: #fff; z-index: 1; }
table.g th.fix2 { z-index: 3; background: var(--head); }
table.g tfoot td { position: sticky; bottom: 0; background: #eef2f6; font-weight: 700; text-align: right; padding: 5px 8px; border-top: 1px solid var(--line); }
table.g input, table.g select { border: 1px solid transparent; background: var(--input); padding: 3px 5px; border-radius: 4px; width: 100%; min-width: 60px; }
table.g input:focus, table.g select:focus { outline: 2px solid var(--accent); background: #fff; }
table.g input.n { text-align: right; width: 78px; min-width: 0; }
table.g input.n.s { width: 56px; }
table.g input.t { min-width: 140px; }
table.g input.d { width: 132px; }
table.g input.tm { width: 92px; }
table.g td.saving input { background: #fff7d6; }
table.g td.err input { outline: 2px solid var(--danger); }
table.g tr.new td { background: #f3fbf5; }
.nm { font-weight: 600; }
.kana { color: var(--sub); font-size: 11px; }
.empty { padding: 30px; text-align: center; color: var(--sub); }

/* フォーム */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--sub); }
.form input, .form select, .form textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--ink); font-size: 14px; }
.form textarea { min-height: 70px; }
.form .wide { grid-column: 1 / -1; }
.form h3 { grid-column: 1 / -1; margin: 10px 0 0; font-size: 14px; border-bottom: 1px solid var(--line); padding-bottom: 4px; color: var(--accent); }
input.field, select.field { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }

.calcgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 12px; font-size: 13px; }
.calcgrid div { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: 3px 0; }
.calcgrid b { font-variant-numeric: tabular-nums; }
.calcgrid .hl { color: var(--accent); font-weight: 700; }

/* モーダル */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 30px 12px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: min(1100px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.small { width: min(480px, 100%); }
.modal header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal header h2 { font-size: 16px; margin: 0; flex: 1; }
.modal .body { padding: 14px 16px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }

/* ログイン */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #1f6f8b, #164b5e); }
.login form { background: #fff; padding: 28px 28px 22px; border-radius: 14px; width: min(360px, 92vw); box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.login h1 { font-size: 18px; margin: 0 0 18px; text-align: center; }
.login label { display: block; font-size: 12px; color: var(--sub); margin: 10px 0 4px; }
.login input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 15px; }
.login .btn { width: 100%; margin-top: 18px; padding: 10px; font-size: 15px; }
.login .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#toast div { background: #1f2933; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.err { background: var(--danger); }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.menu-grid a { display: block; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-decoration: none; color: var(--ink); }
.menu-grid a:hover { border-color: var(--accent); box-shadow: 0 3px 10px rgba(31,111,139,.12); }
.menu-grid a b { display: block; color: var(--accent); margin-bottom: 3px; }
.menu-grid a span { font-size: 12px; color: var(--sub); }
.stat { display: flex; gap: 12px; flex-wrap: wrap; }
.stat div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; min-width: 150px; }
.stat small { color: var(--sub); display: block; font-size: 12px; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--line2); color: var(--sub); }
.badge.w { background: #fff1e0; color: var(--warn); }

/* 帳票プレビュー */
.preview { background: #8a96a3; padding: 18px; border-radius: 8px; overflow: auto; max-height: calc(100vh - 220px); }
.preview .page { margin: 0 auto 18px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
#print { display: none; }

/* 帳票共通（画面・印刷とも） */
.page { background: #fff; width: 210mm; min-height: 297mm; padding: 14mm 14mm 12mm; color: #000; font-size: 10.5pt; position: relative; }
.page.land { width: 297mm; min-height: 210mm; padding: 10mm 10mm; }
.page.env { width: 120mm; min-height: 235mm; padding: 18mm 14mm; }
.page h1 { text-align: center; font-size: 18pt; letter-spacing: .3em; margin: 0 0 6mm; font-weight: 600; }
.page h2 { font-size: 13pt; margin: 0 0 3mm; }
.rt { width: 100%; border-collapse: collapse; font-size: 9pt; }
.rt th, .rt td { border: .6pt solid #333; padding: 1.2mm 1.6mm; }
.rt th { background: #eee; font-weight: 600; white-space: nowrap; }
.rt td.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rt tr.sub td { background: #f4f4f4; font-weight: 600; }
.rt tr.tot td { background: #e6e6e6; font-weight: 700; }
.rt.small { font-size: 8pt; }
.rt.small th, .rt.small td { padding: .7mm 1.4mm; }
.rh { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 3mm; font-size: 9.5pt; }
.inv-head { display: flex; justify-content: space-between; gap: 8mm; margin-bottom: 4mm; }
.inv-to { font-size: 13pt; border-bottom: 1pt solid #000; padding-bottom: 1mm; min-width: 80mm; }
.inv-to small { display: block; font-size: 9pt; margin-bottom: 1mm; }
.inv-from { text-align: right; font-size: 9.5pt; line-height: 1.6; }
.inv-total { display: flex; align-items: center; justify-content: space-between; border: 1.5pt solid #000; padding: 2.5mm 5mm; margin: 3mm 0 3mm; font-size: 14pt; }
.inv-total b { font-size: 18pt; letter-spacing: .05em; }
.inv-sec { margin-top: 3mm; }
.inv-sec h3 { font-size: 10.5pt; margin: 0 0 1.5mm; border-left: 3pt solid #000; padding-left: 2mm; }
.inv-msg { border: .6pt solid #333; padding: 2mm 3mm; margin-top: 4mm; font-size: 9.5pt; min-height: 10mm; }
.inv-pay { margin-top: 4mm; font-size: 9.5pt; }
.stamp { position: absolute; top: 12mm; right: 14mm; border: 1.2pt solid #c00; color: #c00; padding: 1mm 3mm; font-size: 10pt; transform: rotate(-6deg); }
.receipt { border: 1.2pt solid #000; padding: 6mm 8mm; margin-bottom: 8mm; min-height: 120mm; position: relative; }
.receipt .amt { font-size: 20pt; text-align: center; border-bottom: 1pt solid #000; margin: 6mm 20mm 4mm; padding-bottom: 1mm; letter-spacing: .05em; }
.receipt .cut { position: absolute; bottom: -5mm; left: 0; right: 0; border-top: .6pt dashed #888; }
.env-zip { font-size: 16pt; letter-spacing: .3em; margin-bottom: 10mm; }
.env-addr { font-size: 14pt; line-height: 1.8; margin-bottom: 14mm; }
.env-name { font-size: 20pt; text-align: center; letter-spacing: .1em; }
.env-from { position: absolute; bottom: 18mm; right: 14mm; font-size: 9pt; text-align: right; line-height: 1.6; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  #app, #toast { display: none !important; }
  #print { display: block; }
  #print .page { margin: 0; box-shadow: none; page-break-after: always; break-after: page; }
  #print .page:last-child { page-break-after: auto; break-after: auto; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { display: none; position: fixed; top: 52px; bottom: 0; left: 0; width: 240px; z-index: 30; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .nav.open { display: block; }
  .navtoggle { display: inline-block; }
  .top .brand { display: none; }
  .top .who, .top .pwbtn, .top .ym .lbl { display: none; }
  .top { gap: 8px; padding: 0 8px; }
  .top .ym { margin-left: 0; }
  .top .ym select { max-width: 200px; }
  .main { padding: 12px 10px 60px; }
}
