:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light dark;
  --page: #f3f6f7;
  --surface: #ffffff;
  --surface-soft: #f5f9f9;
  --text: #17282f;
  --muted: #51636b;
  --border: #c9d5d8;
  --brand: #0f6559;
  --brand-hover: #0b4a40;
  --brand-text: #ffffff;
  --focus: #16816b;
  --error-bg: #fff1ef;
  --error-border: #bd5549;
  --error-text: #862b24;
  --success-bg: #edf8f3;
  --success-border: #368065;
  --success-text: #225c47;
  --shadow: 0 24px 64px rgba(24, 53, 62, .09), 0 2px 8px rgba(24, 53, 62, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.55;
}

.page-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 1rem;
  background: radial-gradient(circle at 50% 18%, rgba(30, 115, 126, .08), transparent 37rem);
}

.site-header,
.site-footer {
  width: min(100%, 60rem);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.35rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  height: 2.5rem;
}

.site-header-note { color: var(--muted); font-size: .8rem; font-weight: 600; }

.portal-card {
  width: min(100%, 60rem);
  margin: 2rem auto 3rem;
  padding: clamp(1.4rem, 4vw, 2.5rem);
  align-self: center;
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card { width: min(100%, 29rem); }
.codes-card { width: min(100%, 39rem); }

h1, h2, h3 { line-height: 1.2; letter-spacing: -.035em; }
h1 { margin: 0; font-size: clamp(1.65rem, 5vw, 2rem); }
h2 { font-size: 1.16rem; }
p { margin-block: .6rem 1rem; }

.card-heading { margin-bottom: 1.7rem; }
.card-heading > p:last-child { margin-bottom: 0; color: var(--muted); }
.eyebrow {
  margin: 0 0 .6rem;
  color: var(--brand);
  font-size: .75rem;
  font-weight: 750;
  letter-spacing: .1em;
  text-transform: uppercase;
}

form { margin-block: 1rem; }
.form-stack { display: grid; gap: 1.2rem; margin-block: 0; }
.field { min-width: 0; }
.field label, label { display: block; font-weight: 650; }

input:not([type="hidden"]), select {
  display: block;
  width: 100%;
  min-height: 3rem;
  margin-top: .4rem;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: .55rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:not([type="hidden"]):hover, select:hover { border-color: var(--muted); }
input::placeholder { color: var(--muted); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

input:not([type="hidden"]):focus-visible, select:focus-visible {
  border-color: var(--focus);
  outline-offset: 2px;
}

.field-help { margin: .4rem 0 0; color: var(--muted); font-size: .85rem; }

button, .button-primary, .button-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: .65rem 1.1rem;
  border: 1px solid var(--brand);
  border-radius: .55rem;
  background: var(--brand);
  color: var(--brand-text);
  font: inherit;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .button-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-text); }
button:disabled { cursor: not-allowed; opacity: .55; }
.form-stack > button, .setup-action > button, .card-actions > .button-primary { width: 100%; }

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--brand);
}

.button-secondary:hover { border-color: var(--brand); background: var(--surface-soft); }

a { color: var(--brand); text-underline-offset: .2em; }
a:hover { color: var(--brand-hover); }

.notice {
  margin: 0 0 1.4rem;
  padding: .8rem 1rem;
  border: 1px solid;
  border-radius: .55rem;
  font-weight: 600;
}

.notice-error, p[role="alert"] {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
}

.notice-success { border-color: var(--success-border); background: var(--success-bg); color: var(--success-text); }

.setup-panel, .setup-action {
  margin-block: 0 1.7rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: .7rem;
  background: var(--surface-soft);
}

.setup-panel h2, .recovery-option h2 { margin: 0; }
.setup-panel p, .setup-action p, .recovery-option > p { margin: .45rem 0 .9rem; color: var(--muted); font-size: .9rem; }

.secret-value {
  padding: .85rem;
  border: 1px dashed var(--border);
  border-radius: .55rem;
  background: var(--surface);
  text-align: center;
}

code, pre { overflow-wrap: anywhere; }
.secret-value code { font-size: 1rem; font-weight: 700; letter-spacing: .06em; }

.recovery-option {
  margin-top: 1.8rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.save-instruction { color: var(--muted); }
.recovery-codes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: .65rem;
  margin: 1.2rem 0 1.7rem;
  padding: 0;
  list-style: none;
}

.recovery-codes li {
  padding: .75rem .9rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--surface-soft);
  text-align: center;
}

.recovery-codes code { font-size: .9rem; font-weight: 700; letter-spacing: .03em; }
.card-actions { margin-top: 1.5rem; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .4rem 1.5rem;
  padding-block: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .76rem;
}

.site-footer p { margin: 0; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .35rem 1rem; }
.site-footer a { color: inherit; }

@media (max-width: 35rem) {
  .site-header-note { display: none; }
  .portal-card { margin-block: 1rem 2rem; }
  .site-footer { flex-direction: column; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0e191e;
    --surface: #17262c;
    --surface-soft: #203238;
    --text: #f0f6f7;
    --muted: #b9cbd0;
    --border: #4d626a;
    --brand: #35b493;
    --brand-hover: #5cc8a9;
    --brand-text: #0e3029;
    --focus: #5cc8a9;
    --error-bg: #3e2627;
    --error-border: #ed9a91;
    --error-text: #ffcac4;
    --success-bg: #203b32;
    --success-border: #7bc9a6;
    --success-text: #b9ebd1;
    --shadow: 0 24px 64px rgba(0, 0, 0, .24);
  }

  .page-shell { background: radial-gradient(circle at 50% 18%, rgba(67, 154, 165, .12), transparent 37rem); }
}

@media print {
  :root {
    color-scheme: light;
    --surface: #ffffff;
    --surface-soft: #ffffff;
    --text: #111111;
    --muted: #333333;
    --border: #777777;
    --brand: #0f6559;
    --brand-text: #ffffff;
  }
  body, .page-shell { min-height: 0; background: #fff; color: #111; }
  .page-shell { display: block; padding: 0; }
  .site-header { padding: 0 0 1rem; }
  .portal-card { width: 100%; margin: 0; padding: 0; border: 0; box-shadow: none; }
  .site-footer, .card-actions { display: none; }
  .recovery-codes { grid-template-columns: repeat(2, 1fr); }
  .recovery-codes li { break-inside: avoid; background: #fff; color: #111; }
  .notice-success { color: #111; background: #fff; }
}

/* QR del alta TOTP: fondo blanco también en modo oscuro (los lectores necesitan contraste) */
.totp-qr-box { display: flex; justify-content: center; margin: 1rem 0; }
.totp-qr { display: block; width: min(220px, 100%); aspect-ratio: 1; background: #fff; border-radius: .5rem; }
