:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1f2328; --sub: #5c6470; --line: #d9dde3;
  --primary: #1f5fbf; --primary-ink: #fff; --ok: #1e7b45; --ok-bg: #e7f5ec;
  --ng: #c62828; --ng-bg: #fdecec; --draft-bg: #fffbe8;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
main { max-width: 1180px; margin: 0 auto; padding: 16px; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.top .brand { font-weight: bold; text-decoration: none; color: var(--ink); }
.top nav { display: flex; gap: 16px; flex-wrap: wrap; }
.top nav a { text-decoration: none; color: var(--sub); padding: 4px 2px; }
.top nav a[aria-current="page"] { color: var(--ink); border-bottom: 2px solid var(--primary); }
.password-once { border: 2px solid var(--primary); }
.password-once code { font-size: 1.4rem; letter-spacing: .08em; padding: 2px 8px; background: #f3f4f6; border-radius: 4px; }
.top .who { margin-left: auto; color: var(--sub); font-size: .9em; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 8px 0 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.card .bar { margin: 0 0 10px; }
details.card > summary { cursor: pointer; font-weight: bold; }
details.card[open] > summary { margin-bottom: 10px; }

label { display: block; margin-bottom: 10px; font-size: .9rem; color: var(--sub); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 3px; }
input, select, textarea { font: inherit; color: var(--ink); padding: 7px 9px; border: 1px solid #b9c0ca; border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 0 0 auto; }
.row > label.grow { flex: 1 1 240px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; }
fieldset.terms { display: flex; gap: 12px; flex-wrap: wrap; }
fieldset.seg { display: flex; gap: 14px; border: 0; padding: 0; margin: 0; }
fieldset.seg label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ink); }
fieldset.seg input { width: auto; margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.btn { display: inline-block; font: inherit; padding: 8px 16px; border-radius: 6px; border: 1px solid #aeb6c1; background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #174c99; }
.btn-danger-quiet { color: var(--ng); border-color: #e5b4b4; }
.btn:disabled { opacity: .5; cursor: wait; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 2px 6px; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.alert ul { margin: 0; padding-left: 1.2em; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--ng-bg); color: var(--ng); }
.hint { color: var(--sub); font-size: .85rem; margin: 4px 0 10px; }
.ng { color: var(--ng); font-weight: bold; margin: 4px 0 10px; }
.empty { color: var(--sub); padding: 30px 0; text-align: center; }

/* 一覧 */
.table-scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.list th, table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.list th { font-weight: normal; color: var(--sub); font-size: .85rem; background: #fafbfc; }
table.list td:nth-child(3) { white-space: normal; }
table.list .r, .r { text-align: right; }
table.list .c, .c { text-align: center; }
table.list input[type=checkbox] { width: 20px; height: 20px; cursor: pointer; }
tr.is-draft { background: var(--draft-bg); }
tr.is-paid td { color: var(--sub); }
tr.is-paid a { color: var(--sub); }
tr.is-overdue td { color: var(--ng); font-weight: bold; }
tr.is-overdue a { color: var(--ng); }
tr.is-void td { color: #9aa1ab; text-decoration: line-through; }
.tag { display: inline-block; font-size: .8rem; padding: 1px 8px; border-radius: 99px; background: #eef0f3; color: var(--sub); font-weight: normal; text-decoration: none; }
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-ng { background: var(--ng); color: #fff; }
.tag-sub { background: #e8f0fb; color: var(--primary); }

.search { margin-bottom: 14px; }
.search > summary { cursor: pointer; color: var(--primary); }
.search-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 8px; }
.search-form label { margin: 0; }
.search-form .range, .card .range { display: flex; gap: 6px; align-items: center; }
.search-form .range input, .card .range input { width: 150px; }
.logout { margin-top: 24px; text-align: right; }

/* 入力 */
table.items { width: 100%; border-collapse: collapse; min-width: 940px; }
table.items th { font-weight: normal; color: var(--sub); font-size: .82rem; text-align: left; padding: 4px; }
table.items td { padding: 3px 4px; }
table.items input, table.items select { width: 100%; padding: 6px 7px; }
table.items input[type=date] { width: 150px; }
table.items .date-cell { white-space: nowrap; }
table.items .range-toggle { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 0 6px; color: var(--sub); font-size: .82rem; }
table.items .range-toggle input { width: auto; margin: 0; }
table.items .range-end { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: .85rem; color: var(--sub); }
table.items .range-end[hidden] { display: none; }
.btn-block { display: block; width: 100%; text-align: center; margin-top: 8px; }
table.items .num { text-align: right; }
table.items .qty { width: 70px; }
table.items .unit { width: 60px; }
table.items .price { width: 130px; }
table.items .amount { width: 120px; white-space: nowrap; }
table.items td:nth-child(2) { min-width: 240px; }
#add-row { margin-top: 8px; }
table.totals { margin: 14px 0 0 auto; border-collapse: collapse; min-width: 300px; }
table.totals th { text-align: left; font-weight: normal; color: var(--sub); padding: 4px 16px 4px 0; }
table.totals td { text-align: right; padding: 4px 0; }
table.totals .grand th, table.totals .grand td { border-top: 2px solid var(--ink); font-weight: bold; font-size: 1.1rem; padding-top: 8px; color: var(--ink); }

/* 発行した請求書を見る */
.view { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.paper { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.paper iframe { width: 100%; height: 1200px; border: 0; display: block; }
.side .big { font-size: 1.2rem; font-weight: bold; margin: 0 0 4px; }
.paid-line { font-size: 1rem; margin: 10px 0; }
.paid-line input { width: 20px; height: 20px; }
.paid-line.is-overdue { color: var(--ng); font-weight: bold; }
.hist { margin: 0; padding-left: 1.1em; font-size: .85rem; color: var(--sub); }
@media (max-width: 900px) {
  .view { grid-template-columns: 1fr; }
  .paper iframe { height: 800px; }
}

/* ログイン */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: min(360px, calc(100% - 32px)); }
.login-box h1 { margin-bottom: 16px; }
