/* ==========================================================================
   2FA Icarus — design tokens
   Dark-first developer tool. Every colour is defined once, here.
   ========================================================================== */

:root {
  /* Surfaces, darkest to lightest */
  --bg: #020617;
  --surface: #0e1223;
  --surface-2: #1a1e2f;
  --border: #334155;
  --border-soft: #232a3d;

  /* Text. ~18:1 and ~7:1 against --bg, both past WCAG AAA for their size. */
  --fg: #f8fafc;
  --fg-muted: #94a3b8;

  /* Primary is split on purpose. The filled value only ever appears behind
     white text; as text on --bg it would land near 3.4:1 and fail. */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --on-primary: #ffffff;
  --link: #60a5fa;

  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --on-danger: #ffffff;

  /* Tinted grounds for status blocks, dark enough to keep text readable */
  --ok-bg: #0b2a18;
  --warn-bg: #2c1f05;
  --danger-bg: #2c0f12;

  /* 4/8px rhythm */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --radius: 10px;
  --radius-lg: 14px;

  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas,
    'Liberation Mono', monospace;

  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.25);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 180ms;

  --z-nav: 40;
  --z-modal: 100;
  --z-toast: 1000;

  color-scheme: dark;
}

/* --------------------------------------------------------------------------
   Fonts. Self-hosted: a vault should not announce every page view to a CDN,
   and it keeps the content security policy free of external origins.
   -------------------------------------------------------------------------- */

@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/inter-variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  font-style: normal;
}

/* JetBrains Mono publishes its variable build as TTF only, so the two weights
   this design actually uses are shipped as static woff2 instead. */
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/jetbrains-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  font-style: normal;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/jetbrains-mono-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
  font-style: normal;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute must win over any class that sets display (.btn, .nav__link
   and friends use flex, which would otherwise override the UA hidden rule). */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0 0 var(--s3);
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 24px;
  font-weight: 600;
}
h2 {
  font-size: 20px;
  font-weight: 600;
}
h3 {
  font-size: 16px;
  font-weight: 600;
}

p {
  margin: 0 0 var(--s4);
  max-width: 68ch; /* keeps prose inside a readable measure */
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

small,
.muted {
  color: var(--fg-muted);
  font-size: 14px;
}

code,
kbd,
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* A focus ring that is always visible and never removed. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: var(--s4);
  top: -100px;
  z-index: var(--z-toast);
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--s2) var(--s4);
  background: var(--surface-2);
  color: var(--fg);
  border-radius: var(--radius);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus {
  top: var(--s4);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Shell and navigation
   -------------------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: 1fr;
  /* Explicit rows: without them both children are auto rows and the container's
     min-height is shared between them, stretching the nav down the viewport. */
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

.nav {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  /* The brand plus three labelled links need ~397px, so on a 375px phone the
     links wrap to a second row. Wrapping keeps every item's text label, which
     dropping to icon-only would not. */
  flex-wrap: wrap;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  /* Respect a notch or rounded corner on a phone. */
  padding-left: max(var(--s4), env(safe-area-inset-left));
  padding-right: max(var(--s4), env(safe-area-inset-right));
}

.nav__brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
  margin-right: auto;
  min-height: 44px;
}

.nav__links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__link {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  padding: var(--s2) var(--s3);
  border-radius: var(--radius);
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav__link:hover {
  background: var(--surface-2);
  color: var(--fg);
}
/* Current location marked by weight and a rule, not colour alone. */
.nav__link[aria-current='page'] {
  color: var(--fg);
  background: var(--surface-2);
  box-shadow: inset 0 -2px 0 var(--link);
}

/* Signing out is destructive-adjacent, so it sits apart from the nav items. */
.nav__signout {
  margin-left: var(--s3);
  padding-left: var(--s3);
  border-left: 1px solid var(--border-soft);
}

/*
 * On a phone the wordmark is what pushes the bar onto a second row, and a
 * two-row sticky header costs real screen. Drop to the shield mark alone; the
 * link keeps its aria-label, and the navigation items keep their text.
 */
@media (max-width: 619px) {
  .nav__wordmark {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .nav__link {
    padding-inline: var(--s2);
  }
  .nav__signout {
    margin-left: var(--s2);
    padding-left: var(--s2);
  }
}

.main {
  padding: var(--s5) var(--s4) var(--s7);
  padding-left: max(var(--s4), env(safe-area-inset-left));
  padding-right: max(var(--s4), env(safe-area-inset-right));
}

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}
.container--narrow {
  max-width: 560px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s5);
}

@media (min-width: 1024px) {
  .main {
    padding-inline: var(--s6);
  }
}

/* --------------------------------------------------------------------------
   Cards and the vault grid
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--s4);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s4);
}

.account {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.account__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s2);
  min-height: 44px;
}

.account__issuer {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.account__label {
  font-size: 14px;
  color: var(--fg-muted);
  overflow-wrap: anywhere;
}

.account__body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

/* The code. Tabular figures are essential: without them the digits change
   width every second and the whole card twitches. */
.code {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.1;
  /* A code must never wrap: a half-code on two lines is unreadable and it
     makes the card jump taller than its neighbours. */
  white-space: nowrap;
  background: none;
  border: 0;
  padding: var(--s2) var(--s1);
  margin: 0;
  color: var(--fg);
  cursor: pointer;
  border-radius: var(--radius);
  transition: color var(--dur) var(--ease);
}
.code:hover {
  color: var(--link);
}
.code[data-state='stale'] {
  color: var(--fg-muted);
}

/* Longer codes step down a size so every card keeps the same height. */
.code[data-digits='7'] {
  font-size: 28px;
}
.code[data-digits='8'] {
  font-size: 25px;
  letter-spacing: 0.06em;
}
.code[data-digits='9'],
.code[data-digits='10'] {
  font-size: 22px;
  letter-spacing: 0.04em;
}

.code__placeholder {
  color: var(--fg-muted);
  letter-spacing: 0.08em;
}

/* Countdown ring */
.ring {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  transform: rotate(-90deg);
}
.ring__track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 3;
}
.ring__value {
  fill: none;
  stroke: var(--ok);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke var(--dur) var(--ease);
}
.ring[data-level='warn'] .ring__value {
  stroke: var(--warn);
}
.ring[data-level='danger'] .ring__value {
  stroke: var(--danger);
}

.countdown {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

/* The seconds are always shown, so the ring's colour is never the only signal. */
.countdown__seconds {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--fg-muted);
  min-width: 3ch;
  text-align: right;
}

.account__actions {
  display: flex;
  gap: var(--s2);
  padding-top: var(--s3);
  border-top: 1px solid var(--border-soft);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: var(--s2) var(--s4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}
.btn:hover:not(:disabled) {
  background: #232a3d;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--primary);
  color: var(--on-primary);
}
.btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn--danger:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn--sm {
  min-height: 36px;
  padding: var(--s1) var(--s3);
  font-size: 13px;
}

.btn--block {
  width: 100%;
}

.btn__spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm {
  width: 16px;
  height: 16px;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field {
  margin-bottom: var(--s4);
}

.field__label {
  display: block;
  margin-bottom: var(--s2);
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}

.field__hint {
  display: block;
  margin-top: var(--s2);
  font-size: 13px;
  color: var(--fg-muted);
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: var(--s2) var(--s3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font: inherit;
  /* 16px prevents iOS from zooming the viewport when a field is focused. */
  font-size: 16px;
  transition: border-color var(--dur) var(--ease);
}
.input:hover,
.select:hover {
  border-color: #475569;
}
.input[aria-invalid='true'] {
  border-color: var(--danger);
}
.textarea {
  min-height: 88px;
  font-family: var(--mono);
  font-size: 14px;
  resize: vertical;
}
.input--mono {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.input--code {
  font-family: var(--mono);
  font-size: 20px;
  letter-spacing: 0.3em;
  text-align: center;
}

.field__error {
  display: block;
  margin-top: var(--s2);
  font-size: 13px;
  color: var(--danger);
}
.field__error:empty {
  display: none;
}

.password-wrap {
  position: relative;
}
.password-wrap .input {
  padding-right: 52px;
}
.password-toggle {
  position: absolute;
  right: var(--s1);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.password-toggle:hover {
  color: var(--fg);
  background: var(--surface-2);
}

fieldset {
  margin: 0 0 var(--s4);
  padding: var(--s4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
legend {
  padding: 0 var(--s2);
  font-size: 14px;
  font-weight: 500;
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  min-height: 44px;
  padding: var(--s2) 0;
  cursor: pointer;
}
.checkbox input {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--primary);
  flex: 0 0 auto;
}
.checkbox__text {
  font-size: 14px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
  margin-top: var(--s5);
}

/* --------------------------------------------------------------------------
   Status blocks, empty states, tables
   -------------------------------------------------------------------------- */

.alert {
  display: flex;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  border: 1px solid;
  border-radius: var(--radius);
  font-size: 14px;
}
.alert:empty {
  display: none;
}
.alert--error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: #fecaca;
}
.alert--ok {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: #bbf7d0;
}
.alert--warn {
  background: var(--warn-bg);
  border-color: var(--warn);
  color: #fde68a;
}

.empty {
  text-align: center;
  padding: var(--s7) var(--s4);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.empty h2 {
  margin-bottom: var(--s2);
}
.empty p {
  margin-inline: auto;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th,
td {
  padding: var(--s3);
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
th {
  font-weight: 600;
  color: var(--fg-muted);
  font-size: 13px;
  background: var(--surface);
}
tbody tr:last-child td {
  border-bottom: 0;
}
td.wrap {
  white-space: normal;
}

.tag {
  display: inline-block;
  padding: 2px var(--s2);
  margin-right: var(--s1);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: 13px;
}
.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status--active {
  color: var(--ok);
}
.status--inactive {
  color: var(--fg-muted);
}

/* Skeleton shown on first load rather than an empty grid. */
.skeleton {
  height: 34px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, #232a3d 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--fg);
  padding: var(--s5);
  width: min(480px, calc(100vw - var(--s6)));
  box-shadow: var(--shadow);
}
.modal::backdrop {
  /* Strong enough to isolate the dialog from a grid of live codes behind it. */
  background: rgb(2 6 23 / 0.72);
}
.modal h2 {
  margin-bottom: var(--s3);
}
.modal__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s3);
  margin-top: var(--s5);
}

/* Reveal-once panel for an API key or recovery codes. */
.reveal {
  border: 1px solid var(--warn);
  background: var(--warn-bg);
  border-radius: var(--radius-lg);
  padding: var(--s4);
  margin-bottom: var(--s5);
}
.reveal__value {
  display: block;
  width: 100%;
  padding: var(--s3);
  margin: var(--s3) 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 14px;
  color: var(--fg);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--s5);
  transform: translateX(-50%);
  z-index: var(--z-toast);
  padding: var(--s3) var(--s4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow);
}
.toast[hidden] {
  display: none;
}

.stack > * + * {
  margin-top: var(--s4);
}

/* --------------------------------------------------------------------------
   Docs
   -------------------------------------------------------------------------- */

.codeblock {
  margin: var(--s3) 0;
  padding: var(--s3) var(--s4);
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow-x: auto;
}
.codeblock code {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--fg);
  white-space: pre;
}

.docs h3 {
  margin-top: var(--s5);
}
.docs p,
.docs li {
  color: var(--fg);
  font-size: 14px;
}
.docs ul {
  padding-left: var(--s5);
}
.docs .muted {
  color: var(--fg-muted);
}
.endpoint {
  font-family: var(--mono);
  font-size: 13px;
}
.endpoint .verb {
  display: inline-block;
  min-width: 52px;
  font-weight: 600;
  color: var(--link);
}

/* --------------------------------------------------------------------------
   QR scanner
   -------------------------------------------------------------------------- */

.scanner {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin-inline: auto;
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}
.scanner__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* A framing reticle so the viewer knows where to aim. */
.scanner__frame {
  position: absolute;
  inset: 18%;
  border: 2px solid rgb(255 255 255 / 0.85);
  border-radius: var(--radius);
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.35);
}

.btn input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
}

/* --------------------------------------------------------------------------
   Reduced motion. The ring steps once per second instead of sweeping, and the
   numeric countdown carries the signal.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .ring__value {
    transition: none;
  }
  .btn__spinner {
    animation: none;
    border-right-color: currentColor;
    opacity: 0.5;
  }
  .skeleton {
    animation: none;
  }
}
