:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-soft: #f2f6f4;
  --text: #202527;
  --muted: #667277;
  --line: #d9e0e2;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #dff3ef;
  --blue: #2563eb;
  --warn: #b45309;
  --warn-soft: #fff4db;
  --danger: #b91c1c;
  --shadow: 0 16px 40px rgba(24, 31, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Noto Sans CJK JP",
    "Noto Sans JP",
    "Yu Gothic UI",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
}

body.locked {
  overflow: hidden;
}

body.locked .app-header,
body.locked .app-shell {
  filter: blur(9px);
  pointer-events: none;
  user-select: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-header h1 {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1.15;
}

.eyebrow,
.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.app-shell {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

.summary-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.control-grid {
  display: grid;
  grid-template-columns: 170px 140px 140px minmax(220px, 1fr) 130px;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
}

input:focus,
select:focus,
button:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  outline-offset: 1px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
}

.kpi {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 14px;
  background: var(--panel-soft);
  border: 1px solid #dbe9e5;
  border-radius: 8px;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi strong {
  font-size: 22px;
  line-height: 1.1;
}

.table-panel {
  overflow: hidden;
}

.import-panel {
  padding: 14px;
}

.drop-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 92px;
  padding: 16px;
  background: #f7faf9;
  border: 1px dashed #9fb7b3;
  border-radius: 8px;
}

.drop-zone.dragging {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.drop-zone strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.drop-zone span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.import-status {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.table-header h2,
.detail-heading h2 {
  margin: 2px 0 0;
  font-size: 20px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: 1px;
}

.dot.ok {
  background: var(--accent);
}

.dot.warn {
  background: var(--warn);
}

.table-wrap {
  max-height: calc(100vh - 380px);
  min-height: 420px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f4;
  color: #3f4a4e;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

.sort-button,
.link-button,
.help-button,
.page-button {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
  padding: 0;
}

.sort-button {
  min-height: 22px;
}

.sort-button.active::after {
  content: attr(data-sort-marker);
  margin-left: 4px;
  color: var(--accent);
}

.link-button {
  color: var(--text);
  text-align: left;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-button:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.help-button {
  width: 24px;
  height: 24px;
  margin-left: 4px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  color: var(--accent-strong);
  text-align: center;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.pagination-bar:last-child {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-button {
  min-width: 34px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.page-button.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.page-button:disabled {
  opacity: 0.45;
  cursor: default;
}

tbody td {
  border-bottom: 1px solid #edf1f2;
  padding: 10px;
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr {
  background: #ffffff;
}

tbody tr:hover,
tbody tr.selected {
  background: var(--accent-soft);
}

td strong {
  display: block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-left: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.status.ok {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.empty-state {
  margin-top: 18px;
  min-height: 140px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #f7f9f9;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.detail-body {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.hidden {
  display: none !important;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.detail-stats div {
  display: grid;
  gap: 6px;
  min-height: 70px;
  align-content: center;
  padding: 10px;
  background: #f7faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-stats span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.detail-stats strong {
  font-size: 14px;
  line-height: 1.25;
}

.stacked-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fafbfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
  padding: 0 12px;
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.text-button {
  min-height: 30px;
  background: transparent;
  color: var(--danger);
  padding: 0;
}

.records {
  display: grid;
  gap: 8px;
}

.records-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.records ul {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  max-height: 190px;
  overflow: auto;
}

.records li {
  display: grid;
  grid-template-columns: 88px 54px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}

.records li small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.records .record-empty {
  display: block;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 36px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.22);
}

.modal::backdrop {
  background: rgba(24, 31, 35, 0.42);
}

.modal-shell {
  display: grid;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-header h2 {
  margin: 2px 0 0;
  font-size: 22px;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 1fr;
  gap: 14px;
  padding: 16px;
}

.help-modal {
  width: min(720px, calc(100vw - 32px));
}

.help-body {
  display: grid;
  gap: 10px;
  color: #344044;
  line-height: 1.75;
}

.help-body a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

.preview-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(rgba(246, 247, 248, 0.52), rgba(246, 247, 248, 0.78)),
    rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(12px) saturate(1.05);
}

.preview-gate.hidden {
  display: none;
}

.preview-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(217, 224, 226, 0.9);
  border-radius: 8px;
  box-shadow: 0 28px 90px rgba(18, 33, 39, 0.24);
}

.preview-card h2 {
  margin: 0;
  font-size: 25px;
  line-height: 1.25;
}

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

.preview-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1120px) {
  .control-grid,
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-wrap {
    max-height: none;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .app-shell {
    padding: 10px;
  }

  .control-grid,
  .kpi-grid,
  .detail-stats {
    grid-template-columns: 1fr;
  }

  .table-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .legend {
    flex-wrap: wrap;
  }

  .drop-zone,
  .pagination-bar,
  .modal-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
