:root {
  --cream: #fbf5ea;
  --paper: #fffdf8;
  --ink: #1c333a;
  --ink-soft: #52676c;
  --line: #e4dacb;
  --teal: #2f5d66;
  --mint: #dcefee;
  --coral: #c94a22;
  --coral-soft: #fbe4d9;
  --sun: #ffc53d;
  --danger: #8f2f12;
  --success: #2f6b4f;
  --shadow: 0 12px 30px rgba(28, 51, 58, 0.08);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Figtree", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--coral); }
a:hover { color: var(--ink); }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--coral) 55%, transparent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 4vw, 44px);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-bubble {
  width: 34px;
  height: 34px;
  border-radius: 42% 58% 55% 45%;
  background: radial-gradient(circle at 32% 28%, #f4fffb, #8cb8c1 45%, #5a8792 100%);
  box-shadow: inset -3px -4px 0 rgba(28, 51, 58, 0.15);
}

.brand strong { display: block; font-size: 1.05rem; line-height: 1; }
.brand small { display: block; color: var(--ink-soft); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; }

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
}

.topbar-nav a { color: var(--ink); font-weight: 700; text-decoration: none; }
.who { color: var(--ink-soft); font-size: 0.8rem; }

.inline-form { display: inline; }
.link-button {
  border: 0;
  background: none;
  color: var(--coral);
  padding: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.wrap { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 52px; }

.flash {
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
}
.flash--success { background: #e7f4ed; color: var(--success); }
.flash--error { background: #fff0ea; color: var(--danger); }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.page-head h1 { margin: 2px 0 4px; font-size: clamp(1.7rem, 4vw, 2.6rem); line-height: 1.1; }
.eyebrow { margin: 0; color: var(--coral); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.muted { color: var(--ink-soft); font-size: 0.88rem; }
.back { display: inline-block; margin-bottom: 6px; font-size: 0.84rem; font-weight: 700; text-decoration: none; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat {
  display: grid;
  gap: 2px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
}
.stat strong { font-size: 1.5rem; }
.stat span { color: var(--ink-soft); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.stat.is-active { border-color: var(--coral); background: var(--coral-soft); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.filters input, .filters select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 11px;
  font: inherit;
}
.filters input { flex: 1 1 260px; }
.link { font-size: 0.86rem; font-weight: 700; }

.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; background: #fcf8f0; }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; margin-top: 2px; }
.row-link { font-weight: 800; text-decoration: none; }

.status {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}
.status--new { background: #fff0c2; color: #6b4e00; }
.status--contacted { background: var(--mint); color: #1e4d4f; }
.status--qualified { background: #e0ecff; color: #234b7a; }
.status--converted { background: #e7f4ed; color: var(--success); }
.status--discarded { background: #f0e9e4; color: #6b5548; }

.empty { padding: 34px; background: var(--paper); border: 1px dashed var(--line); border-radius: 16px; text-align: center; }
.empty h1, .empty h2 { margin-top: 0; }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.card h3 { margin: 18px 0 6px; font-size: 0.88rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.card--wide { margin-top: 14px; }
.facts { display: grid; grid-template-columns: minmax(110px, 0.8fr) 1.2fr; gap: 7px 12px; margin: 0 0 14px; font-size: 0.88rem; }
.facts dt { color: var(--ink-soft); font-weight: 700; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dd.big { font-size: 1.3rem; font-weight: 800; color: var(--coral); }

.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 0.84rem; font-weight: 700; }
.form input, .form select, .form textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  font: inherit;
}
.form textarea { min-height: 96px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  padding: 10px 20px;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--ink); color: #fff; }
.btn-small { min-height: 38px; padding: 8px 14px; font-size: 0.84rem; }

.notes { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.notes li { padding: 10px 12px; border-radius: 10px; background: #fcf8f0; }
.notes p { margin: 0 0 4px; white-space: normal; }
.notes small { color: var(--ink-soft); font-size: 0.76rem; }

pre {
  overflow: auto;
  max-height: 360px;
  padding: 12px;
  border-radius: 10px;
  background: #fcf8f0;
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.5;
}

.auth-card {
  width: min(460px, 100%);
  margin: 34px auto;
  padding: clamp(22px, 4vw, 34px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 4px 0 8px; font-size: clamp(1.5rem, 4vw, 2.1rem); line-height: 1.1; }
.auth-card .btn { width: 100%; margin-top: 6px; }
.alert { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: #fff0ea; color: var(--danger); font-size: 0.86rem; font-weight: 600; }

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 18px clamp(16px, 4vw, 44px);
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.76rem;
}

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .topbar-nav { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 640px) {
  .wrap { width: min(100% - 24px, 1180px); padding-top: 20px; }
  .page-head { display: grid; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:last-child { grid-column: span 2; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tr { padding: 12px; border-bottom: 1px solid var(--line); }
  td { display: flex; justify-content: space-between; gap: 12px; padding: 5px 2px; border: 0; }
  td::before { content: attr(data-label); color: var(--ink-soft); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }
  td[data-label="Persona"], td[data-label="Contacto"] { display: block; }
  td[data-label="Persona"]::before, td[data-label="Contacto"]::before { display: block; margin-bottom: 2px; }
  td:last-child { padding-top: 10px; }
  td:last-child::before { display: none; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dt { margin-top: 7px; }
  .footer { display: grid; }
}

/* Métricas del test */
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.section-head h2 { margin: 2px 0 0; }
.result-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--teal);
  font-size: 1.25rem;
  font-weight: 900;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.metric {
  display: grid;
  gap: 2px;
  padding: 13px 14px;
  border-radius: 12px;
  background: #fcf8f0;
  border: 1px solid var(--line);
}
.metric span { color: var(--ink-soft); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.metric strong { font-size: 1.35rem; }
.metric small { color: var(--ink-soft); font-size: 0.8rem; }
.metric--good { background: #e7f4ed; border-color: #cce3d7; }
.metric--good strong { color: var(--success); }
.metric--bad { background: #fff0ea; border-color: #f3d2c4; }
.metric--bad strong { color: var(--danger); }

.level-metrics { margin: 0 0 18px; }
.level-row { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 12px; margin: 7px 0; }
.level-label { display: flex; justify-content: space-between; gap: 8px; font-size: 0.82rem; }
.level-label span { color: var(--ink-soft); }
.level-row progress {
  width: 100%;
  height: 9px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #f0e8da;
  accent-color: var(--coral);
}
.level-row progress::-webkit-progress-bar { background: #f0e8da; border-radius: 999px; }
.level-row progress::-webkit-progress-value { background: var(--coral); border-radius: 999px; }
.level-row progress::-moz-progress-bar { background: var(--coral); border-radius: 999px; }

.insights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 4px 0 20px; }
.insight { padding: 14px; border-radius: 12px; border: 1px solid var(--line); }
.insight h3 { margin: 0 0 8px; }
.insight--good { background: #f1f9f4; border-color: #cfe5d8; }
.insight--warn { background: #fff8ed; border-color: #f0dfbd; }
.insight p { margin: 0; color: var(--ink-soft); font-size: 0.86rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-block; padding: 5px 9px; border-radius: 999px; font-size: 0.76rem; font-weight: 800; }
.tag--good { background: #dcefe4; color: var(--success); }
.tag--warn { background: #ffebc9; color: #7a5200; }

.table-wrap--inner { box-shadow: none; margin: 8px 0 14px; }
.answers-table { font-size: 0.82rem; }
.answers-table th, .answers-table td { padding: 9px 10px; }
.answers-table td[data-label="Pregunta"] { min-width: 220px; }
.answer-wrong { color: var(--danger); font-weight: 700; }
.answer-right { color: var(--success); font-weight: 700; }
.answer-badge { display: inline-block; padding: 3px 7px; border-radius: 999px; font-size: 0.7rem; font-weight: 800; }
.answer-badge--ok { background: #e7f4ed; color: var(--success); }
.answer-badge--ko { background: #fff0ea; color: var(--danger); }
.answers-disclosure { margin-top: 8px; }
.answers-disclosure summary { cursor: pointer; color: var(--coral); font-size: 0.86rem; font-weight: 800; }
.answers-disclosure summary:hover { color: var(--ink); }
.orientation-facts { grid-template-columns: minmax(160px, 0.55fr) 1.45fr; margin-bottom: 0; }

@media (max-width: 860px) {
  .metrics { grid-template-columns: 1fr; }
  .insights { grid-template-columns: 1fr; }
  .level-row { grid-template-columns: 1fr; gap: 4px; }
}

/* Usuarios, roles y recuperación */
.form--grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}
.form--grid .btn { justify-self: start; }
.form--grid label:last-of-type { grid-column: span 2; }
.auth-help { margin: 14px 0 0; text-align: center; font-size: 0.86rem; }
.auth-help a { font-weight: 700; }
.notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #e7f4ed;
  color: var(--success);
  font-size: 0.86rem;
  font-weight: 600;
}
.role-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
}
.role-badge--admin { background: #fbe4d9; color: var(--coral); }
.role-badge--user { background: var(--mint); color: var(--teal); }
.row-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.row-form select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 4px 7px;
  font: inherit;
  font-size: 0.8rem;
}
.row-form .btn-small { min-height: 34px; padding: 5px 10px; font-size: 0.78rem; }
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .form--grid { grid-template-columns: 1fr; }
  .form--grid label:last-of-type { grid-column: auto; }
  .form--grid .btn { width: 100%; }
  .row-form { margin-top: 6px; }
}

/* Solicitudes de inscripción */
.request-list { display: grid; gap: 12px; }
.request-card { display: grid; gap: 12px; }
.request-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.request-head h2 { margin: 2px 0 2px; font-size: 1.3rem; }
.request-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.request-grid > div { display: grid; gap: 2px; font-size: 0.86rem; }
.request-grid span { color: var(--ink-soft); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.request-grid a { overflow-wrap: anywhere; }
.request-wide { grid-column: span 2; }
.request-note { margin: 0; padding: 9px 11px; border-radius: 9px; background: #fcf8f0; font-size: 0.84rem; }
.request-actions { border-top: 1px solid var(--line); padding-top: 10px; }
.request-actions summary { cursor: pointer; color: var(--coral); font-size: 0.84rem; font-weight: 800; }
.request-actions .form { margin-top: 10px; }
.request-consents { margin: 10px 0 0; }
@media (max-width: 800px) {
  .request-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .request-grid { grid-template-columns: 1fr; }
  .request-wide { grid-column: auto; }
  .request-head { display: grid; }
}

/* Estados de suscripciones y renovaciones */
.status--pending { background: #fff0c2; color: #6b4e00; }
.status--active { background: #e7f4ed; color: var(--success); }
.status--due { background: #ffe8d6; color: #8a3c1c; }
.status--renewed { background: #e0ecff; color: #234b7a; }
.status--cancelled { background: #f0e9e4; color: #6b5548; }
.status--paused { background: #f0e9e4; color: #6b5548; }
.status--in_progress { background: var(--mint); color: var(--teal); }
.status--done { background: #e7f4ed; color: var(--success); }
.status--skipped { background: #f0e9e4; color: #6b5548; }

/* Multimedia */
.media-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.media-card { min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.media-card > img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--cream); }
.media-card__body { display: grid; gap: 7px; padding: 12px; }
.media-card__body p { margin: 0; font-size: 0.85rem; line-height: 1.4; }
.media-card__body small { color: var(--ink-soft); font-size: 0.76rem; }
.media-card__body form { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 900px) { .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .media-grid { grid-template-columns: 1fr; } }

.media-card__edit { border-top: 1px solid var(--line); padding-top: 8px; }
.media-card__edit summary { cursor: pointer; color: var(--coral); font-size: 0.8rem; font-weight: 800; }
.media-card__edit .form { margin-top: 8px; }
.media-card__edit .form label { font-size: 0.68rem; }
.media-card__edit .form input { padding: 7px 9px; font-size: 0.8rem; }

.media-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.media-heading h2 { margin: 0; }
@media (max-width: 520px) { .media-heading { align-items: start; flex-direction: column; } }

.media-card[draggable="true"] { cursor: grab; }
.media-card.is-dragging { opacity: 0.45; cursor: grabbing; }
.media-order-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.media-order-bar p { margin: 0; }
@media (max-width: 520px) { .media-order-bar { align-items: start; flex-direction: column; } }
.status--featured { background: var(--mint); color: var(--teal); }

.media-consent-check { display: flex; align-items: flex-start; gap: 8px; grid-column: 1 / -1; padding: 10px 12px; background: #fcf8f0; border: 1px solid var(--line); border-radius: 9px; font-size: 0.8rem; line-height: 1.45; color: var(--ink-soft); }
.media-consent-check input { margin-top: 3px; }

.media-alt-list { display: grid; gap: 8px; grid-column: 1 / -1; }
.media-alt-list[hidden] { display: none; }
.media-alt-list label { font-size: 0.72rem; }
.media-alt-list input { padding: 7px 9px; font-size: 0.8rem; }
