:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --line: #d9e0e8;
  --brand: #1264a3;
  --brand-dark: #0b4f82;
  --ok: #16794c;
  --warn: #b7791f;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, .button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
}
button:hover, .button:hover { background: var(--brand-dark); }
button:disabled, .button[aria-disabled="true"] {
  cursor: wait;
  opacity: 0.68;
}
.ghost { background: #eef4fa; color: var(--brand); }
.danger { background: var(--danger); }
.full { width: 100%; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 22px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--brand); color: white; display: grid; place-items: center; font-weight: 800;
}
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.nav { display: grid; gap: 6px; margin-bottom: 20px; }
.nav a { padding: 11px 12px; border-radius: 6px; color: #344054; }
.nav a.active, .nav a:hover { background: #e8f2fb; color: var(--brand); }
.content { padding: 22px; min-width: 0; }
.page-header h1 { margin: 0 0 18px; font-size: 26px; letter-spacing: 0; }

.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.compact { gap: 10px; margin-bottom: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 18px; }
.error-text { color: var(--danger); }
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 14px;
  font-weight: 600;
}
.notice.ok {
  border-color: #b7e4ca;
  background: #ecfdf3;
  color: var(--ok);
}
.notice.error {
  border-color: #f4b8b2;
  background: #fff1f0;
  color: var(--danger);
}

.stack-form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: #344054; font-size: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
.template-textarea { min-height: 170px; font-family: Consolas, "Courier New", monospace; }
.template-help { margin: -4px 0 0; font-size: 13px; }
.template-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 6px;
}
.template-legend div {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}
.template-legend code {
  font: 600 12px/1.4 Consolas, "Courier New", monospace;
  color: var(--brand);
}
.template-legend span {
  color: var(--muted);
  font-size: 13px;
}
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar.between { justify-content: space-between; align-items: center; }
.toolbar label { min-width: 150px; }
.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input { max-width: 96px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.slim-panel { padding-top: 14px; }
.slim-panel h2 { margin-bottom: 4px; }
.subline { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.settings-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}
.region-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.region-summary div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #f8fafc;
}
.region-summary strong {
  display: block;
  font-size: 15px;
  word-break: break-word;
}
.region-summary span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.region-added {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.region-chip-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.region-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #ffffff;
  font-size: 13px;
}
.region-chip code {
  color: var(--muted);
  font: 600 12px/1.2 Consolas, "Courier New", monospace;
}
.action-popover { position: relative; }
.action-popover > summary { list-style: none; }
.action-popover > summary::-webkit-details-marker { display: none; }
.compact-form {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 8px);
  width: min(360px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
}
.badge-button {
  border-radius: 999px;
  min-height: auto;
  padding: 4px 8px;
  font-size: 12px;
  background: #f2f4f7;
  color: #344054;
}
.badge-button.warn { background: #fff6df; color: var(--warn); }

.responsive-table { width: 100%; border-collapse: collapse; }
.responsive-table th, .responsive-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
.responsive-table th { color: var(--muted); font-size: 13px; font-weight: 700; }
.responsive-table tr.active { background: #edf7ff; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #f2f4f7; color: #344054; font-size: 12px; }
.badge.ok { background: #e7f7ef; color: var(--ok); }
.badge.warn { background: #fff6df; color: var(--warn); }

.pill-list { display: grid; gap: 8px; }
.customer-summary { margin-bottom: 14px; }
.pill {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px;
}
.pill.active { border-color: var(--brand); background: #edf7ff; }
.pill span { color: var(--muted); font-size: 13px; }
.bind-pill span { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.bind-pill button { min-height: 30px; padding: 5px 9px; }

.subscription-table th:last-child,
.subscription-table td:last-child { width: 34%; }
.endpoint { font-family: Consolas, "Courier New", monospace; font-size: 13px; word-break: break-all; }
.copy-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.copy-actions button { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.protocol-copy { background: #eef4fa; color: var(--brand); }
.protocol-copy:hover { background: #dcecf8; }
.empty-inline { color: var(--muted); font-size: 13px; }
.steps { margin: 0; padding-left: 20px; line-height: 1.9; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: min(820px, 100%);
  max-height: min(720px, 86vh);
  overflow: hidden;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; align-items: center; }
.modal-card pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #101828;
  color: #f9fafb;
  font: 13px/1.5 Consolas, "Courier New", monospace;
}
.qr-modal-card { width: min(520px, 100%); }
.qr-modal-body {
  padding: 16px;
  display: grid;
  gap: 12px;
  overflow: auto;
}
.qr-box {
  min-height: 260px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}
.qr-box svg {
  width: min(280px, 72vw);
  height: auto;
  display: block;
}
.subscription-link-text {
  min-height: 110px;
  font: 12px/1.5 Consolas, "Courier New", monospace;
  word-break: break-all;
}
.progress-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.38);
}
.progress-backdrop[hidden] { display: none; }
.progress-card {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
  display: grid;
  gap: 12px;
}
.progress-card strong { font-size: 17px; }
.progress-card p { margin: 0; font-size: 13px; }
.progress-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}
.progress-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #2f855a);
  animation: progress-slide 1s ease-in-out infinite;
}

@keyframes progress-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(250%); }
}

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 24px; }
.auth-card h1 { margin-top: 0; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; padding-bottom: 72px; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }
  .brand { margin-bottom: 10px; }
  .nav {
    position: fixed;
    z-index: 10;
    left: 0; right: 0; bottom: 0;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
    background: white;
    border-top: 1px solid var(--line);
    margin: 0;
  }
  .nav a { border-radius: 0; text-align: center; padding: 12px 4px; font-size: 12px; }
  .sidebar form { display: none; }
  .content { padding: 14px; }
  .grid.two { grid-template-columns: 1fr; }

  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
  .responsive-table tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 10px;
    background: white;
  }
  .responsive-table td {
    border: 0;
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    padding: 7px 4px;
    word-break: break-word;
  }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }
  .actions, .inline-form, .toolbar { align-items: stretch; }
  .actions form, .actions button, .actions .button, .toolbar button { width: 100%; }
  .copy-actions { align-items: stretch; }
  .copy-actions button { flex: 1 1 96px; }
  .action-popover { width: 100%; }
  .action-popover > summary { width: 100%; }
  .compact-form {
    position: static;
    width: 100%;
    margin-top: 8px;
    box-shadow: none;
  }
}
