:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687385;
  --line: #d6dde6;
  --accent: #0f6b5f;
  --accent-2: #214e8a;
  --danger: #b42318;
  --soft: #e7f4f1;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0 0 14px; font-size: 18px; }
p { margin: 6px 0 0; color: var(--muted); }

input, select, textarea, button, a {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}
button, .toolbar a {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger {
  color: var(--danger);
  border-color: #f1b8b2;
  background: #fff7f6;
}
.auth-badge {
  align-self: center;
  border-color: #c8d1dd;
  background: #f8fafc;
  color: var(--muted);
}
.auth-badge.connected {
  border-color: #9bd0c8;
  background: var(--soft);
  color: var(--accent);
}

.tabs {
  position: relative;
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding: 10px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.tabs::after {
  content: "";
  position: sticky;
  right: 0;
  flex: 0 0 22px;
  pointer-events: none;
  background: linear-gradient(90deg, rgb(255 255 255 / 0), #fff 70%);
}
.tab.active { background: var(--soft); color: var(--accent); border-color: #9bd0c8; }

main { max-width: 1180px; margin: 0 auto; padding: 20px; }
.view { display: none; }
.view.active { display: block; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 24px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.list { display: grid; gap: 8px; }
.item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #edf0f4;
  padding: 8px 0;
}
.item:last-child { border-bottom: 0; }
.muted { color: var(--muted); font-size: 13px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.wide { grid-column: 1 / -1; }
.transfer-only { display: none; }
.is-transfer .transfer-only { display: grid; }
.is-transfer .normal-account { display: none; }
.actions { display: flex; gap: 8px; }
.advanced {
  border: 1px solid #e5eaf0;
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfd;
}
.advanced summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 700;
}
.nested {
  margin-top: 12px;
}
.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkline input {
  width: auto;
}
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar h2 { margin-right: auto; margin-bottom: 0; }
.toolbar-check {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  white-space: nowrap;
}
.toolbar-check input {
  width: auto;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 10px; border-bottom: 1px solid #edf0f4; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
.deleted-row {
  color: var(--muted);
  background: #f8fafc;
}
.deleted-row td:not(:last-child) {
  text-decoration: line-through;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
  text-decoration: none;
}
.status-badge.deleted {
  color: #5b6472;
  background: #e9edf2;
}
.status-badge.duplicate {
  color: #7a4f00;
  background: #fff3cd;
}
.status-badge.error {
  color: var(--danger);
  background: #fff7f6;
  border: 1px solid #f1b8b2;
}
.inline-input {
  min-width: 110px;
  padding: 7px 8px;
}
.row-actions {
  min-width: 180px;
}
.row-actions, .table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.table-actions {
  justify-content: center;
  margin-top: 12px;
}
.compact {
  margin-top: 12px;
}
.compact .item {
  align-items: center;
}
.item button {
  padding: 7px 10px;
}
.stack { display: grid; gap: 10px; margin-bottom: 16px; }
.notice {
  color: var(--accent-2);
  background: #edf4ff;
  border: 1px solid #b9d0f5;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 14px;
}
#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  display: none;
  z-index: 10;
}
.auth-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgb(15 23 42 / 0.22);
}
.wide-dialog {
  width: min(980px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgb(15 23 42 / 0.22);
}
.wide-dialog::backdrop {
  background: rgb(15 23 42 / 0.34);
}
.wide-dialog form {
  display: grid;
  gap: 12px;
  padding: 20px;
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.dialog-head h2 {
  margin: 0;
}
.import-check {
  align-self: end;
  min-height: 42px;
}
.import-preview-wrap {
  max-height: 380px;
  border: 1px solid #edf0f4;
  border-radius: 6px;
}
.import-preview-wrap table {
  min-width: 820px;
}
.auth-dialog::backdrop {
  background: rgb(15 23 42 / 0.34);
}
.auth-dialog form {
  display: grid;
  gap: 12px;
  padding: 20px;
}
.form-error {
  color: var(--danger);
  background: #fff7f6;
  border: 1px solid #f1b8b2;
  border-radius: 6px;
  padding: 9px 10px;
}

@media (max-width: 760px) {
  .topbar { display: grid; padding: 14px; }
  .auth-badge { justify-self: start; }
  main { padding: 12px; }
  .summary-grid, .two-col, .form-grid { grid-template-columns: 1fr; }
  .tabs { padding: 8px 12px; }
  .tab { padding: 9px 10px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar h2 { width: 100%; }
  .toolbar-check { width: 100%; }
  .metric strong { font-size: 21px; }
  th, td { padding: 8px; }
  .inline-input { min-width: 96px; }
  .row-actions { min-width: 140px; }
}
