:root {
  color-scheme: dark;
  --bg: #08090a;
  --panel: #0f1012;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.055);
  --text: #f7f8f8;
  --text-secondary: #c5c9d1;
  --muted: #858b96;
  --accent: #7170ff;
  --accent-strong: #5e6ad2;
  --accent-hover: #8584ff;
  --success: #35c98a;
  --danger: #ef6b73;
  --warning: #e8b968;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv01", "ss03";
}

* { box-sizing: border-box; }
.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; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 45% -20%, rgba(113, 112, 255, 0.16), transparent 38rem),
    linear-gradient(180deg, #0b0c0f 0%, var(--bg) 55%);
  line-height: 1.5;
  overflow-x: hidden;
}
button, input, select { font: inherit; }
a { color: inherit; }

.ambient {
  position: fixed;
  z-index: -1;
  width: 22rem;
  height: 22rem;
  border-radius: 50%;
  filter: blur(100px);
  opacity: .12;
  pointer-events: none;
}
.ambient-one { top: -10rem; left: 12%; background: #7170ff; }
.ambient-two { right: -11rem; bottom: 4rem; background: #3940a5; }

.topbar {
  width: min(1120px, calc(100% - 40px));
  height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.12px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: white;
  background: linear-gradient(145deg, #8584ff, #4f55c8);
  box-shadow: 0 0 24px rgba(113, 112, 255, .28), inset 0 1px 0 rgba(255,255,255,.22);
}
.private-badge, .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  background: rgba(255,255,255,.025);
  font-size: 12px;
  font-weight: 500;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 9px var(--success); }

.app-shell {
  width: min(1120px, calc(100% - 40px));
  min-height: calc(100vh - 132px);
  margin: 0 auto;
  padding: 56px 0 72px;
}
.auth-shell {
  width: 100%;
  min-height: 570px;
  display: grid;
  place-items: center;
}
.auth-card, .panel {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.022));
  box-shadow: 0 24px 80px rgba(0,0,0,.34), inset 0 1px 0 rgba(255,255,255,.035);
}
.auth-card {
  width: min(430px, 100%);
  padding: 34px;
  border-radius: 16px;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-hover);
  font: 500 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(28px, 4vw, 38px); line-height: 1.08; letter-spacing: -.8px; font-weight: 590; }
h2 { margin-bottom: 8px; font-size: 20px; letter-spacing: -.25px; font-weight: 590; }
.lead, .muted { color: var(--muted); }
.lead { margin-bottom: 28px; font-size: 15px; }
.muted { font-size: 13px; }

.form-stack { display: grid; gap: 14px; }
.field { display: grid; gap: 8px; color: var(--text-secondary); font-size: 13px; font-weight: 510; }
input, select {
  width: 100%;
  min-height: 45px;
  padding: 11px 13px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: rgba(255,255,255,.03);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
select {
  appearance: none;
  padding-right: 42px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select option { color: var(--text); background: #17181b; }
input:hover, select:hover { background-color: rgba(255,255,255,.045); }
input:focus, select:focus { border-color: rgba(113,112,255,.75); box-shadow: 0 0 0 3px rgba(113,112,255,.14); }
button, .button {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255,255,255,.04);
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  font-weight: 590;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
button:hover, .button:hover { transform: translateY(-1px); background: var(--surface-hover); border-color: rgba(255,255,255,.16); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.button-primary { border-color: rgba(132,131,255,.5); background: linear-gradient(180deg, #7473e8, #5e6ad2); box-shadow: 0 8px 24px rgba(94,106,210,.2), inset 0 1px 0 rgba(255,255,255,.22); }
.button-primary:hover { background: linear-gradient(180deg, #8584ff, #6772da); }
.button-danger { color: #ffb1b6; border-color: rgba(239,107,115,.2); background: rgba(239,107,115,.06); }
.button-compact { min-height: 34px; padding: 6px 10px; }
.alert {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(239,107,115,.25);
  border-radius: 8px;
  color: #ffb9be;
  background: rgba(239,107,115,.07);
  font-size: 13px;
}
.auth-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border-soft); color: var(--muted); font-size: 12px; }
.auth-meta a { color: var(--text-secondary); text-decoration: none; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-header p { margin-bottom: 0; color: var(--muted); }
.header-actions { display: flex; gap: 10px; }
.panel { border-radius: 14px; overflow: hidden; }
.panel-section { padding: 24px; }
.panel-section + .panel-section { border-top: 1px solid var(--border-soft); }
.inline-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; align-items: end; gap: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 20px; border-top: 1px solid var(--border-soft); text-align: left; font-size: 13px; }
th { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; font-weight: 590; background: rgba(255,255,255,.018); }
td { color: var(--text-secondary); }
.empty-state { padding: 38px 24px; text-align: center; color: var(--muted); }
.status-pill { padding: 3px 9px; font-size: 11px; }
.status-active { color: #8ce5bd; border-color: rgba(53,201,138,.2); background: rgba(53,201,138,.06); }
.status-revoked { color: #a0a4ad; }
.status-pending { color: #dfc187; border-color: rgba(232,185,104,.2); background: rgba(232,185,104,.06); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.dashboard-header { margin-bottom: 32px; }
.dashboard-header h1 { margin-bottom: 12px; }
.setup-panel, .devices-panel {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.018));
  box-shadow: 0 26px 90px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.04);
  overflow: hidden;
}
.setup-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 28px 30px 26px;
  border-bottom: 1px solid var(--border-soft);
}
.setup-intro h2 { margin: 7px 0 7px; font-size: 25px; letter-spacing: -.48px; }
.setup-intro p { margin: 0; color: var(--muted); font-size: 14px; }
.setup-kicker {
  display: inline-flex;
  padding: 4px 9px;
  color: #c9c8ff;
  border: 1px solid rgba(113,112,255,.24);
  border-radius: 999px;
  background: rgba(113,112,255,.08);
  font-size: 11px;
  font-weight: 590;
}
.setup-progress {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 11px;
}
.setup-progress li { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.setup-progress li + li::before { content: ""; width: 22px; height: 1px; margin-right: 1px; background: var(--border); }
.setup-progress span {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  color: #dedfff;
  border: 1px solid rgba(113,112,255,.3);
  border-radius: 50%;
  background: rgba(113,112,255,.1);
  font-weight: 590;
}
.profile-rule {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 22px 30px 2px;
  padding: 14px 16px;
  border: 1px solid rgba(232,185,104,.18);
  border-radius: 11px;
  background: rgba(232,185,104,.055);
}
.profile-rule-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  color: #f1cc8a;
  border: 1px solid rgba(232,185,104,.25);
  border-radius: 10px;
  background: rgba(232,185,104,.08);
  font-weight: 590;
}
.profile-rule strong { display: block; margin-bottom: 2px; color: #f0d7a8; font-size: 13px; }
.profile-rule p { margin: 0; color: #b6a98f; font-size: 12px; }
.device-setup-form { padding: 20px 30px 30px; }
.setup-step {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, .72fr);
  align-items: center;
  gap: 36px;
  min-width: 0;
  margin: 0;
  padding: 20px 0;
  border: 0;
  border-bottom: 1px solid var(--border-soft);
}
.step-heading { display: flex; align-items: flex-start; gap: 14px; }
.step-heading h3 { margin: 1px 0 4px; font-size: 15px; letter-spacing: -.12px; }
.step-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.step-number {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 30px;
  height: 30px;
  color: #fff;
  border: 1px solid rgba(132,131,255,.48);
  border-radius: 9px;
  background: linear-gradient(145deg, rgba(133,132,255,.28), rgba(94,106,210,.16));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12);
  font-size: 12px;
  font-weight: 590;
}
.step-control { display: grid; gap: 7px; }
.control-label { color: var(--text-secondary); font-size: 11px; font-weight: 590; }
.step-control input, .step-control select { min-height: 48px; border-radius: 10px; background-color: rgba(255,255,255,.035); }
.setup-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: 24px;
}
.setup-submit strong, .setup-submit span { display: block; }
.setup-submit strong { margin-bottom: 2px; font-size: 13px; }
.setup-submit > div > span { color: var(--muted); font-size: 12px; }
.setup-submit-button { min-width: 220px; min-height: 48px; border-radius: 10px; }
.setup-submit-button span { display: inline; margin-left: 8px; font-size: 16px; }
.devices-panel { min-width: 0; margin-top: 22px; }
.devices-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px 18px; border-bottom: 1px solid var(--border-soft); }
.devices-heading .eyebrow { margin-bottom: 5px; }
.devices-heading h2 { margin: 0; }
.device-count { display: grid; place-items: center; min-width: 32px; height: 32px; padding: 0 9px; border: 1px solid var(--border); border-radius: 10px; color: var(--text-secondary); background: rgba(255,255,255,.025); font-size: 12px; font-weight: 590; }

.secret-card { max-width: 720px; margin: 6vh auto 0; padding: 30px; }
.secret-box { margin: 22px 0; padding: 18px; border: 1px solid rgba(113,112,255,.25); border-radius: 10px; background: rgba(113,112,255,.065); }
.secret-box code { display: block; overflow-wrap: anywhere; color: #d9d8ff; font: 500 15px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; user-select: all; }
.warning { color: #dfc187; }
.credential-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.credential-heading h2 { margin-bottom: 0; }
.credential-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.credential-box { max-width: 100%; margin: 18px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; user-select: all; }
.credential-box-collapsed { max-height: 180px; overflow-y: auto; }
.qr-card { display: grid; grid-template-columns: minmax(180px, 300px) minmax(180px, 1fr); align-items: center; gap: 24px; margin-top: 20px; padding: 18px; border: 1px solid var(--border-soft); border-radius: 12px; background: rgba(255,255,255,.025); }
.qr-card p { margin: 8px 0 0; }
.qr-image { display: block; width: min(300px, 100%); height: auto; aspect-ratio: 1; padding: 8px; border-radius: 8px; background: #fff; }
.store-link { display: inline-block; margin-top: 14px; color: #c8c7ff; font-size: 13px; text-underline-offset: 3px; }

.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); gap: 12px; min-width: 0; padding: 16px; }
.device-card { min-width: 0; min-height: 150px; padding: 18px; border: 1px solid var(--border-soft); border-radius: 10px; background: var(--surface); }
.device-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.device-card-top > div { min-width: 0; }
.device-card h3 { overflow-wrap: anywhere; margin-bottom: 6px; font-size: 15px; }
.device-card .technical { overflow-wrap: anywhere; margin: 20px 0 0; color: var(--muted); font: 400 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.device-card form { margin-top: 15px; }

.footer { height: 60px; display: grid; place-items: center; color: #5f646e; font-size: 11px; letter-spacing: .03em; }

@media (max-width: 720px) {
  .topbar, .app-shell { width: min(100% - 28px, 1120px); }
  .private-badge { display: none; }
  .app-shell { padding-top: 34px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .credential-heading { align-items: flex-start; flex-direction: column; }
  .credential-heading .button { width: 100%; }
  .credential-actions { width: 100%; }
  .credential-actions .button { flex: 1 1 190px; }
  .qr-card { grid-template-columns: 1fr; }
  .header-actions { width: 100%; }
  .header-actions form, .header-actions button { width: 100%; }
  .inline-form { grid-template-columns: 1fr; }
  .setup-intro { align-items: flex-start; flex-direction: column; }
  .setup-progress { width: 100%; justify-content: space-between; }
  .setup-progress li + li::before { display: none; }
  .setup-step { grid-template-columns: 1fr; gap: 14px; }
  .setup-submit { align-items: stretch; flex-direction: column; }
  .setup-submit-button { width: 100%; }
  th:nth-child(2), td:nth-child(2) { display: none; }
}

@media (max-width: 640px) {
  .auth-shell { min-height: 500px; place-items: start center; padding-top: 24px; }
  .auth-card { padding: 25px 21px; }
  h1 { font-size: 29px; }
  .auth-meta { flex-direction: column; }
  .panel-section { padding: 19px; }
  .setup-intro { padding: 23px 20px 21px; }
  .profile-rule { align-items: flex-start; margin: 18px 20px 0; padding: 13px; }
  .profile-rule-icon { width: 32px; height: 32px; }
  .device-setup-form { padding: 12px 20px 22px; }
  .setup-step { padding: 18px 0; }
  .setup-progress { gap: 8px; font-size: 10px; }
  .setup-progress li { gap: 5px; }
  .setup-progress span { width: 21px; height: 21px; }
  .devices-heading { padding: 19px; }
  th, td { padding: 13px 15px; }
  .device-grid { grid-template-columns: 1fr; }
}

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