/*
 * DNSVault ID — design system
 *
 * Hand-authored, Propshaft-served (no build step, no Tailwind). Matches the
 * light, clean modern-SaaS TONE of the rpzdb app: soft slate background, white
 * cards with a hairline border + gentle shadow, blue primary, system font.
 *
 * Layout:
 *   1. Design tokens (:root custom properties)
 *   2. Base / reset niceties
 *   3. Layout shells        (.page, .topbar, .auth-shell, .auth-card, .content)
 *   4. Typography helpers
 *   5. Forms                (.field, .btn, .btn-primary, .btn-secondary)
 *   6. Flash banners        (.flash)
 *   7. App grid / tiles     (.app-grid, .app-tile)
 *   8. Status pills         (.pill)
 *   9. Misc (org-switcher, QR, code, empty-state)
 *  10. Reduced motion + dark mode
 */

/* 1. Design tokens ------------------------------------------------------- */
:root {
  --bg:               #f8fafc;
  --surface:          #ffffff;
  --surface-2:        #f8fafc;
  --border:           #e5e7eb;
  --text:             #0f172a;
  --muted:            #64748b;
  --primary:          #2563eb;
  --primary-hover:    #1d4ed8;
  --primary-contrast: #ffffff;
  --success:          #16a34a;
  --danger:           #dc2626;

  --radius-card:  14px;
  --radius-input: 8px;
  --radius-pill:  999px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .05);

  --ring: 0 0 0 3px rgba(37, 99, 235, .15);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter,
          "Helvetica Neue", Arial, sans-serif;
}

/* 2. Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 {
  margin: 0 0 .35em;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -.01em;
  text-wrap: balance;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* 3. Layout shells ------------------------------------------------------- */

/* Full-height column: topbar + content. Used by the Launchpad. */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar__email {
  font-size: 13px;
  color: var(--muted);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

/* Centered card shell for the auth wizard. */
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 18px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 32px 28px;
}

.auth-card__lead {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 22px;
}

.auth-foot {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* 4. Brand wordmark ------------------------------------------------------ */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand__glyph {
  width: 26px;
  height: 26px;
  flex: none;
  color: var(--primary);
}
.brand__id {
  font-weight: 600;
  color: var(--muted);
}

/* Centered, larger wordmark for the top of an auth card. */
.brand-lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  text-align: center;
}
.brand-lockup .brand { font-size: 22px; }
.brand-lockup .brand__glyph { width: 30px; height: 30px; }
.brand-lockup__tag {
  font-size: 13px;
  color: var(--muted);
}

/* 5. Forms --------------------------------------------------------------- */
.field { margin-bottom: 16px; }

.field label,
label.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field input[type="password"],
.field select,
input.input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus,
.field select:focus,
input.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.field input::placeholder { color: #9aa4b2; }

/* A large centered code input for OTP / TOTP steps. */
.field input.code-input {
  text-align: center;
  font-size: 24px;
  letter-spacing: .35em;
  font-variant-numeric: tabular-nums;
  padding-left: 12px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  border-radius: var(--radius-input);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-contrast); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-block { width: 100%; }

.btn-sm { padding: 7px 12px; font-size: 13px; }

/* Rails submit buttons inside auth forms adopt the primary block button. */
.auth-card form input[type="submit"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 16px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-contrast);
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: background-color .15s ease;
}
.auth-card form input[type="submit"]:hover { background: var(--primary-hover); }

/* 6. Flash banners ------------------------------------------------------- */
.flash {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
.flash-notice {
  color: #14532d;
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.flash-alert {
  color: #7f1d1d;
  background: #fef2f2;
  border-color: #fecaca;
}

/* In the centered auth shell the flash sits above the card, card-width. */
.auth-shell .flash { width: 100%; max-width: 400px; }

/* 7. App grid / tiles ---------------------------------------------------- */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.app-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.app-tile:hover {
  text-decoration: none;
  border-color: #cbd5e1;
  box-shadow: var(--shadow-card);
  transform: translateY(-1px);
}
.app-tile__icon {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
}
.app-tile__name { font-weight: 600; font-size: 15px; }
.app-tile__meta { font-size: 13px; color: var(--muted); }

/* 8. Status pills -------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  line-height: 1.4;
}
.pill-success {
  color: #14532d;
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.pill-neutral {
  color: #475569;
  background: #f1f5f9;
  border-color: #e2e8f0;
}
.pill-danger {
  color: #7f1d1d;
  background: #fef2f2;
  border-color: #fecaca;
}

/* 9. Misc ---------------------------------------------------------------- */
.page-head { margin-bottom: 4px; }
.page-head h1 { font-size: 22px; }
.page-sub { color: var(--muted); margin: 0 0 8px; }

.org-switcher {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 20px 0;
}
.org-switcher form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.org-switcher label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}
.org-switcher select {
  padding: 8px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--text);
  min-width: 200px;
}
.org-switcher select:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.org-switcher input[type="submit"] {
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--primary-contrast);
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  cursor: pointer;
}
.org-switcher input[type="submit"]:hover { background: var(--primary-hover); }
.org-switcher__note { font-size: 13px; color: var(--muted); margin: 0; }

.empty-state {
  padding: 44px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
}

/* TOTP enrollment QR + setup key */
.qr-frame {
  display: inline-flex;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 4px 0 16px;
}
.qr-frame svg { display: block; width: 180px; height: 180px; }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
.setup-key {
  display: inline-block;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  word-break: break-all;
}

.linkbtn {
  display: inline-block;
  margin-top: 4px;
  font-weight: 600;
}

/* Sign-out button-to renders a bare form; keep it inline. */
.logout-form { display: inline; margin: 0; }

/* 9b. Security page — methods list -------------------------------------- */

/* "Add a passkey" promo banner. */
.promo {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 20px;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: var(--radius-card);
}
.promo__body { flex: 1; min-width: 0; }
.promo__body strong { display: block; font-size: 14px; color: var(--text); }
.promo__body p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.method-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.method-card__head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.method-card__head h2 { font-size: 15px; margin: 0; }
.method-card__head p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.method-list { list-style: none; margin: 0; padding: 0; }

.method {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.method:last-child { border-bottom: 0; }

.method__info { min-width: 0; flex: 1; }
.method__title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.method__name { font-weight: 600; font-size: 14px; }
.method__tag { font-size: 12px; color: var(--muted); }
.method__desc { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.method__action { flex: none; }

.passkey-list { list-style: none; margin: 12px 0 0; padding: 0; }
.passkey-list__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
}
.passkey-list__name { font-weight: 600; font-size: 13px; }
.passkey-list__meta { font-size: 12px; color: var(--muted); }
.passkey-list__remove { margin: 0 0 0 auto; }

.method-status {
  margin: 0;
  padding: 12px 20px 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1px;
}
.method-status[data-state="error"] { color: var(--danger); }

/* "or" divider between email + passkey sign-in on the login card. */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

@media (prefers-color-scheme: dark) {
  .promo { background: #172554; border-color: #1e3a8a; }
}

/* 10. Reduced motion + dark mode ---------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .app-tile:hover { transform: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0b1120;
    --surface:       #111827;
    --surface-2:     #0f1626;
    --border:        #1f2937;
    --text:          #e5e7eb;
    --muted:         #94a3b8;
    --primary:       #3b82f6;
    --primary-hover: #2563eb;
    --shadow-card:   0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    --shadow-sm:     0 1px 2px rgba(0, 0, 0, .3);
    --ring:          0 0 0 3px rgba(59, 130, 246, .25);
  }
  .app-tile__icon { background: #172554; color: #93c5fd; }
  .flash-notice { color: #bbf7d0; background: #052e1a; border-color: #14532d; }
  .flash-alert  { color: #fecaca; background: #300f0f; border-color: #7f1d1d; }
  .pill-success { color: #bbf7d0; background: #052e1a; border-color: #14532d; }
  .pill-neutral { color: #cbd5e1; background: #1e293b; border-color: #334155; }
  .pill-danger  { color: #fecaca; background: #300f0f; border-color: #7f1d1d; }
  .setup-key, .empty-state { background: var(--surface-2); }
  .qr-frame { background: #fff; }
}

/* --- Launchpad "Opening app…" overlay (SSO handoff feedback) --- */
.launch-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
  z-index: 50;
}
.launch-overlay[hidden] { display: none; }
.launch-overlay__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 12px 34px rgba(0,0,0,.10);
  padding: 28px 40px;
  text-align: center;
  max-width: 340px;
}
.launch-overlay__text { margin: 14px 0 2px; font-weight: 600; color: var(--text); }
.launch-overlay__sub  { margin: 0; font-size: 13px; color: var(--muted); }
.spinner {
  display: inline-block;
  width: 30px; height: 30px;
  border: 3px solid color-mix(in srgb, var(--primary) 22%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: launch-spin .7s linear infinite;
}
@keyframes launch-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .launch-overlay { backdrop-filter: none; }
}
