﻿/* =============================
   基本設定
   ============================= */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: #222;
  background: #f5f5f5;
  line-height: 1.6;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-wrap {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 40px;
}

/* =============================
   タイトル
   ============================= */
.app-title {
  margin: 0 0 12px;
  padding: 4px 0 12px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  border-bottom: 1px solid #cfcfcf;
}

/* =============================
   共通セクション
   ============================= */
.section-box {
  background: #ffffff;
  border: 1px solid #cfcfcf;
  padding: 14px;
  margin-bottom: 16px;
}

.section-heading {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 700;
  border-bottom: 1px solid #dddddd;
  padding-bottom: 6px;
}

.notice-box {
  background: #fafafa;
  border: 1px solid #d9d9d9;
  padding: 10px;
  margin-bottom: 12px;
}

.notice-text {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 10px;
}

.field-grid-second {
  margin-top: 10px;
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.col-2 {
  grid-column: span 2;
}

.col-3 {
  grid-column: span 3;
}

.col-4 {
  grid-column: span 4;
}

.col-5 {
  grid-column: span 5;
}

.col-6 {
  grid-column: span 6;
}

label {
  font-size: 0.95rem;
  font-weight: 700;
}

.sub-label {
  font-weight: 400;
  color: #555;
  font-size: 0.88rem;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #bdbdbd;
  background: #ffffff;
  padding: 8px 10px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding-top: 24px;
}

.small-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.small-inline input {
  flex: 1;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  min-height: 38px;
  border: 1px solid #7f7f7f;
  background: #f0f0f0;
  padding: 8px 14px;
  color: #111;
}

.btn:hover {
  background: #e5e5e5;
}

.btn-primary {
  background: #dddddd;
  font-weight: 700;
}

.btn-danger {
  background: #efefef;
  border-color: #999999;
}

.validation-text,
.status-text {
  margin: 10px 0 0;
  font-size: 0.92rem;
  min-height: 1.4em;
}

.validation-text {
  color: #b00020;
}

.status-text {
  color: #0d4f8b;
}

/* =============================
   修正・表示エリア
   ============================= */
.display-wrap {
  background: #f0f0f0;
  border: 1px solid #c6c6c6;
  padding: 14px;
}

.sticky-display-tools {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #d9d9d9;
  border: 1px solid #a8a8a8;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.display-tools-top,
.display-tools-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.display-tools-top {
  justify-content: space-between;
  margin-bottom: 10px;
}

.display-tools-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tool-label {
  font-weight: 700;
}

.current-data-name {
  font-weight: 700;
  color: #111;
  background: #f8f8f8;
  border: 1px solid #bdbdbd;
  padding: 6px 10px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

/* =============================
   帳票本文
   ============================= */
.document-paper {
  background: #ffffff;
  border: 1px solid #d0d0d0;
  padding: 24px;
  min-height: 320px;
}

.document-header {
  margin-bottom: 18px;
}

.document-title-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}

.document-company,
.document-date {
  font-size: 0.95rem;
  border-bottom: 1px solid #d9d9d9;
  padding-bottom: 4px;
  min-height: 32px;
}

.document-date {
  text-align: right;
}

.document-title {
  margin: 0;
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.document-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.party-box {
  border: 1px solid #d3d3d3;
  padding: 10px 12px;
  min-height: 80px;
}

.party-label {
  font-size: 0.88rem;
  color: #555;
  margin-bottom: 6px;
}

.party-value {
  font-size: 1rem;
  font-weight: 700;
  word-break: break-word;
}

.right-box .party-value {
  font-weight: 400;
}

.document-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.meta-line {
  border-bottom: 1px solid #d9d9d9;
  padding-bottom: 4px;
  min-height: 28px;
}

.sheet-section {
  margin-bottom: 20px;
}

.sheet-section:last-child {
  margin-bottom: 0;
}

.sheet-section-title {
  font-size: 1rem;
  font-weight: 700;
  border-bottom: 1px solid #bdbdbd;
  margin: 0 0 10px;
  padding-bottom: 5px;
}

.category-heading {
  margin: 12px 0 6px;
  font-weight: 700;
  background: #f7f7f7;
  border-left: 4px solid #bdbdbd;
  padding: 4px 8px;
}

.estimate-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}

.estimate-table th,
.estimate-table td {
  border: 1px solid #cfcfcf;
  padding: 8px;
  vertical-align: top;
  text-align: left;
  font-size: 0.95rem;
}

.estimate-table th {
  background: #f3f3f3;
}

.text-right {
  text-align: right;
}

.indent-label {
  padding-left: 18px;
}

.row-action-cell {
  width: 160px;
  white-space: nowrap;
}

.inline-action-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-btn {
  border: 1px solid #8c8c8c;
  background: #f4f4f4;
  padding: 5px 10px;
  min-height: 32px;
}

.mini-btn:hover {
  background: #e7e7e7;
}

.edit-row-panel {
  background: #fafafa;
  border: 1px solid #d0d0d0;
  padding: 12px;
  margin: 8px 0 12px;
}

.summary-table {
  width: min(520px, 100%);
  margin-left: auto;
  border-collapse: collapse;
}

.summary-table th,
.summary-table td {
  border: 1px solid #cfcfcf;
  padding: 8px 10px;
  font-size: 0.95rem;
}

.summary-table th {
  width: 55%;
  background: #f5f5f5;
  text-align: left;
}

.empty-text {
  color: #555;
  margin: 0;
}

.screen-only {
  display: block;
}

/* =============================
   印刷時
   ============================= */
@page {
  size: A4;
  margin: 12mm;
}

@media print {
  body {
    background: #ffffff;
    color: #000;
  }

  .app-title,
  .input-area,
  .sticky-display-tools,
  .screen-only,
  .section-heading {
    display: none !important;
  }

  .page-wrap {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .display-wrap,
  .document-paper {
    background: #ffffff;
    border: none;
    padding: 0;
    margin: 0;
  }

  .document-paper {
    min-height: auto;
  }

  .document-header {
    margin-bottom: 12mm;
  }

  .document-title-row {
    grid-template-columns: 1fr 1.2fr 1fr;
    align-items: start;
    gap: 8mm;
    margin-bottom: 8mm;
  }

  .document-company {
    border: none;
    padding: 0;
    min-height: auto;
    font-size: 11pt;
    font-weight: 700;
    text-align: left;
    align-self: start;
  }

  .document-title {
    font-size: 18pt;
    letter-spacing: 0.06em;
    text-align: center;
    align-self: center;
  }

  .document-date {
    border: none;
    padding: 0;
    min-height: auto;
    font-size: 10.5pt;
    text-align: right;
    align-self: start;
  }

  .document-parties {
    grid-template-columns: 1fr 1fr;
    gap: 10mm;
    margin-bottom: 6mm;
  }

  .party-box {
    border: none;
    padding: 0;
    min-height: auto;
  }

  .party-label {
    display: none !important;
  }

  .party-value {
    font-size: 12pt;
    font-weight: 700;
    border-bottom: 1px solid #666666;
    padding-bottom: 2mm;
    min-height: 8mm;
  }

  .right-box .party-value {
    font-weight: 400;
  }

  .document-meta {
    gap: 4mm;
    margin-bottom: 2mm;
  }

  .meta-line {
    border: none;
    padding: 0;
    min-height: auto;
    font-size: 10.5pt;
  }

  .sheet-section {
    margin-bottom: 8mm;
    break-inside: avoid;
  }

  .sheet-section-title {
    display: none !important;
  }

  .category-heading {
    margin: 4mm 0 2mm;
    padding: 0;
    background: transparent;
    border-left: none;
    font-size: 10.5pt;
    font-weight: 700;
  }

  .estimate-table {
    margin-bottom: 2mm;
  }

  .estimate-table th,
  .estimate-table td {
    border: 1px solid #888888;
    padding: 2.5mm 2mm;
    font-size: 10pt;
  }

  .estimate-table th {
    background: #ffffff;
    font-weight: 700;
  }

  .row-action-cell {
    display: none !important;
  }

  .summary-table {
    width: 72mm;
    margin-left: auto;
  }

  .summary-table th,
  .summary-table td {
    border: 1px solid #888888;
    padding: 2.5mm 2mm;
    font-size: 10pt;
  }

  .summary-table th {
    background: #ffffff;
    width: 60%;
  }

  .empty-text {
    font-size: 10pt;
  }
}

@media (max-width: 920px) {
  .col-2,
  .col-3,
  .col-4,
  .col-5,
  .col-6 {
    grid-column: span 12;
  }

  .document-title-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .document-date {
    text-align: left;
  }

  .document-parties {
    grid-template-columns: 1fr;
  }

  .display-tools-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-table {
    margin-left: 0;
  }
}