:root {
  --brand: #1d3f8f;
  --brand-dark: #142d68;
  --brand-soft: #e8eefb;
  --ok: #138a4b;
  --ok-soft: #e6f6ed;
  --warn: #a15c00;
  --warn-soft: #fff4e0;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --text: #1b2333;
  --muted: #5d6779;
  --line: #dfe4ee;
  --bg: #f4f6fb;
  --card: #ffffff;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 460px; margin: 0 auto; padding: 20px 16px 40px; }
.wrap.wide { max-width: 1040px; }

.brand { display: flex; align-items: center; gap: 10px; margin: 4px 0 18px; }
.brand img { width: 36px; height: 36px; }
.brand .name { font-weight: 700; font-size: 1.25rem; color: var(--brand); letter-spacing: -0.01em; }
.brand .sub { font-size: .8rem; color: var(--muted); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  padding: 20px;
  margin-bottom: 16px;
}

h1 { font-size: 1.35rem; margin: 0 0 6px; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .92rem; }
.small { font-size: .82rem; }
.center { text-align: center; }
.hidden { display: none !important; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 6px; }
input, select {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.phone-row { display: flex; gap: 8px; }
.phone-row select { width: 112px; flex: 0 0 112px; }
.phone-row input { flex: 1 1 auto; width: auto; min-width: 0; }
html, body { overflow-x: hidden; }

.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  margin-top: 12px;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; text-decoration: underline; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.inline { width: auto; margin-top: 0; padding: 8px 12px; font-size: .85rem; }

.tabs { display: flex; background: var(--brand-soft); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tab {
  flex: 1;
  font: inherit;
  font-weight: 600;
  border: 0;
  background: transparent;
  color: var(--brand);
  padding: 10px 8px;
  border-radius: 9px;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: #fff; box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }

.code-box {
  margin: 16px 0 6px;
  padding: 18px 10px;
  border: 2px dashed var(--brand);
  border-radius: 14px;
  background: var(--brand-soft);
  text-align: center;
}
.code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--brand-dark);
  user-select: all;
}
.flash { color: var(--ok); font-weight: 600; font-size: .85rem; min-height: 1.2em; }

ol.steps { padding-left: 0; margin: 16px 0 0; list-style: none; counter-reset: s; }
ol.steps li { counter-increment: s; position: relative; padding: 0 0 12px 40px; }
ol.steps li::before {
  content: counter(s);
  position: absolute; left: 0; top: -1px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 700; font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
}

.qr { display: flex; justify-content: center; margin: 8px 0; min-height: 264px; align-items: center; }
.qr img { width: 264px; height: 264px; image-rendering: pixelated; border-radius: 8px; background: #fff; }

.waiting { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: .9rem; margin-top: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.spinner {
  width: 34px; height: 34px; margin: 24px auto;
  border: 3px solid var(--brand-soft); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.success { background: var(--ok-soft); border: 1.5px solid #a7dfbf; text-align: center; }
.success .check {
  width: 64px; height: 64px; margin: 4px auto 12px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 2rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.success h1 { color: var(--ok); }
.success .number { font-size: 1.15rem; font-weight: 700; margin: 6px 0 14px; }

.alert { padding: 12px 14px; border-radius: 12px; font-size: .9rem; margin: 12px 0 0; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); }

footer { text-align: center; color: var(--muted); font-size: .78rem; margin-top: 24px; }

/* ---------------- admin ---------------- */
.grid { display: grid; gap: 12px; }
@media (min-width: 720px) { .grid.cols-3 { grid-template-columns: 1fr 1fr 1fr auto; align-items: end; } }
.list { display: grid; gap: 10px; }
.item {
  display: grid; gap: 8px;
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff;
}
@media (min-width: 720px) { .item { grid-template-columns: 1.4fr 1fr 1fr auto; align-items: center; } }
.item .title { font-weight: 700; }
.item .meta { color: var(--muted); font-size: .82rem; word-break: break-all; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.pill.connected { background: var(--ok-soft); color: var(--ok); }
.pill.waiting { background: var(--warn-soft); color: var(--warn); }
.pill.disconnected { background: var(--bad-soft); color: var(--bad); }
.pill.revoked { background: #eceff3; color: var(--muted); }
.health { display: flex; gap: 12px; font-size: .82rem; color: var(--muted); flex-wrap: wrap; }
.health span::before { content: "●"; margin-right: 4px; color: var(--bad); }
.health span.ok::before { color: var(--ok); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.newlink { word-break: break-all; font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.narrow { max-width: 440px; }
.mt8 { margin-top: 8px; }
