:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d5d9e0;
  --border-strong: #b6bcc7;
  --text: #1b1f27;
  --muted: #5a6372;
  --accent: #1f5fd6;
  --accent-hover: #1a4fb3;
  --accent-contrast: #ffffff;
  --accent-bg: #e3ecfc;
  --accent-text: #174aa6;
  --ok-bg: #dcf3e3;
  --ok-text: #14572b;
  --warn-bg: #fdf0cc;
  --warn-text: #7a4b00;
  --danger: #c0262d;
  --danger-hover: #a01d23;
  --danger-bg: #fbe0e1;
  --danger-text: #8f1b21;
  --info-bg: #dff0fa;
  --info-text: #0b4f73;
  --muted-bg: #e8ebf0;
  --shadow: 0 6px 24px rgba(15, 20, 30, 0.16);
  --radius: 8px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', 'SF Mono', Consolas, 'Liberation Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1e232d;
    --border: #2d3441;
    --border-strong: #434c5d;
    --text: #e6e9ef;
    --muted: #9aa4b5;
    --accent: #6ea0ff;
    --accent-hover: #8bb4ff;
    --accent-contrast: #0b1426;
    --accent-bg: #1c2a47;
    --accent-text: #a9c5ff;
    --ok-bg: #153523;
    --ok-text: #8fe0ab;
    --warn-bg: #3a2c0a;
    --warn-text: #f3cd78;
    --danger: #ef6a70;
    --danger-hover: #f58a8f;
    --danger-bg: #3d1a1d;
    --danger-text: #ffadb1;
    --info-bg: #11303f;
    --info-text: #8fd0f2;
    --muted-bg: #272d39;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  min-height: 100vh;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}
h1 {
  font-size: 1.4rem;
}
h2 {
  font-size: 1.05rem;
}
h3 {
  font-size: 0.95rem;
}
p {
  margin: 0 0 0.6em;
}
a {
  color: var(--accent);
}
ul {
  margin: 0.4em 0 0.6em;
  padding-left: 1.2em;
}
code,
.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.86em;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 8px 12px;
  border-radius: var(--radius);
  z-index: 100;
}
.skip-link:focus {
  top: 8px;
}

.noscript {
  padding: 24px;
}

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}
.side {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0 6px;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 800;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.nav-link:hover {
  background: var(--surface-2);
}
.nav-link[aria-current='page'] {
  background: var(--accent-bg);
  color: var(--accent-text);
  font-weight: 650;
}
.nav-badge {
  background: var(--danger);
  color: #fff;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 20px;
}
.who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 6px 0;
  border-top: 1px solid var(--border);
}
.who-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.main {
  padding: 24px 28px 64px;
  min-width: 0;
  max-width: 1500px;
  width: 100%;
}
.main:focus {
  outline: none;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- tarjetas y estadísticas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}
.card > h2 {
  margin-bottom: 10px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}
.grid-2 > .card {
  margin-bottom: 0;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat--ok {
  border-left-color: var(--ok-text);
}
.stat--warn {
  border-left-color: var(--warn-text);
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat-label {
  color: var(--muted);
  font-size: 0.88em;
  margin-top: 2px;
}

.banner {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin: 0 0 12px;
}
.banner--warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: transparent;
}
.notice {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 8px 12px;
  border-radius: var(--radius);
}

/* ---------- tablas ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  max-width: 100%;
}
.card .table-wrap {
  border-color: var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  text-align: left;
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover {
  background: var(--surface-2);
}
.col-actions {
  white-space: nowrap;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.when {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 170px;
}

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--muted-bg);
  color: var(--muted);
  border: 1px solid transparent;
}
.badge--ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.badge--warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}
.badge--danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}
.badge--info {
  background: var(--info-bg);
  color: var(--info-text);
}
.badge--accent {
  background: var(--accent-bg);
  color: var(--accent-text);
}

/* ---------- botones y formularios ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  line-height: 1.2;
}
.btn:hover:not(:disabled) {
  background: var(--surface-2);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 0.88em;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}
.btn-danger-ghost {
  color: var(--danger-text);
  border-color: var(--danger);
}
.btn-block {
  width: 100%;
}
.icon-btn {
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 10px;
  width: 100%;
  min-width: 0;
}
input[type='checkbox'] {
  width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  accent-color: var(--accent);
  flex: none;
}
input:read-only {
  background: var(--surface-2);
}
textarea {
  resize: vertical;
}
textarea.code,
.mono-input {
  font-family: var(--mono);
  font-size: 0.9em;
}
.search {
  width: 240px;
  max-width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  min-width: 0;
}
.field > label,
.fieldset legend {
  font-weight: 600;
}
.hint {
  color: var(--muted);
  font-size: 0.86em;
  margin: 0;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}
.field--check {
  margin-bottom: 8px;
}
.check-list {
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px 4px;
}
.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 4px;
  margin: 0 0 16px;
  min-width: 0;
}
.fieldset legend {
  padding: 0 6px;
}
.row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid {
  min-width: 0;
}
.form-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.secret-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.secret-input {
  flex: 1 1 220px;
}
.secret-actions {
  display: flex;
  gap: 6px;
}
.inline-actions {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: flex-end;
  margin-bottom: 14px;
}
.filters .field {
  flex: 1 1 180px;
  max-width: 280px;
  margin-bottom: 4px;
}
.filters .field--check {
  flex: 0 0 auto;
  max-width: none;
  align-self: center;
}
.more {
  display: flex;
  justify-content: center;
  padding: 14px 0;
}
.subblock {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

/* ---------- verificaciones ---------- */
.challenge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.challenge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius);
}
.challenge-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.challenge-info .muted {
  color: var(--danger-text);
}
.challenge-input {
  display: flex;
  gap: 8px;
}
.challenge-input input {
  width: 180px;
}
.card:has(.challenge-list .challenge) {
  border-color: var(--danger);
}

/* ---------- estados ---------- */
.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}
.empty {
  text-align: center;
  padding: 32px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
}
.empty-title {
  font-weight: 650;
  color: var(--text);
  margin-bottom: 4px;
}
.empty--error {
  border-color: var(--danger);
}
.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid var(--ok-text);
  box-shadow: var(--shadow);
  font-weight: 500;
}
.toast > span {
  flex: 1;
  overflow-wrap: anywhere;
}
.toast--error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger);
}
.toast-close {
  all: unset;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 4px;
}
.toast-close:focus-visible {
  outline: 2px solid currentColor;
}

/* ---------- diálogos ---------- */
dialog.modal {
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  box-shadow: var(--shadow);
}
dialog.modal--wide {
  width: min(860px, calc(100vw - 24px));
}
dialog.modal::backdrop {
  background: rgba(8, 10, 14, 0.6);
}
.modal-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 24px);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-body {
  padding: 16px 18px 4px;
  overflow: auto;
  min-height: 0;
}
.modal-form > .form-error {
  margin: 0 18px;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.shot-big {
  text-align: center;
}
.shot-big img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.thumb {
  all: unset;
  cursor: zoom-in;
  display: block;
  border-radius: 4px;
}
.thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.thumb-img {
  display: block;
  width: 96px;
  height: 72px;
  object-fit: cover;
  object-position: top;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
}

/* ---------- menú de acciones ---------- */
.menu {
  position: fixed;
  z-index: 500;
  min-width: 230px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-item {
  font: inherit;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-2);
}
.menu-item--danger {
  color: var(--danger-text);
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-size: 1.5rem;
}
.login-card .btn {
  margin-top: 6px;
}

/* ---------- móvil ---------- */
@media (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .side {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav {
    order: 3;
    flex: 1 1 100%;
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 2px;
  }
  .nav-link {
    white-space: nowrap;
    flex: none;
  }
  .who {
    margin-left: auto;
    border-top: 0;
    padding: 0;
  }
  .main {
    padding: 16px 12px 56px;
  }
  .grid-2,
  .row-2 {
    grid-template-columns: minmax(0, 1fr);
  }
  .search {
    width: 100%;
  }
  .filters .field {
    max-width: none;
  }
  .toasts {
    left: 12px;
    right: 12px;
    max-width: none;
  }
}

.col-label {
  min-width: 120px;
}
.col-session {
  min-width: 170px;
}
.nowrap {
  white-space: nowrap;
}
