/* ============ 基本 ============ */
:root {
  --bg: #eef1f4;
  --ink: #1a222c;
  --muted: #5b6674;
  --line: #d5dbe2;
  --accent: #0f6db3;
  --accent-dark: #0b578f;
  --danger: #b3352b;
  --paper: #ffffff;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ============ ヘッダー ============ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand strong { font-size: 18px; margin-right: 10px; }
.brand span { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  padding: 7px 14px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: #f4f6f8; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fbf0ef; }

.btn-add { margin-top: 8px; width: 100%; border-style: dashed; color: var(--muted); }

/* ============ レイアウト ============ */
.app-main {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 20px;
}

@media (max-width: 980px) {
  .app-main { grid-template-columns: 1fr; }
}

/* ============ フォーム ============ */
.form-pane fieldset {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px 16px;
  margin: 0 0 14px;
}

.form-pane legend {
  font-weight: 700;
  font-size: 13px;
  padding: 0 6px;
}
.form-pane legend small { font-weight: 400; color: var(--muted); }

.field { margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

.field input[type="text"],
.field input[type="date"],
.field select,
.field textarea {
  width: 100%;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.field textarea { resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus,
.item-row input:focus,
.item-row select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.field-inline { display: flex; gap: 10px; }
.field-inline .grow { flex: 1; }

.field-check { display: flex; align-items: flex-start; gap: 8px; }
.field-check input { margin-top: 3px; }
.field-check label { font-size: 13px; color: var(--ink); margin: 0; }

.warning {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--danger);
}

/* 明細行 */
.item-header,
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 84px 64px 76px 26px;
  gap: 6px;
  align-items: center;
}

.item-header {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.item-row { margin-bottom: 6px; }

.item-row input,
.item-row select {
  width: 100%;
  padding: 6px 6px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 0;
}

.item-amount {
  font-size: 12px;
  text-align: right;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-remove {
  width: 26px; height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.item-remove:hover { color: var(--danger); border-color: var(--danger); }

/* ============ フッター ============ */
.app-footer {
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px 20px 32px;
  color: var(--muted);
  font-size: 12px;
}
.app-footer p { margin: 2px 0; }

/* ============ 請求書プレビュー（画面・印刷共通のドキュメント体裁） ============ */
.preview-wrap { min-width: 0; }

.paper {
  background: var(--paper);
  color: #111;
  width: 100%;
  max-width: 794px; /* A4幅 210mm ≒ 794px @96dpi */
  min-height: 1000px;
  margin: 0 auto;
  padding: 52px 48px;
  box-shadow: 0 2px 14px rgba(20, 30, 40, 0.12);
  font-size: 13px;
}

.doc-title {
  margin: 0 0 30px;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-indent: 0.5em; /* letter-spacingの右側余白を相殺して中央に見せる */
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 28px;
}

.doc-head-left { flex: 1; min-width: 0; }

.pv-client {
  margin: 0 0 6px;
  font-size: 17px;
  border-bottom: 1px solid #333;
  padding-bottom: 4px;
}

.pv-subject { margin: 4px 0; }
.pv-greeting { margin: 8px 0 0; }

.pv-total-box {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  max-width: 300px;
  margin-top: 18px;
  padding: 10px 16px;
  border: 2px solid #333;
}
.pv-total-box strong { font-size: 21px; }

.doc-head-right { text-align: left; flex-shrink: 0; max-width: 45%; }

.pv-meta { border-collapse: collapse; margin-left: auto; }
.pv-meta th {
  font-weight: 400;
  color: #444;
  text-align: left;
  padding: 1px 14px 1px 0;
}
.pv-meta td { text-align: right; padding: 1px 0; }

.pv-issuer { margin-top: 16px; font-size: 12px; line-height: 1.7; }
.pv-issuer p { margin: 0; }
.pv-issuer-name { font-size: 14px; font-weight: 700; }

/* 明細テーブル */
.pv-items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 30px;
}

.pv-items th, .pv-items td {
  border: 1px solid #777;
  padding: 6px 9px;
}

.pv-items thead th {
  background: #f0f2f4;
  font-weight: 600;
  text-align: center;
}

.pv-items .col-qty { width: 62px; }
.pv-items .col-price { width: 110px; }
.pv-items .col-amount { width: 128px; }
.pv-items td.num { text-align: right; white-space: nowrap; }

/* 合計テーブル */
.pv-totals {
  border-collapse: collapse;
  margin: 12px 0 0 auto;
  min-width: 330px;
}

.pv-totals th {
  font-weight: 400;
  text-align: left;
  padding: 4px 18px 4px 0;
}
.pv-totals td { text-align: right; padding: 4px 0; white-space: nowrap; }

.pv-totals .pv-grand th,
.pv-totals .pv-grand td {
  border-top: 2px solid #333;
  font-weight: 700;
  font-size: 15px;
  padding-top: 7px;
}

.pv-note { margin: 10px 0 0; font-size: 11px; color: #555; }

.pv-block { margin-top: 22px; }
.pv-block h2 {
  margin: 0 0 4px;
  font-size: 12px;
  padding: 3px 8px;
  background: #f0f2f4;
  border-left: 3px solid #333;
}
.pv-block p { margin: 0; padding: 0 4px; }

.pre-line { white-space: pre-line; }

.pv-credit {
  margin: 36px 0 0;
  text-align: right;
  font-size: 10px;
  color: #9aa3ad;
}

/* ============ 印刷 ============ */
@media print {
  @page { size: A4 portrait; margin: 13mm; }

  body { background: #fff; }

  .app-header,
  .form-pane,
  .app-footer { display: none !important; }

  .app-main { display: block; padding: 0; max-width: none; }

  .paper {
    box-shadow: none;
    max-width: none;
    width: auto;
    min-height: 0;
    padding: 0;
    font-size: 12px;
  }
}
