:root {
  color-scheme: light;
  --bg: #f4f8ff;
  --card: #ffffff;
  --ink: #14213d;
  --muted: #6c7892;
  --line: #dce5f3;
  --blue: #1769e0;
  --blue-hover: #0e5bc9;
  --blue-soft: #eaf2ff;
  --green: #15946c;
  --red: #d6415b;
  --content: 1120px;
  --shadow: 0 18px 45px rgba(40, 76, 130, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, #edf5ff, #f9fbff 35%, #f4f7fc);
  color: var(--ink);
  font: 15px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 68px;
  padding: 0 max(20px, calc((100% - var(--content)) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.brand b {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
}

.brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state {
  flex: 0 0 auto;
  margin-left: 16px;
  color: var(--muted);
  font-size: 13px;
}

.state.ready { color: var(--green); }
.state.error { color: var(--red); }

main {
  width: min(var(--content), calc(100% - 40px));
  margin: 0 auto;
  padding: 52px 0;
}

.hero {
  max-width: 880px;
}

.hero small {
  color: var(--blue);
  font-weight: 800;
  letter-spacing: 0.14em;
}

.hero h1 {
  max-width: 860px;
  margin: 12px 0;
  font-size: clamp(38px, 4.2vw, 58px);
  line-height: 1.08;
  letter-spacing: -0.05em;
  text-wrap: balance;
}

.hero p {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
}

.steps {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 34px 0 22px;
  overflow-x: auto;
  color: #a0aac0;
  font-size: 13px;
  scrollbar-width: thin;
  white-space: nowrap;
}

.steps span {
  flex: 0 0 auto;
}

.steps span.on {
  color: var(--blue);
  font-weight: 800;
}

.steps i {
  flex: 1 1 38px;
  min-width: 28px;
  height: 1px;
  background: var(--line);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  align-items: start;
  gap: 20px;
}

.grid > * {
  min-width: 0;
}

.card {
  min-width: 0;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}

h2 {
  margin: 0 0 22px;
  font-size: 21px;
}

h3 {
  margin: 0 0 16px;
}

label {
  display: block;
  margin: 0 0 16px;
  font-weight: 700;
}

input,
textarea,
select {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #fbfdff;
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 190px;
  resize: vertical;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.11);
}

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

button {
  min-height: 44px;
  padding: 12px 17px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  width: 100%;
  background: var(--blue);
  color: #fff;
}

.primary:hover:not(:disabled) {
  background: var(--blue-hover);
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.message {
  min-height: 23px;
  color: var(--muted);
}

.message.error,
.warning { color: var(--red); }
.message.success { color: var(--green); }
.hidden { display: none !important; }

.confirm {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.confirm dl,
.status dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  background: var(--line);
}

.confirm dl div,
.status dl div {
  min-width: 0;
  padding: 12px;
  background: #f8fbff;
}

dt {
  color: var(--muted);
  font-size: 12px;
}

dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.warning {
  padding: 10px;
  border-radius: 8px;
  background: #fff4f5;
  font-size: 13px;
}

.actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 8px;
}

.badge {
  float: right;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  font-size: 11px;
}

.badge.processing { color: #a06e00; }
.badge.success { color: var(--green); }
.badge.failed { color: var(--red); }

.bar {
  height: 7px;
  margin: 0 0 22px;
  overflow: hidden;
  border-radius: 10px;
  background: #e9eff8;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--blue);
  transition: width 0.3s;
}

.status > strong {
  font-size: 25px;
}

.status > p {
  min-height: 46px;
  color: var(--muted);
}

.status dl {
  margin-top: 18px;
}

.status dl input {
  margin: 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  font-size: 11px;
}

.status ol {
  margin: 18px 0 0;
  padding-left: 20px;
  color: var(--muted);
}

.status li {
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.status li b {
  display: block;
  color: var(--ink);
}

.status li span {
  font-size: 12px;
}

.restore {
  margin-top: 20px;
}

.restore button {
  margin-top: 2px;
}

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

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

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

pre {
  overflow: auto;
  padding: 14px;
  border-radius: 10px;
  background: #f8fbff;
}

footer {
  padding: 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.admin-body {
  background: #f2f6fb;
}

.admin-page {
  display: grid;
  width: min(1160px, calc(100% - 32px));
  min-height: 100vh;
  place-items: center;
  padding: 48px 0;
}

.admin-login-card {
  width: min(600px, 100%);
  padding: 50px;
  border: 1px solid #d7e1ee;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(28, 54, 88, 0.12);
}

.admin-kicker {
  color: #2a67ae;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
}

.admin-login-card h1 {
  margin: 12px 0 6px;
  font-size: 38px;
  line-height: 1.25;
}

.admin-login-copy {
  margin: 0 0 32px;
  color: var(--muted);
  font-size: 17px;
}

.admin-login-form label {
  margin-bottom: 8px;
}

.admin-field {
  margin-bottom: 24px;
}

.admin-login-form input {
  min-height: 64px;
  padding: 16px;
  background: #fff;
  font-size: 18px;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 70px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 10px;
  min-height: 38px;
  padding: 6px 10px;
  transform: translateY(-50%);
  background: transparent;
  color: var(--blue);
  font-size: 13px;
}

.password-toggle:hover:not(:disabled) {
  transform: translateY(-50%);
  background: var(--blue-soft);
}

.admin-login-button {
  min-height: 54px;
  margin-top: 6px;
  box-shadow: 0 10px 22px rgba(23, 105, 224, 0.2);
}

.admin-login-message {
  margin: 12px 0 0;
  text-align: center;
}

.admin-login-footer {
  margin: 46px 0 -8px;
  color: #91a0b8;
  text-align: center;
}

.admin-dashboard {
  width: 100%;
}

.admin-dashboard > .card {
  margin-top: 20px;
}

.admin-dashboard-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.admin-account {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}

@media (max-width: 900px) {
  main {
    width: min(100% - 32px, var(--content));
    padding-top: 34px;
  }

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

  .steps {
    padding-bottom: 6px;
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  header {
    min-height: 60px;
    padding-inline: 16px;
  }

  .state {
    font-size: 12px;
  }

  main {
    width: calc(100% - 24px);
    padding: 28px 0 36px;
  }

  .hero h1 {
    font-size: clamp(34px, 11vw, 46px);
  }

  .hero p {
    font-size: 15px;
  }

  .card {
    padding: 20px;
    border-radius: 14px;
  }

  .confirm dl,
  .status dl,
  .actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-page {
    width: calc(100% - 24px);
    padding: 24px 0;
  }

  .admin-login-card {
    padding: 30px 22px;
  }

  .admin-login-card h1 {
    font-size: 32px;
  }

  .admin-dashboard-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

/* Operations console */
.admin-body {
  color-scheme: dark;
  background: #101a2d;
  color: #f4f7ff;
}

.admin-body .admin-page {
  width: min(1540px, calc(100% - 48px));
  align-content: center;
}

.admin-body .admin-login-card {
  color-scheme: light;
  color: var(--ink);
}

.admin-body .admin-dashboard {
  color-scheme: dark;
}

.admin-title h1 {
  margin: 8px 0 4px;
  color: #fff;
  font-size: clamp(32px, 4vw, 48px);
  letter-spacing: -0.04em;
}

.admin-title p {
  margin: 0;
  color: #9dafcf;
}

.admin-body .admin-account {
  color: #dce6fb;
}

.admin-body .secondary {
  border-color: #2a3c59;
  background: #16233a;
  color: #eef4ff;
}

.admin-body .secondary:hover:not(:disabled) {
  background: #1d2c47;
}

.admin-flash {
  position: sticky;
  top: 10px;
  z-index: 20;
  min-height: 34px;
  margin: 14px 0;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(16, 26, 45, 0.92);
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.admin-stats article {
  min-height: 134px;
  padding: 25px 24px;
  border: 1px solid #273955;
  border-radius: 18px;
  background: #111c2f;
}

.admin-stats span {
  display: block;
  color: #a9bad8;
}

.admin-stats strong {
  display: block;
  margin-top: 10px;
  color: #fff;
  font-size: 42px;
  line-height: 1;
}

.admin-two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 22px;
}

.admin-body .admin-panel {
  border-color: #273955;
  background: #101b2d;
  box-shadow: none;
}

.full-panel {
  margin-top: 22px;
}

.admin-panel h2 {
  margin: 4px 0 22px;
  color: #fff;
  font-size: 29px;
}

.section-label {
  color: #50f3c2;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

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

.panel-heading h2 {
  margin-bottom: 18px;
}

.panel-heading.wrap {
  flex-wrap: wrap;
}

.panel-divider {
  height: 1px;
  margin: 22px 0;
  background: #293a55;
}

.admin-body input,
.admin-body textarea,
.admin-body select {
  border-color: #2a3d5c;
  background: #17243a;
  color: #f5f8ff;
}

.admin-body input::placeholder,
.admin-body textarea::placeholder {
  color: #7586a4;
}

.admin-body input:focus,
.admin-body textarea:focus,
.admin-body select:focus {
  border-color: #6977ff;
  box-shadow: 0 0 0 3px rgba(105, 119, 255, 0.18);
}

.admin-body input[type="checkbox"] {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin: 0;
  vertical-align: middle;
  accent-color: #6874ff;
}

.admin-form-row {
  display: grid;
  gap: 10px;
}

.issue-row {
  grid-template-columns: minmax(160px, 1fr) 112px 140px;
}

.admin-form-row label,
.issue-row label {
  margin: 0;
}

.admin-form-row input,
.admin-form-row select,
.issue-row input,
.issue-row select {
  min-height: 58px;
  margin: 0;
}

.issue-row button {
  min-height: 58px;
}

.code-output {
  min-height: 190px;
  margin-top: 14px;
}

.compact {
  width: auto;
  min-height: 42px;
  padding: 9px 14px;
}

.provider-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.provider-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 58px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #152238;
}

.provider-list dt {
  color: #fff;
  font-size: 16px;
}

.provider-list dd {
  color: #50f3c2;
}

.provider-list .balance-cell {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 2px;
}

.provider-list .balance-cell strong {
  font-size: 18px;
}

.provider-list .balance-cell small {
  color: #8396b7;
  font-size: 11px;
  font-weight: 500;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 5px 10px;
  border: 1px solid #40516e;
  border-radius: 999px;
  color: #c7d4eb;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.status-pill.success {
  border-color: #208568;
  color: #50f3c2;
}

.status-pill.error {
  border-color: #8f3950;
  color: #ff708b;
}

.status-pill.processing {
  border-color: #6a5d37;
  color: #f3c760;
}

.routing-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.routing-form label {
  margin: 0;
  color: #b8c7e1;
  font-size: 13px;
}

.routing-form .switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 45px;
}

.routing-form button {
  grid-column: 1 / -1;
}

.manual-form {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 14px;
}

.manual-form label {
  margin: 0;
}

.manual-form .full {
  grid-column: 1 / -1;
}

.manual-form textarea {
  min-height: 132px;
}

.manual-form button {
  width: 300px;
}

.form-result {
  align-self: center;
  margin: 0;
}

.form-result.processing {
  color: #f3c760;
}

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

.danger {
  border: 1px solid #743148;
  background: #3a1e2a;
  color: #ff8499;
}

.danger:hover:not(:disabled) {
  background: #512638;
}

.plan-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 2px 0 20px;
}

.plan-stats article {
  padding: 18px;
  border: 1px solid #2b3d5a;
  border-radius: 13px;
  background: #142137;
}

.plan-stats span,
.plan-stats small {
  display: block;
  color: #a8b9d6;
}

.plan-stats strong {
  display: block;
  margin: 5px 0 2px;
  color: #50f3c2;
  font-size: 25px;
}

.filter-row {
  display: grid;
  grid-template-columns: 220px 220px minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
}

.filter-row label {
  margin: 0;
  color: #b8c7e1;
  font-size: 13px;
}

.table-count {
  align-self: center;
  color: #a8b9d6;
  white-space: nowrap;
}

.admin-table {
  min-width: 1080px;
}

.admin-table th,
.admin-table td {
  padding: 14px 12px;
  border-color: #293b58;
}

.admin-table th {
  color: #91a7cc;
  font-size: 12px;
  font-weight: 800;
}

.admin-table td {
  color: #edf3ff;
}

.admin-table tbody tr:hover {
  background: #142239;
}

.admin-table code {
  color: #e3ebff;
  font: 12px/1.4 ui-monospace, Consolas, monospace;
}

.inline-import {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 10px;
  width: min(640px, 100%);
}

.inline-import input,
.inline-import textarea {
  min-height: 44px;
  margin: 0;
}

.inline-import textarea {
  min-height: 66px;
}

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

@media (max-width: 1050px) {
  .admin-two-column,
  .admin-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .admin-body .admin-page {
    width: calc(100% - 20px);
  }

  .admin-two-column,
  .admin-stats,
  .plan-stats,
  .filter-row,
  .manual-form,
  .routing-form,
  .issue-row,
  .inline-import {
    grid-template-columns: minmax(0, 1fr);
  }

  .manual-form .full,
  .routing-form button {
    grid-column: auto;
  }

  .manual-form button,
  .inline-import {
    width: 100%;
  }

  .panel-heading {
    flex-direction: column;
  }
}
