:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2430;
  --ink2: #556070;
  --ink3: #8a93a1;
  --line: #e3e6eb;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --accent-soft: #e8eff7;
  --ok: #1f7a4d;
  --ok-soft: #e6f4ec;
  --warn: #9a6200;
  --warn-soft: #fdf3dd;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  font-size: 15px; line-height: 1.7; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 80px 16px; text-align: center; color: var(--ink3); }
.num { font-variant-numeric: tabular-nums; }

/* ヘッダー */
.top { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.brand b { font-size: 16px; letter-spacing: .02em; }
.brand small { display: block; font-size: 11px; color: var(--ink3); line-height: 1.2; }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a, .nav button { text-decoration: none; color: var(--ink2); padding: 6px 10px; border-radius: 8px; border: 0; background: none; cursor: pointer; font-size: 14px; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a:hover, .nav button:hover { background: #eef0f3; }
.who { font-size: 12px; color: var(--ink2); display: flex; gap: 6px; align-items: center; }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: #eef0f3; color: var(--ink2); white-space: nowrap; }
.tag.demo { background: var(--warn-soft); color: var(--warn); }
.tag.test { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 80px; }
h1 { font-size: 22px; margin: 4px 0 16px; line-height: 1.4; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--ink2); }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.grid2 > div { min-width: 0; }
.panel a, .timeline .msg { overflow-wrap: anywhere; }
.tbl td:first-child { min-width: 7.5em; }

/* ボタン */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; line-height: 1.4; }
.btn:hover { background: #f1f3f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.big { padding: 12px 20px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }

/* 状態 */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 99px; white-space: nowrap; }
.st-requested { background: #efe9fb; color: #5b3a9b; }
.st-working, .st-revision { background: var(--accent-soft); color: var(--accent); }
.st-delivered { background: var(--warn-soft); color: var(--warn); }
.st-charging { background: #eef0f3; color: var(--ink2); }
.st-payment_failed { background: var(--bad-soft); color: var(--bad); }
.st-paid { background: var(--ok-soft); color: var(--ok); }
.st-cancelled { background: #eef0f3; color: var(--ink3); }

/* 一覧 */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 640px) { .stats { grid-template-columns: 1fr; } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--ink2); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--ink3); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 4px 14px; cursor: pointer; font-size: 13px; color: var(--ink2); }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.plist { display: grid; gap: 10px; }
.pcard { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.pcard:hover { border-color: #c9d3df; }
.pcard .t { font-weight: 600; }
.pcard .amt { text-align: right; font-weight: 700; }
.pcard .meta { font-size: 12px; color: var(--ink2); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.pcard .todo { grid-column: 1 / -1; font-size: 12px; color: var(--warn); font-weight: 600; }
.empty { text-align: center; padding: 40px 16px; color: var(--ink3); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

/* 次にやること */
.next { border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.next.warn { border-color: var(--warn); background: var(--warn-soft); }
.next.bad { border-color: var(--bad); background: var(--bad-soft); }
.next.ok { border-color: var(--ok); background: var(--ok-soft); }
.next b { display: block; margin-bottom: 4px; }
.next .row { margin-top: 10px; }

/* ステップ */
.steps { display: flex; gap: 0; margin: 0 0 18px; padding: 0; list-style: none; font-size: 12px; }
.steps li { flex: 1; text-align: center; color: var(--ink3); position: relative; padding-top: 18px; }
.steps li::before { content: ""; position: absolute; top: 5px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--line); z-index: 1; }
.steps li::after { content: ""; position: absolute; top: 9px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.steps li:first-child::after { display: none; }
.steps li.done, .steps li.cur { color: var(--ink); }
.steps li.done::before, .steps li.done::after, .steps li.cur::after { background: var(--accent); }
.steps li.cur::before { background: var(--panel); border: 3px solid var(--accent); width: 14px; height: 14px; top: 3px; margin-left: -7px; }
.steps li.cur { font-weight: 700; }

/* 表 */
table { border-collapse: collapse; width: 100%; }
.tbl th, .tbl td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 12px; color: var(--ink2); font-weight: 600; white-space: nowrap; }
.tbl td.r, .tbl th.r { text-align: right; white-space: nowrap; }
.tbl td.small { white-space: nowrap; }
.tbl tfoot td { border-bottom: 0; }
.wrap-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sum { margin-top: 10px; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: 14px; }
.sum .k { color: var(--ink2); }
.sum .v { text-align: right; }
.sum .pay { font-size: 18px; font-weight: 700; color: var(--ink); border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }
.diff-up { color: var(--warn); font-weight: 600; }
.diff-dn { color: var(--ok); font-weight: 600; }
.strike { text-decoration: line-through; color: var(--ink3); }

/* フォーム */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=url], select, textarea {
  width: 100%; border: 1px solid #cfd5dd; border-radius: 8px; padding: 8px 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.items-edit td { padding: 6px 4px; }
.items-edit input, .items-edit select { padding: 6px 8px; }
.items-edit .w-kind { width: 120px; } .items-edit .w-price { width: 96px; } .items-edit .w-qty { width: 96px; } .items-edit .w-unit { width: 56px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; white-space: nowrap; }
.hint { font-size: 12px; color: var(--ink3); }

/* 履歴 */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 5px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--ink3); }
.timeline li.client::before { border-color: #5b3a9b; }
.timeline li.owner::before { border-color: var(--accent); }
.timeline li.system::before { border-color: var(--warn); }
.timeline .when { font-size: 12px; color: var(--ink3); }
.timeline .who2 { font-size: 12px; font-weight: 600; margin-right: 6px; }
.timeline .msg { white-space: pre-wrap; font-size: 14px; }
.timeline li.alert .msg { color: var(--warn); font-weight: 600; }

/* ログイン */
.login { max-width: 460px; margin: 48px auto; }
.login h1 { text-align: center; }
.choice { display: grid; gap: 10px; }
.choice button { text-align: left; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); cursor: pointer; }
.choice button:hover { border-color: var(--accent); }
.choice b { display: block; }
.choice span { font-size: 13px; color: var(--ink2); }

/* モーダル */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; max-width: 460px; width: 100%; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal h2 { margin-bottom: 8px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); }

/* 請求書・領収書 */
.doc-tools { max-width: 800px; margin: 0 auto 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.doc { background: #fff; max-width: 800px; margin: 0 auto; padding: 48px 56px; border: 1px solid var(--line); color: #111; font-size: 13px; line-height: 1.7; }
@media (max-width: 640px) { .doc { padding: 24px 16px; } }
.doc h1 { text-align: center; font-size: 24px; letter-spacing: .4em; margin: 0 0 28px; }
.doc .head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 20px; }
.doc .to { font-size: 17px; border-bottom: 1px solid #111; padding-bottom: 2px; display: inline-block; min-width: 260px; }
.doc .from { text-align: right; font-size: 12px; }
.doc .big { font-size: 20px; font-weight: 700; border-bottom: 2px solid #111; display: inline-block; padding: 0 4px; margin: 6px 0 16px; }
.doc table th, .doc table td { border: 1px solid #999; padding: 6px 8px; }
.doc table th { background: #f2f2f2; font-weight: 600; }
.doc .tot { width: 320px; margin-left: auto; margin-top: 10px; }
.doc .tot td { border: 1px solid #999; }
.doc .note { margin-top: 20px; font-size: 12px; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .top, .doc-tools, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; max-width: none; }
}
