:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #16243a;
  --muted: #5d6b80;
  --line: #dde4ee;
  --brand: #1a5aa6;
  --brand-ink: #0f3f78;
  --brand-soft: #e6effa;
  --accent: #f2a900;
  --accent-soft: #fff4d6;
  --ok: #1d8a5a;
  --ok-soft: #e3f5ec;
  --warn: #b26a00;
  --warn-soft: #fff1dc;
  --danger: #c0392b;
  --danger-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 36, 64, .06), 0 6px 20px rgba(16, 36, 64, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1522; --surface: #162134; --surface-2: #1b283e; --text: #e8eef7; --muted: #9aa9bf; --line: #2a3a54;
    --brand: #5b9be6; --brand-ink: #a9cbf3; --brand-soft: #1c3150; --accent: #ffc233; --accent-soft: #3a2f12;
    --ok: #4cc58e; --ok-soft: #133526; --warn: #f0a640; --warn-soft: #3a2a12; --danger: #ff7b6e; --danger-soft: #3d1a17;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.55rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .02em; }
.hidden { display: none !important; }

/* ---- Barra superior ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.brand small { color: var(--muted); font-weight: 600; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: .93rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox .who { text-align: right; line-height: 1.2; font-size: .85rem; }
.userbox .who b { display: block; }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 1.1rem; cursor: pointer; }

.panel { display: flex; align-items: center; gap: 18px; flex: 1; }
@media (max-width: 860px) {
  .menu-toggle { display: block; margin-left: auto; }
  .panel { display: none; }
  .topbar.open .panel { display: flex; flex-direction: column; align-items: stretch; position: absolute; top: 60px; left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px 16px; box-shadow: var(--shadow); }
  .topbar.open .nav { flex-direction: column; }
  .userbox { justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; }
  .userbox .who { text-align: left; }
}

/* ---- Layout ---- */
.page { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .hint { font-size: .82rem; color: var(--muted); }

/* ---- Círculos ---- */
.rings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 640px) { .rings { grid-template-columns: 1fr; } }
.ring-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.ring { width: 200px; max-width: 100%; height: auto; }
.ring-track { stroke: var(--line); }
.ring-fill { stroke: var(--brand); transition: stroke-dashoffset .8s ease; }
.ring-fill.p1 { stroke: var(--accent); }
.ring-fill.p2 { stroke: var(--ok); }
.ring-num { fill: var(--text); font-weight: 800; font-size: 42px; font-family: inherit; }
.ring-sub { fill: var(--muted); font-size: 13px; font-weight: 600; font-family: inherit; }
.ring-tick { stroke: var(--surface); stroke-width: 4; }
.prizes { display: flex; gap: 10px; width: 100%; }
.prize { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface-2); }
.prize b { display: block; }
.prize .state { font-size: .8rem; font-weight: 700; }
.prize.on { border-color: var(--ok); background: var(--ok-soft); }
.prize.on .state { color: var(--ok); }
.prize.off .state { color: var(--muted); }

/* ---- Tablas ---- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
.rank-top td { background: var(--accent-soft); }
.rank-top td:first-child { border-left: 4px solid var(--accent); }
.rank-me td { outline: 2px solid var(--brand); outline-offset: -2px; }
.medal { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 800; font-size: .85rem; background: var(--surface-2); border: 1px solid var(--line); }
.rank-top .medal { background: var(--accent); color: #3a2a00; border-color: transparent; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.pendiente { background: var(--warn-soft); color: var(--warn); }
.badge.validado { background: var(--ok-soft); color: var(--ok); }
.badge.role { background: var(--brand-soft); color: var(--brand-ink); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ---- Formularios ---- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=email], input[type=search], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; border-color: var(--brand); }
.field { margin-bottom: 16px; }
.inline-form { display: inline; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.toolbar .field { margin: 0; }
.toolbar input[type=search] { min-width: 220px; }
select.compact { width: auto; min-height: 36px; padding: 6px 30px 6px 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; border-radius: 10px; padding: 10px 16px; min-height: 44px; border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0b1422; } .btn-primary:hover { color: #0b1422; } }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: .86rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---- Registro de SO ---- */
.so-rows { display: flex; flex-direction: column; gap: 10px; }
.so-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 150px 44px; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.so-row.has-error { border-color: var(--danger); background: var(--danger-soft); }
.so-row .idx { width: 34px; height: 44px; display: grid; place-items: center; font-weight: 800; color: var(--muted); }
.so-row .err { grid-column: 2 / -1; color: var(--danger); font-weight: 600; font-size: .88rem; }
.so-row input.so { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .12em; font-size: 1.05rem; }
.so-row .counter { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.so-row .counter.full { color: var(--ok); font-weight: 700; }
.so-remove { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.so-remove:hover { color: var(--danger); border-color: var(--danger); }
@media (max-width: 560px) {
  .so-row { grid-template-columns: 28px minmax(0, 1fr) 44px; }
  .so-row .pts { grid-column: 2 / 3; }
  .so-row .so-remove { grid-row: 1; grid-column: 3; }
}
.form-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---- Alertas ---- */
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-weight: 600; border: 1px solid transparent; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert.info { background: var(--brand-soft); color: var(--brand-ink); }

/* ---- Autenticación ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; margin-bottom: 18px; font-size: 1.1rem; }
.auth-card h1 { text-align: center; }
.auth-card p.lead { text-align: center; color: var(--muted); margin: 0 0 20px; }
.auth-links { text-align: center; margin-top: 16px; font-size: .92rem; }
.otp-input { text-align: center; font-size: 1.8rem !important; letter-spacing: .5em; font-family: ui-monospace, Menlo, Consolas, monospace; }

.pager { display: flex; gap: 6px; justify-content: center; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; background: var(--surface); }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .tabs a.active { color: #0b1422; } }
details.edit summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: .88rem; }
details.edit[open] { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-top: 10px; align-items: end; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
pre.detail { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .8rem; color: var(--muted); max-width: 420px; }

.mt { margin-top: 16px; }
.mt-sm { margin-top: 12px; }
.mb { margin-bottom: 16px; }
.card-head { flex-wrap: wrap; }
.card-head form.toolbar { flex-wrap: nowrap; }
@media (max-width: 560px) { .card-head form.toolbar { width: 100%; } .toolbar input[type=search] { min-width: 0; flex: 1; } }

/* ---- Imagen de fondo en pantallas de acceso (login, código, recuperar) ---- */
.auth-wrap {
  background-color: #0f3f78; /* se ve este color si la imagen no carga */
  background-image:
    linear-gradient(rgba(10, 25, 50, .45), rgba(10, 25, 50, .55)),
    url('/public/img/login-bg.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.auth-wrap .auth-card { box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }

/* ---- Logo Reset ---- */
.brand-logo { width: 36px; height: 36px; border-radius: 50%; display: block; flex: none; }
.auth-card .brand { flex-direction: column; gap: 8px; }
.auth-card .brand-logo { width: 88px; height: 88px; box-shadow: 0 4px 14px rgba(0, 0, 0, .18); }

/* ---- Recuadro de acceso con efecto vidrio esmerilado ---- */
.auth-wrap .auth-card {
  background: rgba(255, 255, 255, .16);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .30), inset 0 1px 0 rgba(255, 255, 255, .25);
  color: #fff;
}
.auth-wrap .auth-card h1,
.auth-wrap .auth-card label,
.auth-wrap .auth-card .brand { color: #fff; }
.auth-wrap .auth-card .brand small,
.auth-wrap .auth-card p.lead,
.auth-wrap .auth-card .muted { color: rgba(255, 255, 255, .85); }
.auth-wrap .auth-card a { color: #fff; }
.auth-wrap .auth-card input[type=text],
.auth-wrap .auth-card input[type=password] {
  background: rgba(255, 255, 255, .88);
  border-color: rgba(255, 255, 255, .6);
  color: #16243a;
}
.auth-wrap .auth-card .btn-ghost { background: rgba(255, 255, 255, .18); color: #fff; border-color: rgba(255, 255, 255, .45); }
.auth-wrap .auth-card .alert.error { background: rgba(255, 235, 235, .95); color: #b3261e; }
.auth-wrap .auth-card .alert.ok { background: rgba(230, 250, 240, .95); color: #14693f; }
/* Navegadores sin soporte de desenfoque: recuadro más opaco para que se lea bien */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .auth-wrap .auth-card { background: rgba(20, 30, 50, .78); }
}

/* ---- Botón gris en pantallas de acceso ---- */
.auth-wrap .auth-card .btn-primary {
  background-color: #0087f6;
  color: #16243a;
  border-color: #0087f6;
}
.auth-wrap .auth-card .btn-primary:hover { background-color: #f7f8fa; border-color: #f7f8fa; color: #16243a; }

/* ---- Opción eliminar ---- */
details.edit summary.danger-summary { color: var(--danger); }

/* ---- Observaciones del auditor ---- */
.obs-cell { min-width: 220px; }
textarea.obs-input {
  width: 100%; font: inherit; font-size: .88rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; resize: vertical; min-height: 38px;
}
textarea.obs-input.obs-required { border-color: var(--warn); background: var(--warn-soft); }
.obs-note { margin-top: 4px; font-size: .85rem; color: var(--text); background: var(--brand-soft); border-left: 3px solid var(--brand); padding: 6px 10px; border-radius: 6px; }
.obs-note b { color: var(--brand-ink); }
tr.obs-row td { padding-top: 0; }
tr:has(+ tr.obs-row) td { border-bottom: none; }