:root {
  --ink: #1a1a1a;
  --muted: #666;
  --line: #d0d0d0;
  --line-strong: #333;
  --bg: #f4f5f7;
  --accent: #1f6feb;
  --accent-2: #0b8457;
  --paper-w: 190mm;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "Noto Sans JP",
    system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ── 操作バー ── */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.toolbar__title { font-size: 16px; margin: 0; font-weight: 700; }
.toolbar__controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar label { font-size: 13px; color: var(--muted); }

select {
  padding: 7px 10px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  min-width: 120px;
}

.btn {
  padding: 8px 16px;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--accent { background: var(--accent-2); color: #fff; }
.btn--ghost { background: #eef0f3; color: #333; }
.btn:not(:disabled):hover { opacity: 0.88; }

.status {
  max-width: var(--paper-w);
  margin: 12px auto 0;
  padding: 0 4px;
  font-size: 14px;
  min-height: 20px;
}
.status.error { color: #c0392b; }
.status.info { color: var(--muted); }

/* ── 請求書用紙 ── */
.invoice-area { padding: 24px 16px 60px; }
.placeholder {
  max-width: var(--paper-w);
  margin: 40px auto;
  padding: 40px;
  text-align: center;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.invoice {
  max-width: var(--paper-w);
  margin: 0 auto;
  background: #fff;
  padding: 16mm 14mm;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  line-height: 1.6;
}

.inv-title {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.4em;
  margin: 0 0 20px;
  padding-left: 0.4em;
}

.inv-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}
.inv-head__meta { text-align: right; font-size: 12px; color: var(--muted); }
.inv-head__meta div { margin-bottom: 2px; }
.inv-head__meta b { color: var(--ink); }

.bill-to { min-width: 45%; }
.bill-to__name {
  font-size: 18px;
  font-weight: 700;
  border-bottom: 2px solid var(--line-strong);
  padding-bottom: 6px;
  display: inline-block;
  min-width: 60%;
}
.bill-to__name .sama { font-size: 14px; margin-left: 8px; }

.total-banner {
  margin: 20px 0 18px;
  padding: 12px 16px;
  background: #f0f4fb;
  border: 1px solid #cfe0f8;
  border-radius: 8px;
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.total-banner__label { font-size: 14px; font-weight: 700; }
.total-banner__amount { font-size: 26px; font-weight: 800; letter-spacing: 0.02em; }
.total-banner__note { font-size: 12px; color: var(--muted); }

.inv-columns {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 16px;
}
.inv-note { font-size: 12px; color: var(--muted); }
.issuer {
  font-size: 12px;
  text-align: right;
  min-width: 46%;
}
.issuer__name { font-size: 15px; font-weight: 700; color: var(--ink); }
.issuer div { margin-bottom: 1px; }

table.items {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 12.5px;
}
table.items th,
table.items td {
  border: 1px solid var(--line);
  padding: 7px 8px;
}
table.items thead th {
  background: #2b2b2b;
  color: #fff;
  font-weight: 600;
  text-align: center;
}
table.items td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.items td.center { text-align: center; }
table.items .staff { font-size: 11px; color: var(--muted); }
table.items tbody tr:nth-child(even) { background: #fafafa; }

.summary {
  width: 300px;
  margin-left: auto;
  border-collapse: collapse;
  font-size: 13px;
}
.summary td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.summary td.label { color: var(--muted); }
.summary td.num { text-align: right; font-variant-numeric: tabular-nums; }
.summary tr.grand td {
  border-top: 2px solid var(--line-strong);
  border-bottom: 2px solid var(--line-strong);
  font-weight: 800;
  font-size: 15px;
}

.footer {
  margin-top: 24px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.footer__box {
  flex: 1 1 240px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
}
.footer__box h3 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

/* ── 印刷（PDF出力）用 ── */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .no-print { display: none !important; }
  .invoice-area { padding: 0; }
  .invoice {
    box-shadow: none;
    max-width: none;
    width: 100%;
    padding: 0;
    margin: 0;
  }
}

@media (max-width: 640px) {
  .inv-head, .inv-columns, .footer { flex-direction: column; }
  .issuer { text-align: left; }
  .inv-head__meta { text-align: left; }
  .summary { width: 100%; }
}

/* ── 設定モーダル ── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.modal__panel {
  position: relative;
  background: #fff;
  width: min(720px, 94vw);
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.modal__head h2 { margin: 0; font-size: 17px; }
.modal__x { border: none; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal__body { padding: 8px 20px 4px; overflow-y: auto; }
.modal__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-top: 1px solid var(--line); background: #fafbfc;
}
.modal__actions { display: flex; gap: 10px; }
.modal__status { font-size: 13px; color: var(--muted); }
.modal__status.ok { color: var(--accent-2); }
.modal__status.error { color: #c0392b; }

.modal fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px 14px; margin: 14px 0; }
.modal legend { font-size: 13px; font-weight: 700; color: var(--accent); padding: 0 6px; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.modal input[type="text"], .modal select {
  display: block; width: 100%; margin-top: 4px;
  padding: 7px 9px; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.modal .row { display: flex; gap: 12px; flex-wrap: wrap; }
.modal .row > label { flex: 1 1 auto; }
.modal .w25 { flex-basis: 22%; } .modal .w30 { flex-basis: 28%; }
.modal .w35 { flex-basis: 33%; } .modal .w40 { flex-basis: 38%; }
.modal .w50 { flex-basis: 46%; } .modal .w70 { flex-basis: 66%; }
.modal label.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.modal label.checkbox input { width: auto; margin: 0; }
.modal label.checkbox span { color: var(--ink); }
.modal .hint { font-size: 11.5px; color: var(--muted); margin: 4px 2px 0; line-height: 1.5; }

@media (max-width: 640px) {
  .modal .w25, .modal .w30, .modal .w35, .modal .w40, .modal .w50, .modal .w70 { flex-basis: 100%; }
  .modal label.checkbox { margin-top: 4px; }
}
