:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d8dee9;
  --text: #172033;
  --muted: #687386;
  --blue: #2563eb;
  --green: #15803d;
  --red: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.logged-out {
  display: block;
}

body.logged-out .sidebar,
body.logged-out .shell,
body.logged-in #loginPanel {
  display: none;
}

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-help {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  background: #f8fafc;
}

.sidebar {
  background: #111827;
  color: #e5e7eb;
  padding: 18px 12px;
  min-height: 100vh;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 6px 10px 18px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #9ca3af;
  font-size: 12px;
}

.nav {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 2px 0;
  text-align: left;
  color: #d1d5db;
  background: transparent;
  cursor: pointer;
}

.nav.active,
.nav:hover {
  background: #1f2937;
  color: #ffffff;
}

.shell {
  min-width: 0;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 14px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
  margin-bottom: 12px;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
}

.scope,
.form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.account-card {
  display: grid;
  gap: 2px;
  min-width: 150px;
}

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

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

input,
select,
button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

button {
  cursor: pointer;
}

.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  font-weight: 600;
}

.small {
  min-height: 30px;
  padding: 4px 8px;
}

.danger {
  border-color: var(--red);
  background: #ffffff;
  color: var(--red);
}

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

.message {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e40af;
  border-radius: 6px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
}

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

.stat {
  padding: 14px;
}

.stat strong {
  display: block;
  font-size: 26px;
}

.stat span {
  color: var(--muted);
}

.revenue-panel {
  grid-column: 1 / -1;
}

.panel {
  padding: 14px;
  overflow: auto;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: #f8fafc;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
}

.tag.green {
  background: #dcfce7;
  color: var(--green);
}

.tag.red {
  background: #fee2e2;
  color: var(--red);
}

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

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

.config-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.config-row span {
  color: var(--muted);
}

.config-row code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.steps {
  counter-reset: step;
  display: grid;
  gap: 8px;
}

.step {
  counter-increment: step;
  display: flex;
  gap: 10px;
  align-items: center;
}

.step::before {
  content: counter(step);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--blue);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.mapping {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

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

.mapping strong,
.mapping span {
  display: block;
}

.mapping span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.modal-card .panel-head,
.modal-card button[type="submit"] {
  grid-column: 1 / -1;
}

@media (max-width: 880px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    display: flex;
    gap: 6px;
    overflow-x: auto;
  }

  .brand {
    min-width: 140px;
    padding-bottom: 6px;
  }

  .nav {
    width: auto;
    min-width: 72px;
    text-align: center;
  }

  .topbar {
    display: grid;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .config-row,
  .mapping,
  .modal-card {
    grid-template-columns: 1fr;
  }
}
