:root {
  --line: #111;
  --soft: #d7deec;
  --ui-bg: #f3f6fc;
  --band: #3f87d9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  color: #1d1d1d;
  background: var(--ui-bg);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) 1fr;
  gap: 14px;
  min-height: 100vh;
  padding: 12px;
}

.form-panel {
  background: #fff;
  border: 1px solid #ccd5e7;
  border-radius: 10px;
  padding: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.form-panel h1 {
  margin: 0;
  font-size: 20px;
}

.hint {
  margin: 8px 0 10px;
  font-size: 12px;
  color: #4a556f;
}

.form-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.form-section {
  margin-bottom: 10px;
  border: 1px solid #dbe3f2;
  border-radius: 8px;
  background: #fbfcff;
  padding: 10px;
}

.form-section h2 {
  margin: 0 0 8px;
  font-size: 14px;
}

.form-section label {
  display: block;
  font-size: 12px;
  margin-bottom: 7px;
}

input,
textarea,
select,
button {
  width: 100%;
  font: inherit;
}

input,
textarea,
select {
  margin-top: 3px;
  border: 1px solid #b8c6df;
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

input::placeholder,
textarea::placeholder {
  color: #9aa0a6;
  opacity: 1;
}

button {
  border: 1px solid #6f88b8;
  border-radius: 7px;
  padding: 8px 6px;
  background: #ebf2ff;
  color: #17315f;
  cursor: pointer;
}

button.danger {
  border-color: #c37474;
  background: #fff0f0;
  color: #7b1d1d;
}

.inline-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: auto;
  margin: 0;
}

.detail-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}

.detail-editor-wrap {
  overflow: auto;
}

.detail-editor {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

.detail-editor th,
.detail-editor td {
  border: 1px solid #b9c6dd;
  padding: 3px;
  font-size: 12px;
}

.detail-editor th {
  background: #eef3fd;
}

.detail-editor td:last-child {
  text-align: right;
}

.preview-panel {
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px;
}

.estimate-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  padding: 11mm 11mm 9mm;
  box-shadow: 0 3px 18px rgba(0, 0, 0, 0.15);
  position: relative;
  line-height: 1.35;
  font-size: 12px;
  color: #111;
}

.top-right-page {
  position: absolute;
  top: 6mm;
  right: 11mm;
  font-size: 11px;
}

.doc-header {
  position: relative;
  min-height: 27mm;
}

.title-band {
  width: 98mm;
  margin-top: 11mm;
  background: var(--band);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 4px;
  letter-spacing: 0.08em;
}

.doc-no-wrap {
  position: absolute;
  right: 0;
  top: 10mm;
  width: 61mm;
  border-top: 1px solid var(--line);
  padding-top: 2mm;
  font-size: 13px;
  font-weight: 500;
}

.address-area {
  display: grid;
  grid-template-columns: 1fr 66mm;
  column-gap: 12mm;
  margin-top: 2mm;
}

.to-name {
  font-size: 15px;
  margin-bottom: 2px;
  min-height: 23px;
}

.to-person {
  text-align: right;
  font-size: 11px;
  min-height: 18px;
}

.line {
  border-top: 1px solid var(--line);
  margin: 2px 0 4px;
}

.from-block {
  margin-top: 26px;
  font-size: 12px;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.summary-table th,
.summary-table td {
  border-bottom: 1px solid var(--line);
  height: 7.1mm;
  font-size: 12px;
}

.summary-table th {
  width: 38mm;
  text-align: left;
  font-weight: 500;
}

.summary-table td {
  padding-left: 8px;
}

.summary-table .right {
  text-align: right;
  padding-right: 6px;
}

.strong {
  font-weight: 700;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.detail-table th,
.detail-table td {
  border: 1px solid var(--line);
  padding: 3px 4px;
  height: 7.35mm;
  font-size: 12px;
}

.detail-table th {
  background: #f2f2f2;
  font-weight: 500;
  text-align: left;
}

.col-name {
  width: 38%;
}

.col-price {
  width: 15%;
  text-align: right;
}

.col-qty {
  width: 9%;
  text-align: right;
}

.col-unit {
  width: 9%;
  text-align: center;
}

.col-tax {
  width: 9%;
  text-align: center;
}

.col-amt {
  width: 20%;
  text-align: right;
}

.detail-table td:nth-child(2),
.detail-table td:nth-child(3),
.detail-table td:nth-child(6),
.tax-rate-box td,
.total-box td {
  text-align: right;
}

.detail-table td:nth-child(4),
.detail-table td:nth-child(5) {
  text-align: center;
}

.bottom-box {
  display: grid;
  grid-template-columns: 1fr 37%;
  margin-top: -1px;
}

.remarks-box {
  border: 1px solid var(--line);
  border-right: none;
}

.remarks-head {
  border-bottom: 1px solid var(--line);
  min-height: 9mm;
  padding: 2px 5px;
}

.remarks-body {
  min-height: 12mm;
  padding: 4px 5px;
  white-space: pre-wrap;
}

.total-box,
.tax-rate-box {
  width: 100%;
  border-collapse: collapse;
}

.total-box th,
.total-box td,
.tax-rate-box th,
.tax-rate-box td {
  border: 1px solid var(--line);
  min-height: 8.5mm;
  padding: 3px 5px;
  font-size: 12px;
}

.total-box th,
.tax-rate-box th {
  text-align: left;
  font-weight: 500;
}

.tax-rate-box {
  margin-top: -1px;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .form-panel {
    max-height: none;
  }

  .preview-panel {
    justify-content: flex-start;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  html,
  body {
    margin: 0;
    padding: 0;
    background: #fff;
    overflow: visible !important;
  }

  .no-print {
    display: none !important;
  }

  .app-shell,
  .preview-panel {
    display: block;
    margin: 0;
    padding: 0;
    overflow: visible !important;
  }

  .estimate-page {
    box-shadow: none;
    width: 194mm;
    min-height: auto;
    margin: 0;
    padding: 8mm 8mm 6mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .doc-header,
  .address-area,
  .summary-table,
  .detail-table,
  .bottom-box,
  .tax-rate-box {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
