/* sinapta-identity (SIN-19): estilos de login, recuperación, consentimiento y
   consola. Mismo aspecto que la app de Sinapta (tokens de su sinapta.css):
   carmín de marca #ff2d55 (en botones #e51f48 / #d6103c en claro para que el
   texto blanco llegue a contraste AA), Plus Jakarta Sans, modo claro y oscuro
   según el sistema, radio .75rem (paneles 1.25rem) y superficies oscuras
   #0b0b0e / #121217 / #1a1a21. Sin JavaScript ni recursos externos. */

@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("/assets/plus-jakarta-sans.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eceff4;
  --text: #18181e;
  --muted: #60636f;
  --border: #dce0e7;
  --input: #c5cad3;
  --primary: #d6103c;
  --primary-hover: #bb1740;
  --on-primary: #ffffff;
  --link: #bb1740;
  --focus: #bb1740;
  --danger: #bb1740;
  --danger-bg: #fdecef;
  --ok: #177767;
  --ok-bg: #e6f4f1;
  --signal-soft: #e51f480a;
  --grid: #14142107;
  --spark: linear-gradient(135deg, #ff2d55, #ff5c7c 55%, #ff9aa9);
  --radius: .75rem;
  --radius-panel: 1.25rem;
  --shadow: 0 20px 70px #1c213015;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0e;
    --surface: #121217;
    --surface-2: #1a1a21;
    --text: #f5f7fa;
    --muted: #a3a5b0;
    --border: #292930;
    --input: #373740;
    --primary: #e51f48;
    --primary-hover: #ff2d55;
    --on-primary: #ffffff;
    --link: #ff8095;
    --focus: #ff5c7c;
    --danger: #ff8095;
    --danger-bg: #2a0a14;
    --ok: #6cdac8;
    --ok-bg: #0d2622;
    --signal-soft: #ff2d5512;
    --grid: #ffffff05;
    --shadow: 0 20px 70px #0005;
  }
}

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

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

::selection { background: var(--primary); color: var(--on-primary); }

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

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

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

.skip {
  position: absolute; left: 8px; top: -48px; z-index: 10;
  padding: 8px 12px; background: var(--surface); color: var(--text);
  border: 2px solid var(--focus); border-radius: 8px;
}
.skip:focus { top: 8px; }

h1 { font-size: 1.5rem; line-height: 1.25; font-weight: 800; letter-spacing: -.02em; margin: 0 0 8px; }
h2 { font-size: 1.125rem; font-weight: 700; margin: 0 0 4px; }
h3 { font-size: 1rem; font-weight: 700; margin: 0 0 4px; }
p { margin: 0 0 12px; }
.lead, .muted { color: var(--muted); }
.lead { margin-bottom: 20px; }
.small { font-size: .875rem; }

/* ── Tarjeta (login y compañía) ─────────────────────────────── */

.auth-main {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse at 85% 0%, var(--signal-soft), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: auto, 36px 36px, 36px 36px;
}
.card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  position: relative; overflow: hidden;
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--spark);
}
.brand { margin-bottom: 24px; }
.logo { display: block; height: 36px; width: auto; }

/* ── Formularios ─────────────────────────────────────────────── */

form { margin: 0; }
.field { margin-bottom: 16px; }
label, .label { display: block; font-weight: 600; font-size: .9375rem; margin-bottom: 6px; }
.hint { display: block; font-size: .875rem; color: var(--muted); margin-top: 6px; }

input[type=email], input[type=password], input[type=text], input[type=search], select {
  width: 100%; min-height: 44px;
  padding: 10px 12px;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--input);
  border-radius: var(--radius);
}
input:hover, select:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
input[aria-invalid=true] { border-color: var(--danger); }

fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
legend { font-weight: 600; font-size: .9375rem; margin-bottom: 6px; padding: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0; font-weight: 400; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.checks { display: grid; gap: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  font: inherit; font-weight: 700; text-decoration: none;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
}
.btn:hover { background: var(--primary-hover); }
.btn-block { width: 100%; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-link {
  background: none; border: 0; padding: 0; min-height: 0; font: inherit;
  color: var(--link); text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.actions .btn { flex: 1 1 auto; }

.alert { padding: 12px 14px; border-radius: var(--radius); font-size: .9375rem; margin-bottom: 16px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }

.links { margin-top: 20px; font-size: .9375rem; display: grid; gap: 8px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

/* ── Consentimiento ─────────────────────────────────────────── */

.scopes { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.scopes li {
  padding: 10px 12px 10px 36px; position: relative;
  background: var(--surface-2); border-radius: var(--radius);
}
.scopes li::before {
  content: ""; position: absolute; left: 14px; top: 50%; width: 8px; height: 8px;
  margin-top: -4px; border-radius: 50%; background: var(--primary);
}
details { margin: 0 0 16px; font-size: .875rem; }
summary { cursor: pointer; color: var(--muted); font-weight: 600; }
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .875em; }

/* ── Consola ─────────────────────────────────────────────────── */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: relative; }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--spark); }
.topbar-in {
  max-width: 1080px; margin: 0 auto; padding: 12px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
}
.topbar .logo { height: 28px; }
.topbar .org { color: var(--muted); font-weight: 600; font-size: .9375rem; }
.topbar nav { order: 3; width: 100%; }
.topbar nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a {
  display: block; padding: 8px 12px; border-radius: var(--radius);
  color: var(--text); text-decoration: none; font-weight: 600; white-space: nowrap;
}
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a[aria-current=page] { background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--primary); }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: .9375rem; }

.console-main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { margin: 0; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-panel);
  padding: 20px; margin-bottom: 20px;
}
.panel > h2 + p { color: var(--muted); }
.grid-2 { display: grid; gap: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row .field { flex: 1 1 200px; margin-bottom: 0; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: .8125rem; font-weight: 600; background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--danger-bg); color: var(--danger); }
.badge-brand { background: var(--primary); color: var(--on-primary); }

/* Tablas: en móvil cada fila es una tarjeta con sus etiquetas. */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .8125rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.table a { font-weight: 600; }

@media (max-width: 719px) {
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .table td { border: 0; padding: 4px 0; display: flex; gap: 12px; }
  .table td::before { content: attr(data-label); flex: 0 0 96px; color: var(--muted); font-size: .875rem; }
}

@media (min-width: 720px) {
  .card { padding: 40px 36px; }
  .topbar nav { order: 0; width: auto; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.alert-error-text { color: var(--danger); font-weight: 600; }

/* ── Consola: piezas sueltas ────────────────────────────────── */

details.panel > summary { list-style: none; display: flex; align-items: center; gap: 10px; color: var(--text); }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before {
  content: "+"; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--on-primary); font-weight: 800;
}
details.panel[open] > summary::before { content: "−"; }
details.panel[open] > summary { margin-bottom: 12px; }
h2.inline { display: inline; margin: 0; }
.section-title { margin: 28px 0 12px; }
.panel.danger { border-color: var(--danger); }
.search { margin-bottom: 12px; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .875rem; }
.members { list-style: none; margin: 0 0 16px; padding: 0; }
.members li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.members li > span { display: grid; min-width: 0; overflow-wrap: anywhere; }
.members li:last-child { border-bottom: 0; }
.stack { margin-bottom: 16px; }
.empty { margin: 8px 0; }
.brandlink { display: inline-flex; }

/* Notas de versión y detalle de errores (actualizaciones on-premise). */
pre.notes { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 16px; font: inherit; }

/* ── Métricas y auditoría de la consola global ─────────────── */

.alert-warn { background: var(--surface-2); color: var(--text); border: 1px solid var(--danger); border-left-width: 4px; }

.range-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.range-nav a {
  display: inline-block; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: .9375rem;
}
.range-nav a:hover { background: var(--surface-2); }
.range-nav a[aria-current=true] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { display: block; color: var(--muted); font-size: .8125rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { display: block; font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.kpi-note { display: block; color: var(--muted); font-size: .8125rem; }

.charts { display: grid; gap: 16px; }
.chart { margin: 0; }
.chart figcaption { font-weight: 700; margin-bottom: 4px; }
.chart-svg { display: block; width: 100%; height: auto; max-height: 260px; }
.chart-grid line { stroke: var(--border); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--primary); stroke: var(--surface); stroke-width: 1.5; }
.chart-bar { fill: var(--primary); }
.chart-empty { margin: 4px 0 8px; }
.chart-data { margin: 4px 0 0; }
.chart-data table { margin-top: 8px; }

.filters .row { align-items: flex-end; }
.filters .field { flex: 1 1 160px; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
td.wrap { overflow-wrap: anywhere; max-width: 260px; }

@media (min-width: 720px) {
  .charts { grid-template-columns: 1fr 1fr; }
}

/* ── Enlace «Volver a la aplicación» ────────────────────────── */

.back-app { font-weight: 700; }
.back-app::before { content: "\2190\00a0"; }
.topbar .who .back-app {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); text-decoration: none; font-size: .875rem; white-space: nowrap;
}
.topbar .who .back-app:hover { background: var(--surface-2); border-color: var(--primary); }
