:root {
  --bg: #f3f7f7;
  --surface: #ffffff;
  --surface-2: #e6f4f4;
  --ink: #1f3135;
  --muted: #5f7478;
  --line: #d4e3e3;
  --line-strong: #abc8c9;
  --green: #16828a;
  --green-2: #dff3f2;
  --teal: #0f7f88;
  --teal-light: #5dbbbd;
  --teal-soft: #e5f5f5;
  --amber: #9a641e;
  --amber-2: #fff1d8;
  --red: #a33a32;
  --red-2: #fae4e1;
  --blue: #2f6f9a;
  --shadow: 0 8px 22px rgba(37, 104, 108, 0.08);
  color: var(--ink);
  font-family:
    "Yu Gothic UI", "Meiryo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

.app {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #62bec0 0%, #4ba8aa 100%);
  color: #ffffff;
  padding: 20px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: grid;
  gap: 8px;
  min-height: 112px;
  margin-bottom: 12px;
}

.brand__mark {
  display: none;
}

.brand__name {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.brand__sub {
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  margin-top: 0;
}

.nav {
  display: grid;
  gap: 10px;
}

.nav__item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  text-align: center;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}

.nav__item:hover,
.nav__item.is-active {
  background: #0f7f88;
  border-color: #0f7f88;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 0 24px 32px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  gap: 16px;
}

.topbar__left,
.topbar__right,
.actions,
.toolbar,
.filters {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar__right {
  align-items: center;
  justify-content: flex-end;
}

.user {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.user__role {
  color: var(--green);
  background: var(--green-2);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.user__name {
  color: var(--ink);
  font-weight: 700;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.25;
}

h2 {
  font-size: 16px;
}

.page-title p {
  color: var(--muted);
  margin-top: 6px;
}

.button,
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  min-height: 36px;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
}

.button:hover,
.chip:hover {
  border-color: var(--teal);
}

.button--primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
  font-weight: 700;
}

.button--secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #edf4f8;
  font-weight: 700;
  text-decoration: none;
}

.button--import {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 126px;
  background: #0f7f88;
  border-color: #0f7f88;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.button--import:hover {
  background: #0c6870;
  border-color: #0c6870;
}

.button--ghost {
  background: transparent;
  color: var(--teal);
  border-color: transparent;
  padding: 0 8px;
}

.button--danger {
  color: var(--red);
  border-color: #ddb7b2;
}

.button--compact {
  min-height: 32px;
  padding: 0 10px;
}

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

.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.field {
  display: grid;
  gap: 6px;
}

.field--inline {
  grid-template-columns: auto minmax(180px, 220px);
  align-items: center;
  gap: 8px;
}

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

.field__hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input,
select {
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

input[type="file"] {
  display: flex;
  align-items: center;
  min-width: 298px;
  height: 36px;
  padding: 5px 8px;
}

input[type="file"]::file-selector-button {
  height: 26px;
  margin-right: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.textarea {
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  resize: vertical;
}

.textarea--csv {
  margin-top: 12px;
}

input:focus,
select:focus,
.textarea:focus {
  outline: 2px solid rgba(15, 127, 136, 0.22);
  border-color: var(--teal);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.master-summary {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.master-summary__item {
  background: #e9f7f7;
  border: 1px solid #c8e8e8;
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 76px;
  padding: 14px;
  display: grid;
  align-content: space-between;
}

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

.master-summary__item strong {
  font-size: 18px;
}

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

.metric {
  background: #e9f7f7;
  border-color: #c8e8e8;
  padding: 16px;
  min-height: 116px;
  display: grid;
  align-content: space-between;
}

.metric__label,
.metric__foot {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  color: #0f6169;
  font-size: 31px;
  line-height: 1.1;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.panel {
  padding: 16px;
  margin-bottom: 14px;
  min-width: 0;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel__head--inner {
  margin-top: 14px;
}

.panel__head--master-import {
  align-items: stretch;
  flex-direction: column;
}

.panel__head--master-import .actions--master-head {
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.toolbar--mapping {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.toolbar--file-import {
  display: grid;
  grid-template-columns: minmax(298px, 1.6fr) 116px 96px 94px 94px 104px 128px;
  align-items: start;
  gap: 10px;
}

.toolbar--file-import .button {
  align-self: start;
  margin-top: 23px;
  min-width: 100px;
  white-space: nowrap;
}

.toolbar--file-import .field {
  align-content: start;
}

.toolbar--file-import input,
.toolbar--file-import select {
  width: 100%;
}

.task-list {
  display: grid;
  gap: 8px;
}

.task {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 1px solid #c8e8e8;
  border-radius: 6px;
  padding: 8px 10px;
}

.task__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}

.task strong {
  display: block;
  font-size: 14px;
}

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

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

.workflow__step {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.workflow__step.is-done {
  background: var(--teal-soft);
  color: var(--teal);
}

.workflow__step.is-active {
  background: #cfecec;
  color: var(--teal);
  border-color: #9ed3d4;
}

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

.table--wide {
  min-width: 980px;
}

.table-scroll {
  overflow-x: auto;
}

.table--yayoi {
  min-width: 2460px;
}

.table--yayoi th,
.table--yayoi td {
  width: 96px;
}

.table--yayoi th:nth-child(1),
.table--yayoi td:nth-child(1),
.table--yayoi th:nth-child(9),
.table--yayoi td:nth-child(9),
.table--yayoi th:nth-child(10),
.table--yayoi td:nth-child(10),
.table--yayoi th:nth-child(15),
.table--yayoi td:nth-child(15),
.table--yayoi th:nth-child(16),
.table--yayoi td:nth-child(16),
.table--yayoi th:nth-child(20),
.table--yayoi td:nth-child(20),
.table--yayoi th:nth-child(23),
.table--yayoi td:nth-child(23),
.table--yayoi th:nth-child(24),
.table--yayoi td:nth-child(24) {
  width: 86px;
}

.table--yayoi th:nth-child(17),
.table--yayoi td:nth-child(17) {
  width: 180px;
}

.table--candidates {
  table-layout: auto;
}

.table--candidates th:nth-child(1),
.table--candidates td:nth-child(1) {
  width: 36px;
  min-width: 36px;
  text-align: center;
}

.table--candidates th:nth-child(2),
.table--candidates td:nth-child(2) {
  width: 96px;
  min-width: 96px;
}

.table--candidates th:nth-child(3),
.table--candidates td:nth-child(3) {
  width: 116px;
  min-width: 116px;
}

.table--candidates th:nth-child(5),
.table--candidates td:nth-child(5) {
  width: 112px;
  min-width: 112px;
}

.table--candidates th:nth-child(5) {
  text-align: center !important;
}

.table--candidates th:nth-child(8),
.table--candidates td:nth-child(8) {
  width: 100px;
  min-width: 100px;
}

.table--candidates th:nth-child(9),
.table--candidates td:nth-child(9) {
  width: 78px;
  min-width: 78px;
}

.table--rules {
  table-layout: auto;
  min-width: 1420px;
}

.table--rules th:nth-child(1),
.table--rules td:nth-child(1),
.table--rules th:nth-child(2),
.table--rules td:nth-child(2) {
  width: 70px;
  min-width: 70px;
}

.table--rules th:nth-child(3),
.table--rules td:nth-child(3) {
  width: 112px;
  min-width: 112px;
}

.table--rules th:nth-child(4),
.table--rules td:nth-child(4) {
  width: 78px;
  min-width: 78px;
}

.table--rules th:nth-child(5),
.table--rules td:nth-child(5),
.table--rules th:nth-child(6),
.table--rules td:nth-child(6) {
  width: 112px;
  min-width: 112px;
}

.table--rules th:nth-child(7),
.table--rules td:nth-child(7) {
  width: 210px;
  min-width: 210px;
}

.table--rules th:nth-child(8),
.table--rules td:nth-child(8),
.table--rules th:nth-child(9),
.table--rules td:nth-child(9),
.table--rules th:nth-child(10),
.table--rules td:nth-child(10) {
  width: 160px;
  min-width: 160px;
}

.table--rules th:nth-child(11),
.table--rules td:nth-child(11) {
  width: 150px;
  min-width: 150px;
}

.table--import-preview {
  table-layout: auto;
}

.table--import-preview th,
.table--import-preview td {
  text-align: left;
}

.table--import-preview th.num {
  text-align: center !important;
}

.table--import-preview th:nth-child(1),
.table--import-preview td:nth-child(1) {
  width: 82px;
  min-width: 82px;
}

.table--import-preview th:nth-child(2),
.table--import-preview td:nth-child(2) {
  width: 132px;
  min-width: 132px;
}

.table--import-preview th:nth-child(3),
.table--import-preview td:nth-child(3) {
  width: 116px;
  min-width: 116px;
}

.table--import-preview th:nth-child(4),
.table--import-preview td:nth-child(4) {
  width: clamp(260px, 38vw, 520px);
  max-width: 520px;
}

.table--import-preview th:nth-child(5),
.table--import-preview td:nth-child(5),
.table--import-preview th:nth-child(6),
.table--import-preview td:nth-child(6),
.table--import-preview th:nth-child(7),
.table--import-preview td:nth-child(7) {
  width: 117px;
  min-width: 117px;
}

.table--import-preview th:nth-child(8),
.table--import-preview td:nth-child(8) {
  width: 84px;
  min-width: 84px;
  text-align: center;
}

.table--bank-accounts {
  table-layout: fixed;
  min-width: 1200px;
}

.table--bank-accounts th:nth-child(1),
.table--bank-accounts td:nth-child(1) {
  width: 190px;
}

.table--bank-accounts th:nth-child(2),
.table--bank-accounts td:nth-child(2) {
  width: 150px;
}

.table--bank-accounts th:nth-child(3),
.table--bank-accounts td:nth-child(3) {
  width: 150px;
}

.table--bank-accounts th:nth-child(4),
.table--bank-accounts td:nth-child(4) {
  width: 96px;
}

.table--bank-accounts th:nth-child(5),
.table--bank-accounts td:nth-child(5) {
  width: 96px;
}

.table--bank-accounts th:nth-child(6),
.table--bank-accounts td:nth-child(6) {
  width: 128px;
}

.table--bank-accounts th:nth-child(7),
.table--bank-accounts td:nth-child(7) {
  width: 96px;
}

.table--bank-accounts th:nth-child(8),
.table--bank-accounts td:nth-child(8) {
  width: 112px;
}

.table--bank-accounts th:nth-child(9),
.table--bank-accounts td:nth-child(9) {
  width: 72px;
}

.table--bank-accounts th:nth-child(10),
.table--bank-accounts td:nth-child(10) {
  width: 152px;
}

.actions {
  gap: 8px;
}

.actions--master-head {
  align-items: center;
  justify-content: flex-end;
}

.table td.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f4fbfb;
}

.table tbody tr:hover {
  background: #f4fbfb;
}

.table--compact th,
.table--compact td {
  padding: 8px;
}

.num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.status,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status--matched,
.badge--success {
  background: var(--teal-soft);
  color: var(--teal);
}

.status--unmatched,
.badge--warning {
  background: var(--amber-2);
  color: var(--amber);
}

.status--duplicate,
.badge--duplicate {
  background: #eef3f3;
  color: var(--muted);
}

.status--approved {
  background: #e4edf8;
  color: var(--blue);
}

.status--exported {
  background: #eceae5;
  color: var(--muted);
}

.status--error {
  background: var(--red-2);
  color: var(--red);
}

tr.is-excluded {
  color: var(--muted);
  background: #f7fafa;
}

.chip {
  min-height: 32px;
  padding: 0 12px;
}

.chip.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.master-panel {
  display: none;
}

.master-panel.is-active {
  display: block;
}

.search {
  min-width: 260px;
}

.toggle {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  vertical-align: middle;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #0f6169;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 220px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(720px, calc(100vw - 32px));
  box-shadow: 0 20px 64px rgba(32, 37, 33, 0.24);
}

.dialog::backdrop {
  background: rgba(30, 36, 32, 0.38);
}

.dialog__body {
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 18px;
}

.dialog__head,
.dialog__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.candidate-summary {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px minmax(0, 1fr);
  gap: 8px 12px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9f7f7;
}

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

.candidate-summary strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.rule-section h3 {
  margin: 0;
  font-size: 14px;
}

.rule-section__head,
.conversion-line__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.conversion-lines {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

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

.conversion-line__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.is-hidden {
  display: none !important;
}

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

.master-form {
  display: none;
}

.master-form.is-active {
  display: grid;
}

.dialog__actions {
  justify-content: end;
  margin-top: 16px;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid,
  .master-summary,
  .split {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar--file-import {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .main {
    padding: 0 12px 24px;
  }

  .topbar,
  .page-title {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar__right,
  .topbar__right .button {
    width: 100%;
  }

  .metric-grid,
  .master-summary,
  .split,
  .workflow,
  .dialog__grid,
  .conversion-line__grid {
    grid-template-columns: 1fr;
  }

  .field--inline {
    grid-template-columns: 1fr;
  }

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

  .panel {
    overflow-x: auto;
  }

  .toolbar--file-import {
    grid-template-columns: 1fr;
  }

  .toolbar--file-import .button {
    margin-top: 0;
  }
}
