:root {
  color-scheme: light;
  --ink: #16202a;
  --muted: #647181;
  --line: #d8dee7;
  --panel: #ffffff;
  --page: #f4f6f8;
  --accent: #1f6f78;
  --accent-strong: #164f57;
  --danger: #b33a3a;
  --warn: #7d5a12;
  --soft: #eef7f6;
  --shadow: 0 16px 36px rgba(22, 32, 42, 0.08);
  font-family: "Yu Gothic", "Meiryo", "Hiragino Kaku Gothic ProN", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
.file-label {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

button:hover,
.file-label:hover {
  background: var(--accent-strong);
}

button.secondary,
.file-label.secondary {
  background: #e6ecef;
  color: var(--ink);
}

button.secondary:hover,
.file-label.secondary:hover {
  background: #d7e0e5;
}

button.danger {
  background: #f0dddd;
  color: var(--danger);
}

button.danger:hover {
  background: #e9c9c9;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 3px solid rgba(31, 111, 120, 0.18);
  border-color: var(--accent);
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin: 0;
}

legend {
  padding: 0 8px;
  color: var(--ink);
  font-weight: 700;
}

.app-header {
  min-height: 96px;
  padding: 22px min(4vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 4px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-actions input[type="file"] {
  display: none;
}

.app-shell {
  padding: 24px min(4vw, 40px) 48px;
}

.workspace {
  max-width: 1240px;
  margin: 0 auto;
}

.tabs {
  display: flex;
  gap: 4px;
  min-height: 46px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  color: var(--muted);
  border-radius: 7px 7px 0 0;
}

.tab:hover,
.tab.active {
  background: #fff;
  color: var(--ink);
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.panel-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

.tier-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.print-actions {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.print-status {
  margin: 0;
  max-width: 360px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
}

.terms-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(140px, 1fr) minmax(220px, 2fr) minmax(140px, 1fr);
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.terms-view {
  display: grid;
  gap: 18px;
}

.data-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.data-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.data-card h3 {
  margin: 3px 0 12px;
  font-size: 18px;
  letter-spacing: 0;
}

.wide-card {
  grid-column: 1 / -1;
}

.flow-list {
  margin: 0;
  padding-left: 22px;
  color: #25323c;
}

.flow-list li + li {
  margin-top: 8px;
}

.data-status {
  margin: 16px 0 0;
  color: var(--accent-strong);
  font-size: 13px;
}

.ai-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.prompt-box {
  width: 100%;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font: 13px/1.6 Consolas, "Yu Gothic", Meiryo, monospace;
  resize: vertical;
}

.page-block {
  break-before: page;
}

.terms-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.terms-title {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin-bottom: 14px;
}

.terms-title h3 {
  margin: 3px 0 0;
  font-size: 20px;
  letter-spacing: 0;
}

.terms-title strong {
  font-size: 14px;
}

.stage-pill {
  border: 1px solid #b7d1d1;
  background: #eef7f6;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  white-space: nowrap;
}

.chart-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  overflow-x: auto;
}

.chart-wrap svg {
  display: block;
  min-width: 720px;
  width: 100%;
  height: auto;
}

.chart-bg {
  fill: #ffffff;
}

.grid-line {
  stroke: #dfe6ec;
  stroke-width: 1;
}

.stage-line {
  stroke-dasharray: 5 5;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-line.sales {
  stroke: #49606f;
}

.chart-line.publisher {
  stroke: #a07235;
}

.chart-line.author {
  stroke: var(--accent);
}

.selected-line {
  stroke: #b33a3a;
  stroke-width: 2;
}

.author-dot {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
}

.chart-wrap text {
  fill: var(--muted);
  font-size: 12px;
}

.chart-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chart-legend i {
  width: 22px;
  height: 3px;
  display: inline-block;
  border-radius: 3px;
}

.legend-sales {
  background: #49606f;
}

.legend-publisher {
  background: #a07235;
}

.legend-author {
  background: var(--accent);
}

.book-list,
.history-list {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  background: #fbfcfd;
}

.list-item h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.list-item p {
  margin: 5px 0 0;
  color: var(--muted);
}

.report {
  margin-top: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.report:empty {
  display: none;
}

.report-page {
  padding: 28px;
}

.report-title {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.report-title h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.report-meta {
  text-align: right;
  font-size: 13px;
  color: var(--muted);
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
  letter-spacing: 0;
}

.report-section {
  margin-top: 20px;
}

.report-section h3 {
  margin: 0 0 8px;
  font-size: 16px;
  letter-spacing: 0;
}

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

th,
td {
  border: 1px solid var(--line);
  padding: 8px 9px;
  font-size: 13px;
  vertical-align: top;
}

th {
  background: #edf3f3;
  text-align: left;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.note {
  border-left: 4px solid var(--accent);
  background: var(--soft);
  padding: 12px 14px;
  margin-top: 14px;
  color: #25323c;
}

.warning {
  border-left-color: var(--warn);
  background: #fbf5e7;
}

.signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 24px;
}

.signature-box {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fbfcfd;
}

@media (max-width: 900px) {
  .app-header,
  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .print-actions {
    justify-items: start;
  }

  .print-status {
    text-align: left;
  }

  .form-grid,
  .form-grid.compact,
  .tier-grid,
  .terms-toolbar,
  .data-grid,
  .ai-grid,
  .summary-grid,
  .signature-grid {
    grid-template-columns: 1fr;
  }

  .data-actions {
    justify-content: flex-start;
  }

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

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

  body {
    background: #fff;
  }

  .app-header,
  .tabs,
  .panel-heading,
  form,
  .book-list,
  .history-list,
  .terms-toolbar {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .workspace {
    max-width: none;
  }

  .panel,
  .panel.active,
  .report {
    display: block;
    border: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }

  body[data-print-mode="settlement"] .panel:not(#settlementPanel),
  body[data-print-mode="terms"] .panel:not(#termsPanel) {
    display: none;
  }

  body:not([data-print-mode]) .panel:not(#settlementPanel) {
    display: none;
  }

  .terms-card {
    border: 0;
    padding: 0 0 12px;
    break-inside: avoid;
  }

  .chart-wrap {
    border: 0;
    padding: 0;
    overflow: visible;
  }

  .report-page {
    padding: 0;
  }

  .report-title h2 {
    font-size: 22px;
  }

  .metric {
    break-inside: avoid;
  }

  .page-block {
    page-break-before: always;
    break-before: page;
  }

  th,
  td {
    font-size: 10.5px;
    padding: 5px 6px;
  }
}
