:root {
  --bg: #f4f7f8;
  --panel: #ffffff;
  --line: #d7e0e4;
  --line-strong: #b8c6cd;
  --text: #1f2933;
  --muted: #5b6975;
  --primary: #0f766e;
  --primary-soft: #e0f2ef;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success-soft: #e9f8ef;
  --warning-soft: #fff5e8;
  --shadow: 0 12px 28px rgba(31, 41, 51, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #eef4f5 0%, #f8fafb 100%);
  color: var(--text);
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
}

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

.back-link {
  display: inline-flex;
  margin-bottom: 16px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.back-link:hover,
.back-link:focus-visible {
  text-decoration: underline;
}

.hero,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px;
}

.hero-badge {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hero h1 {
  margin: 14px 0 10px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.25;
}

.hero-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}

.panel {
  padding: 22px;
}

.panel-heading {
  margin-bottom: 18px;
}

.panel-heading h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.panel-heading p,
.subsection-head p,
.field-hint,
.payment-note,
.summary-card small {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 0.9rem;
}

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

.subsection {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.subsection-head,
.toggle-row,
.extras-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.subsection-head {
  margin-bottom: 14px;
}

.subsection-head h3,
.breakdown h3 {
  margin: 0;
  font-size: 1rem;
}

.toggle-row {
  padding: 12px 14px;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

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

.toggle-group {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.toggle-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

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

.input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #fff;
  padding-right: 14px;
  overflow: hidden;
}

.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.input-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 14px 14px 14px 16px;
  font: inherit;
  color: var(--text);
}

.input-wrap span {
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.rate-wrap input {
  padding-right: 10px;
}

.field-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
}

.field.invalid .input-wrap {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.field.readonly .input-wrap {
  background: #f3f6f7;
}

.field.readonly input {
  color: #425466;
}

.form-error {
  display: none;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #f0b1aa;
  background: var(--danger-soft);
  color: var(--danger);
  line-height: 1.6;
}

.form-error.visible {
  display: block;
}

.extras {
  margin-top: 18px;
}

.extra-list {
  display: grid;
  gap: 12px;
}

.extra-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px) 92px;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafcfd;
}

.add-button,
.remove-button {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.add-button {
  padding: 10px 14px;
}

.remove-button {
  align-self: end;
  height: 46px;
}

.add-button:hover,
.remove-button:hover,
.add-button:focus-visible,
.remove-button:focus-visible {
  border-color: var(--primary);
  color: var(--primary);
}

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

.summary-card {
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fbfcfc;
}

.summary-card.accent {
  background: var(--primary-soft);
  border-color: #bfe5de;
}

.summary-card.positive {
  background: var(--success-soft);
  border-color: #b4e1c3;
}

.summary-card.negative {
  background: var(--warning-soft);
  border-color: #f1d4a6;
}

.summary-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.summary-card strong {
  display: block;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  line-height: 1.2;
}

.payment-panel {
  margin-top: 16px;
  padding: 18px;
  border-radius: 18px;
  background: #0f172a;
  color: #f8fafc;
}

.payment-label {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: #cbd5e1;
}

.payment-panel strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.breakdown {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.breakdown-list {
  margin: 12px 0 0;
}

.breakdown-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f3;
}

.breakdown-list dt {
  color: var(--muted);
}

.breakdown-list dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.export-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.export-head {
  margin-bottom: 12px;
}

.export-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.export-button {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 12px 16px;
}

.export-button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.export-button:hover,
.export-button:focus-visible {
  border-color: var(--primary);
  color: var(--primary);
}

.export-button.primary:hover,
.export-button.primary:focus-visible {
  color: #fff;
  opacity: 0.92;
}

.export-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

.document-preview-wrap {
  margin-top: 24px;
}

.preview-header {
  margin-bottom: 12px;
}

.preview-header h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.preview-header p {
  margin: 0;
  color: var(--muted);
}

.submission-sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  color: #111827;
  padding: 18mm 16mm;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
  border: 1px solid #e5e7eb;
}

.submission-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  border-bottom: 2px solid #d1d5db;
  padding-bottom: 14px;
}

.submission-kicker {
  margin: 0 0 8px;
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  color: #475569;
}

.submission-header h2 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.3;
}

.submission-meta {
  margin: 0;
  min-width: 220px;
}

.submission-meta div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 6px 0;
  border-bottom: 1px solid #e5e7eb;
}

.submission-meta dt {
  color: #475569;
}

.submission-meta dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.submission-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.submission-box {
  border: 1px solid #d1d5db;
  padding: 12px;
  background: #fafafa;
}

.submission-box span {
  display: block;
  margin-bottom: 8px;
  color: #475569;
  font-size: 0.88rem;
}

.submission-box strong {
  font-size: 1.15rem;
  line-height: 1.4;
}

.submission-table-wrap {
  margin-top: 22px;
}

.submission-table-wrap h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.submission-table {
  width: 100%;
  border-collapse: collapse;
}

.submission-table th,
.submission-table td {
  border: 1px solid #d1d5db;
  padding: 10px 12px;
  font-size: 0.94rem;
}

.submission-table th {
  background: #f8fafc;
  text-align: left;
}

.submission-table td:last-child,
.submission-table th:last-child {
  text-align: right;
  white-space: nowrap;
}

.submission-totals {
  margin-top: 20px;
  margin-left: auto;
  width: min(100%, 360px);
}

.submission-totals dl {
  margin: 0;
}

.submission-totals div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0;
  border-bottom: 1px solid #d1d5db;
}

.submission-totals dt {
  color: #475569;
}

.submission-totals dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.submission-footer {
  margin-top: 28px;
  border-top: 1px solid #d1d5db;
  padding-top: 14px;
  font-size: 0.9rem;
  line-height: 1.8;
  color: #334155;
}

.submission-footer p {
  margin: 0 0 8px;
}

@media (max-width: 900px) {
  .layout,
  .field-grid,
  .summary-cards,
  .submission-summary {
    grid-template-columns: 1fr;
  }

  .extra-item {
    grid-template-columns: 1fr;
  }

  .remove-button {
    width: 100%;
  }

  .submission-sheet {
    width: 100%;
    min-height: auto;
    padding: 24px 18px;
  }

  .submission-header {
    flex-direction: column;
  }

  .submission-meta,
  .submission-totals {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .page {
    width: min(100% - 14px, 1120px);
    padding: 14px 0 28px;
  }

  .hero,
  .panel {
    padding: 16px;
    border-radius: 18px;
  }

  .toggle-row,
  .subsection-head,
  .extras-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .input-wrap input,
  .add-button,
  .remove-button,
  .export-button {
    font-size: 16px;
  }

  .submission-sheet {
    padding: 18px 14px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .page {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .back-link,
  .hero,
  .layout,
  .preview-header {
    display: none !important;
  }

  .document-preview-wrap {
    margin: 0;
  }

  .submission-sheet {
    width: auto;
    min-height: auto;
    margin: 0;
    box-shadow: none;
    border: 0;
    padding: 12mm;
  }

  @page {
    size: A4;
    margin: 12mm;
  }
}
