:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --line: #d9e0e3;
  --text: #1f2a30;
  --muted: #5e6a71;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --warning: #a15c05;
  --danger: #b42318;
  --blue: #2f5f98;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 20px 28px 16px;
}

.header-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: center;
}

.portal-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  border-radius: 6px;
  background: #eef7f6;
  padding: 8px 10px;
}

.portal-controls select {
  width: clamp(220px, 24vw, 320px);
  min-height: 34px;
  border-color: transparent;
  background: #fff;
  color: #12423d;
  font-weight: 700;
}

.actor-name {
  color: #12423d;
  font-weight: 700;
  white-space: nowrap;
}

.permission-badge {
  border-radius: 999px;
  background: #dff7e8;
  color: #0b5f35;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 7px 10px;
  white-space: nowrap;
}

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

.app-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 28px;
}

.tab-button {
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

.tab-button:hover {
  background: #eef3f4;
  color: var(--text);
}

.tab-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

main {
  display: grid;
  gap: 18px;
  padding: 20px 28px 32px;
}

.band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px;
}

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

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.button,
input::file-selector-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 5px;
  padding: 9px 13px;
  font: inherit;
  cursor: pointer;
}

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

.button.secondary {
  background: #fff;
  color: var(--accent);
}

.button.mini {
  padding: 5px 8px;
  font-size: 12px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.file-name {
  color: var(--muted);
}

.status {
  margin-top: 12px;
  color: var(--muted);
}

.status[data-kind="success"] {
  color: var(--accent-strong);
}

.status[data-kind="warn"] {
  color: var(--warning);
}

.status[data-kind="error"] {
  color: var(--danger);
}

h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

h3 {
  margin: 14px 0 8px;
  font-size: 14px;
  color: var(--blue);
}

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.mapping-section {
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-width: 0;
  padding-top: 10px;
}

.mapping-section-wide {
  grid-column: 1 / -1;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.mapping-section h3 {
  grid-column: 1 / -1;
  margin-top: 0;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.85fr) minmax(140px, 1.15fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.field-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

select,
input[type="text"],
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px;
  font: inherit;
  background: #fff;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  border-left: 4px solid var(--accent);
  background: #f8fbfa;
  padding: 8px 10px;
}

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

.metric strong {
  display: block;
  font-size: 18px;
  letter-spacing: 0;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

.account-settings table {
  min-width: 1180px;
}

.account-settings input {
  min-width: 120px;
}

.match-amount-input {
  width: 110px;
  min-width: 110px;
  text-align: right;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #eef3f4;
  color: #314148;
  font-size: 12px;
}

.is-muted {
  color: var(--muted);
  background: #f8fafb;
}

.warnings {
  margin: 0;
  padding-left: 18px;
}

.warnings li {
  margin: 6px 0;
}

.validation-panel {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

textarea {
  min-height: 130px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.journal-controls {
  display: grid;
  grid-template-columns: minmax(180px, 260px);
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.approval-grid {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(260px, 1fr);
  gap: 14px;
  align-items: start;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

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

.approval-reason {
  grid-column: 1 / -1;
}

.match-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin: 14px 0;
}

.report-toolbar {
  margin: 8px 0 12px;
}

.surcharge-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.surcharge-note {
  grid-column: span 2;
}

@media (max-width: 840px) {
  header,
  .app-tabs,
  main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .split-layout,
  .journal-controls,
  .approval-grid,
  .match-actions {
    grid-template-columns: 1fr;
  }

  .header-layout {
    grid-template-columns: 1fr;
  }

  .portal-controls {
    justify-content: flex-start;
  }

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

  .mapping-grid,
  .mapping-section-wide {
    grid-template-columns: 1fr;
  }

  .surcharge-note {
    grid-column: auto;
  }
}
