/* ── Variables (paleta cohesionada con landing y teoría) ── */
:root {
  --pri: #6366F1;
  --pri-d: #4F46E5;
  --pri-hover: #4F46E5;
  --pri-light: #EEF2FF;
  --pri-soft: rgba(99, 102, 241, 0.10);
  --pri-glow: rgba(99, 102, 241, 0.18);
  --grad-a: #6366F1;
  --grad-b: #8B5CF6;

  --bg: #F1F5F9;
  --bg-soft: #EEF2FF;
  --bg-panel: #ffffff;
  --bg-alt: #F8FAFC;
  --txt: #0F172A;
  --txt-soft: #64748B;
  --border: #E2E8F0;

  --primary: var(--pri);
  --primary-hover: var(--pri-d);

  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --danger-soft: #FEF2F2;
  --success: #16A34A;
  --success-light: #D1FAE5;

  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 20px rgba(99, 102, 241, 0.15);

  --radius: 12px;
  --topbar-h: 60px;
  --sidebar-w: 240px;

  --nav-side-bg: #111827;
  --nav-side-text: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] {
  --pri: #818CF8;
  --pri-d: #6366F1;
  --pri-hover: #6366F1;
  --pri-light: #1E1B4B;
  --pri-soft: rgba(129, 140, 248, 0.14);
  --pri-glow: rgba(129, 140, 248, 0.28);
  --grad-a: #6366F1;
  --grad-b: #A78BFA;

  --bg: #0B1220;
  --bg-soft: #111827;
  --bg-panel: #1E293B;
  --bg-alt: #172033;
  --txt: #E2E8F0;
  --txt-soft: #94A3B8;
  --border: #334155;

  --primary: var(--pri);
  --primary-hover: var(--pri-d);

  --danger: #F87171;
  --danger-light: rgba(248, 113, 113, 0.18);
  --danger-soft: rgba(248, 113, 113, 0.08);
  --success: #34D399;
  --success-light: rgba(52, 211, 153, 0.15);

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.45);

  --nav-side-bg: #0F172A;
  --nav-side-text: rgba(226, 232, 240, 0.85);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  display: flex; flex-direction: column;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  transition: background-color 0.2s, color 0.2s;
}
.hidden { display: none !important; }

/* Logo (mask, se colorea con currentColor) */
.brand-logo {
  width: 28px; height: 28px;
  display: inline-block;
  background: currentColor;
  -webkit-mask: url(/logo.svg) center / contain no-repeat;
          mask: url(/logo.svg) center / contain no-repeat;
  flex: 0 0 auto;
}
.brand-logo-lg { width: 64px; height: 64px; }

/* ─── Topbar ─── */
.topbar {
  display: flex; align-items: center; gap: 0.7rem;
  height: var(--topbar-h);
  padding: 0 0.8rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  z-index: 30;
  color: var(--txt);
}
.hamburger {
  background: none; border: 0; color: var(--txt);
  font-size: 1.5rem; cursor: pointer;
  padding: 0.35rem 0.5rem; line-height: 0;
  display: inline-flex; align-items: center;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--pri-d);
  text-decoration: none;
  font-weight: 700; font-size: 1.05rem;
  padding: 4px 10px; border-radius: 999px;
  background: var(--pri-soft);
  transition: background 0.15s;
}
.brand:hover { background: var(--pri-glow); }
.brand .brand-logo { width: 22px; height: 22px; }
.brand-name { letter-spacing: 0.3px; }

/* Nav Tests/Teoría */
.hdr-nav {
  display: none; align-items: center; gap: 4px;
  background: var(--bg-soft);
  padding: 4px; border-radius: 999px;
}
.nav-tab {
  padding: 5px 14px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 600;
  color: var(--txt-soft);
  cursor: pointer; user-select: none;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-tab:hover:not(.active) { color: var(--txt); background: rgba(0, 0, 0, 0.04); }
[data-theme="dark"] .nav-tab:hover:not(.active) { background: rgba(255, 255, 255, 0.08); }
.nav-tab.active {
  background: var(--pri); color: #fff;
  cursor: default; pointer-events: none;
}
@media (min-width: 640px) { .hdr-nav { display: inline-flex; } }

.search-wrap { flex: 1; min-width: 0; position: relative; }
#global-search {
  width: 100%; padding: 0.5rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-alt); color: var(--txt);
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#global-search:focus {
  outline: none; border-color: var(--pri);
  box-shadow: 0 0 0 4px var(--pri-glow);
}
.user-chip {
  display: flex; align-items: center; gap: 0.4rem;
  min-width: 0;
}
.user-btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: transparent; border: 0; padding: 4px 8px 4px 4px;
  border-radius: 999px; cursor: pointer; color: var(--txt);
  transition: background 0.15s;
}
.user-btn:hover { background: var(--bg-soft); }
.user-chip .avatar {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  color: #fff; font-weight: 700;
  border-radius: 50%; font-size: 0.95rem;
  user-select: none; flex: 0 0 auto;
}
.user-chip .user-name {
  font-weight: 600; max-width: 90px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: none;
}
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--bg-soft); color: var(--txt);
  border: 0; border-radius: 50%;
  cursor: pointer; padding: 0;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.btn-icon:hover { background: var(--pri-soft); color: var(--pri-d); }
.btn-icon.danger-icon:hover { background: var(--danger); color: #fff; }
.btn-icon:active { transform: scale(0.92); }

/* ─── Search results ─── */
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18);
  max-height: 70vh; overflow: auto;
  z-index: 50;
}
.search-results .item {
  padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border);
  cursor: pointer; color: var(--txt);
}
.search-results .item:last-child { border-bottom: 0; }
.search-results .item.label {
  background: var(--bg-soft); cursor: default;
  font-size: 0.7rem; letter-spacing: 0.05em;
  color: var(--txt-soft); text-transform: uppercase;
}
.search-results .item:not(.label):hover,
.search-results .item:not(.label):active { background: var(--pri-soft); }

/* ─── Sidebar (drawer en móvil) ─── */
.sidebar {
  position: fixed;
  top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--nav-side-bg); color: #fff;
  padding: 0.75rem 0.5rem;
  display: flex; flex-direction: column; gap: 0.2rem;
  transform: translateX(-100%);
  transition: transform 0.2s;
  z-index: 25;
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); }
.sidebar-backdrop {
  position: fixed; inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 24;
}
.nav-item {
  display: inline-flex; align-items: center; gap: 0.6rem;
  background: none; border: 0; color: var(--nav-side-text);
  padding: 0.7rem 0.85rem; border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover, .nav-item:active { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active {
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  color: #fff;
  pointer-events: none;
  cursor: default;
}
.nav-ico {
  width: 18px; height: 18px; flex: 0 0 auto;
}
.nav-sep {
  height: 1px; background: rgba(255, 255, 255, 0.08);
  margin: 0.5rem 0.4rem;
}

/* ─── Main ─── */
.content { padding: 1rem; flex: 1; min-width: 0; }
.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex; flex-direction: column;
  align-items: stretch; gap: 0.6rem; margin-bottom: 0.9rem;
}
.view-header h2 { margin: 0; font-size: 1.3rem; color: var(--txt); }
.view-header input[type=search] {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; background: var(--bg-panel); color: var(--txt);
}
.view-header input[type=search]:focus {
  outline: none; border-color: var(--pri);
  box-shadow: 0 0 0 4px var(--pri-glow);
}
.view-header .actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ─── Buttons (touch-friendly) ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem;
  min-height: 44px; padding: 0.55rem 1rem;
  border: 0; border-radius: var(--radius);
  font-size: 0.95rem; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
  color: var(--txt);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--txt); }
.btn-ghost:hover, .btn-ghost:active { background: var(--bg-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline {
  background: transparent; color: var(--danger);
  border: 1.5px solid var(--danger);
  min-height: 44px; padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.btn-danger-outline:hover { background: var(--danger); color: #fff; }
.btn-sm { min-height: 34px; padding: 0.35rem 0.7rem; font-size: 0.85rem; }

/* ─── Auth ─── */
.auth-card {
  background: var(--bg-panel); padding: 1.5rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  width: 100%; max-width: 380px;
  margin: 2rem auto;
  color: var(--txt);
}
.auth-hero { text-align: center; margin-bottom: 1rem; }
.auth-hero .brand-logo { color: var(--pri); margin: 0 auto 0.4rem; display: block; }
.auth-card h1 { text-align: center; margin: 0 0 0.2rem; color: var(--txt); }
.tagline {
  text-align: center; margin: 0.2rem 0 0.6rem;
  font-size: 1.05rem; font-weight: 600;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.auth-card label { display: block; margin-bottom: 0.75rem; color: var(--txt-soft); font-size: 0.85rem; font-weight: 600; }
.auth-card input {
  display: block; width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-top: 0.3rem; font-size: 1rem; font-family: inherit;
  background: var(--bg-panel); color: var(--txt);
}
.auth-card input:focus {
  outline: none; border-color: var(--pri);
  box-shadow: 0 0 0 4px var(--pri-glow);
}
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab {
  flex: 1; background: none; border: 0; padding: 0.7rem;
  cursor: pointer; color: var(--txt-soft); font-weight: 600;
  border-bottom: 2px solid transparent;
  min-height: 44px; font-family: inherit;
}
.tab.active { color: var(--pri); border-bottom-color: var(--pri); }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* ─── Stats ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem; margin: 1rem 0;
}
.stat-card {
  background: var(--bg-panel); padding: 0.9rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  text-align: center;
}
.stat-card .v {
  font-size: 1.55rem; font-weight: 700;
  color: var(--pri); line-height: 1.1;
}
.stat-card .l { color: var(--txt-soft); font-size: 0.85rem; }

/* ─── Action cards ─── */
.actions-grid {
  display: grid; grid-template-columns: 1fr;
  gap: 0.7rem; margin-top: 1rem;
}
.action-card {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1rem;
  box-shadow: var(--shadow);
  text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 0.35rem;
  min-height: 100px;
  color: var(--txt);
  font-family: inherit;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}
.action-card:hover { border-color: var(--pri); box-shadow: var(--shadow-md); }
.action-card:active { transform: scale(0.98); }
.action-card .ico { width: 28px; height: 28px; color: var(--pri); }
.action-card strong { font-size: 1.05rem; }
.action-card small { color: var(--txt-soft); }

/* ─── Listas ─── */
#tests-list { display: flex; flex-direction: column; gap: 0.55rem; }
.test-row {
  background: var(--bg-panel); padding: 0.85rem 1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--txt);
}
.test-row:hover { border-color: var(--pri); }
.test-row .titulo { font-weight: 600; word-break: break-word; }
.test-row .tags {
  grid-column: 2 / -1;
  display: flex; flex-wrap: wrap; gap: 0.3rem;
  min-width: 0;
}
.test-row .meta { color: var(--txt-soft); font-size: 0.78rem; white-space: nowrap; }
.test-row .star { font-size: 1.2rem; }

.question-list {
  list-style: none; padding: 0;
  display: flex; flex-direction: column; gap: 0.55rem;
}
.q-row {
  background: var(--bg-panel); padding: 0.85rem 1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  color: var(--txt);
}
.q-row .q-text { font-weight: 500; word-break: break-word; }
.q-row .q-meta { color: var(--txt-soft); font-size: 0.8rem; margin-top: 0.3rem; }
.q-row .q-actions {
  display: flex; gap: 0.3rem; margin-top: 0.5rem;
  justify-content: flex-end;
}

/* ─── Tags (contenedor y chip) ── */
.tags {
  display: flex; flex-wrap: wrap; gap: 0.3rem;
  min-width: 0; max-width: 100%;
}
.q-row .tags { margin-top: 0.4rem; }
.tag {
  background: var(--pri-soft); color: var(--pri-d);
  padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.tag.removable { cursor: default; display: inline-flex; align-items: center; gap: 0.25rem; }
.tag.removable .x {
  cursor: pointer; opacity: 0.55; font-weight: 700; line-height: 1;
  padding: 0 0.15rem;
}
.tag.removable .x:hover { opacity: 1; color: var(--danger); }

.quiz-tags-inline {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
  margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px dashed var(--border);
}

.buscar-tematico {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem;
  margin-top: 0.5rem; padding: 0.6rem 0.9rem;
  background: var(--bg-panel); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.buscar-tematico .small { font-size: 0.8rem; }
.buscar-tematico label { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--txt-soft); }
.buscar-tematico input[type=number] {
  padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 0.4rem;
  background: var(--bg-panel); color: var(--txt);
}
.quiz-tags-inline .muted.small { font-size: 0.75rem; }
.quiz-tags-inline #quiz-tag-add {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 0.25rem 0.7rem; font-size: 0.75rem;
  background: var(--bg-panel); color: var(--txt); outline: none;
  min-width: 9rem; max-width: 14rem;
}
.quiz-tags-inline #quiz-tag-add:focus { border-color: var(--pri); }

/* ─── Quiz ─── */
.quiz-header {
  background: var(--bg-panel); padding: 0.65rem 0.9rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; align-items: center;
  flex-wrap: wrap; gap: 0.4rem 0.9rem;
}
.quiz-header #quiz-title { font-weight: 600; flex: 1; min-width: 0; word-break: break-word; }
.quiz-card {
  background: var(--bg-panel); padding: 1.3rem 1.1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-top: 0.7rem;
  color: var(--txt);
}
.quiz-card #quiz-question { font-size: 1.1rem; line-height: 1.45; margin: 0; word-break: break-word; }
.quiz-timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--pri); }
.options { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1.2rem; }
.option-btn {
  background: var(--bg-alt); border: 1px solid var(--border);
  padding: 0.85rem 1rem; border-radius: var(--radius);
  text-align: left; cursor: pointer;
  font-size: 0.95rem; font-family: inherit;
  color: var(--txt);
  min-height: 50px;
  word-break: break-word;
  transition: background 0.12s, border-color 0.12s;
}
.option-btn:hover { background: var(--pri-soft); border-color: var(--pri); }
.option-btn.correct { background: var(--success-light); border-color: var(--success); color: var(--txt); }
.option-btn.wrong { background: var(--danger-light); border-color: var(--danger); color: var(--txt); }
.option-btn.disabled { pointer-events: none; opacity: 0.9; }
.explanation {
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.4);
  color: var(--txt);
  padding: 0.8rem 1rem;
  border-radius: var(--radius); margin-top: 1rem;
  word-break: break-word;
}
[data-theme="dark"] .explanation { background: rgba(251, 191, 36, 0.1); }
.quiz-actions { margin-top: 1.3rem; display: flex; gap: 0.45rem; flex-wrap: wrap; }
.quiz-actions > span { display: none; } /* spacer solo en desktop */

/* ─── Tiempo per-pregunta input ─── */
.tiempo-input-wrap {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: var(--bg-panel); padding: 0.35rem 0.7rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 44px;
  color: var(--txt);
}
.tiempo-input-wrap input {
  width: 64px; border: 0; background: transparent;
  font-size: 0.95rem; font-weight: 600; text-align: right;
  font-family: inherit; outline: none; color: var(--txt);
}

/* ─── Selects estilizados (mismo look que los inputs vistosos) ─── */
.select-styled, .orden-wrap select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 0.6rem 2.2rem 0.6rem 0.9rem;
  border: 1.5px solid var(--border); border-radius: 999px;
  background-color: var(--bg-panel); color: var(--txt);
  font-family: inherit; font-size: 0.9rem; font-weight: 500;
  min-height: 42px; cursor: pointer;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236366F1' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.select-styled:focus, .orden-wrap select:focus {
  outline: none; border-color: var(--pri);
  box-shadow: 0 0 0 4px var(--pri-glow);
}

/* ─── Etiquetas ─── */
.inline-form {
  display: flex; flex-direction: column;
  gap: 0.6rem; margin-bottom: 1rem;
}
.inline-form input, .inline-form select {
  padding: 0.7rem 0.95rem;
  border: 1.5px solid var(--border); border-radius: 999px;
  font-size: 0.95rem; font-family: inherit; width: 100%;
  background: var(--bg-panel); color: var(--txt);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.inline-form input:focus, .inline-form select:focus {
  outline: none; border-color: var(--pri);
  box-shadow: 0 0 0 4px var(--pri-glow);
}
.inline-form .select-styled { min-height: 46px; }
.etiquetas-list {
  list-style: none; padding: 0;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.etiqueta-row {
  background: var(--bg-panel); padding: 0.85rem 1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: start;
  gap: 0.5rem;
  color: var(--txt);
  max-width: 100%; overflow: hidden;
}
.etiqueta-row > div { min-width: 0; max-width: 100%; }
.etiqueta-row .nombre { font-weight: 600; word-break: break-word; }
.etiqueta-row .descripcion { color: var(--txt-soft); font-size: 0.85rem; word-break: break-word; }
.etiqueta-row .count {
  background: var(--bg-soft); color: var(--txt);
  padding: 0.2rem 0.55rem;
  border-radius: 999px; font-size: 0.78rem; white-space: nowrap;
}
.etiqueta-row button { padding: 0.3rem 0.55rem; min-height: 36px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); margin-top: 6px; flex: 0 0 auto; }
.dot.ok { background: var(--success); }

/* En móvil, la fila de etiqueta se compacta y las palabras clave envuelven bien */
@media (max-width: 500px) {
  .etiqueta-row {
    grid-template-columns: 12px 1fr;
    grid-template-areas:
      "dot cuerpo"
      "meta meta"
      "acciones acciones";
  }
  .etiqueta-row > .dot { grid-area: dot; }
  .etiqueta-row > div:not(.dot) { grid-area: cuerpo; }
  .etiqueta-row > .count { grid-area: meta; justify-self: start; }
  .etiqueta-row > button { grid-area: acciones; justify-self: end; }
  .etiqueta-row > .count + button { grid-column: 2; }
}

/* ─── Controles de listado de tests ─── */
.tests-controls {
  display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem;
  align-items: center;
  margin-bottom: 0.6rem;
}
.tests-controls .tag-chips { margin: 0; }
.orden-wrap {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.85rem; color: var(--txt-soft);
}

/* ─── Tag chips ─── */
.tag-chips {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  margin: 0 0 0.8rem;
}
.tag-chips .chip {
  background: var(--bg-panel); border: 1px solid var(--border);
  padding: 0.35rem 0.85rem; border-radius: 999px;
  font-size: 0.85rem; cursor: pointer; color: var(--txt);
  min-height: 34px; display: inline-flex; align-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.tag-chips .chip:hover:not(.active) { border-color: var(--pri); background: var(--pri-soft); }
.tag-chips .chip:active { transform: scale(0.95); }
.tag-chips .chip.active {
  background: var(--pri); color: #fff; border-color: var(--pri);
}

/* ─── Progreso ─── */
.por-test { list-style: none; padding: 0; }
.por-test li {
  background: var(--bg-panel); padding: 0.75rem 1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 0.5rem; word-break: break-word;
  color: var(--txt);
}

/* ─── Pagination ─── */
.pagination {
  display: flex; gap: 0.25rem; justify-content: center;
  flex-wrap: wrap; margin-top: 1rem;
}
.pagination .page {
  background: var(--bg-panel); border: 1px solid var(--border);
  padding: 0.4rem 0.65rem; border-radius: 0.5rem;
  cursor: pointer; min-width: 38px; min-height: 38px;
  color: var(--txt);
}
.pagination .page:hover { border-color: var(--pri); }
.pagination .page.active {
  background: var(--pri); color: #fff; border-color: var(--pri);
}

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 1rem;
  left: 1rem; right: 1rem;
  background: var(--txt); color: var(--bg);
  padding: 0.7rem 1rem; border-radius: var(--radius);
  text-align: center; z-index: 100; line-height: 1.3;
}

/* ─── Forms ─── */
textarea {
  width: 100%; min-height: 180px;
  padding: 0.7rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-family: monospace;
  font-size: 0.85rem;
  background: var(--bg-panel); color: var(--txt);
}
textarea:focus { outline: none; border-color: var(--pri); box-shadow: 0 0 0 4px var(--pri-glow); }
.muted { color: var(--txt-soft); font-size: 0.9rem; }
.actions { display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }

/* ─── Modal ─── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; z-index: 200;
  padding: 0.5rem;
}
.modal-card {
  background: var(--bg-panel); color: var(--txt);
  width: 100%; max-width: 560px;
  margin: auto;
  border-radius: var(--radius);
  max-height: 95vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; }
.modal form { padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.7rem; }
.modal label { display: block; font-weight: 600; }
.modal input, .modal textarea, .modal select {
  display: block; width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: 0.95rem;
  background: var(--bg-panel); color: var(--txt);
}
.modal input:focus, .modal textarea:focus, .modal select:focus {
  outline: none; border-color: var(--pri); box-shadow: 0 0 0 4px var(--pri-glow);
}
.modal textarea { font-family: monospace; font-size: 0.85rem; }
.modal-actions {
  display: flex; gap: 0.5rem; margin-top: 0.4rem; flex-wrap: wrap;
}

/* Gestión solo a quien tenga permisos */
body:not(.puede-gestionar) .gestion { display: none !important; }
body:not(.es-admin)         .solo-admin { display: none !important; }

/* ─── Usuarios ─── */
.usuarios-list {
  list-style: none; padding: 0;
  display: flex; flex-direction: column; gap: 0.55rem;
}
.usuarios-list .usuario-row {
  background: var(--bg-panel); padding: 0.85rem 1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 0.7rem; cursor: pointer;
  color: var(--txt);
}
.usuarios-list .avatar-row {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  color: #fff; font-weight: 700;
  border-radius: 50%; font-size: 1rem;
  user-select: none;
}
.usuarios-list .nombre { font-weight: 600; word-break: break-word; }
.usuarios-list .meta { color: var(--txt-soft); font-size: 0.8rem; }
.usuarios-list .roles-chips {
  display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.25rem;
}
.usuarios-list .role-chip {
  background: var(--pri-soft); color: var(--pri-d);
  padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem;
  font-weight: 600;
}
.usuarios-list .role-chip.admin { background: #fde68a; color: #92400e; }
[data-theme="dark"] .usuarios-list .role-chip.admin { background: rgba(253, 230, 138, 0.2); color: #fbbf24; }
.usuarios-list .inactivo { opacity: 0.55; }

.modal-body { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.9rem; }
.modal-body h4 { margin: 0; font-size: 0.85rem; color: var(--txt-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.modal-body .roles-grid {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
}
.modal-body .role-toggle {
  background: var(--bg-soft); border: 1px solid var(--border);
  color: var(--txt);
  padding: 0.45rem 0.85rem; border-radius: 999px;
  cursor: pointer; font-size: 0.9rem;
  min-height: 36px;
  font-family: inherit;
}
.modal-body .role-toggle.active {
  background: var(--pri); color: #fff; border-color: var(--pri);
}
.modal-body .input-row {
  display: flex; gap: 0.5rem; align-items: stretch; flex-wrap: wrap;
}
.modal-body .input-row input {
  flex: 1; min-width: 160px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: 0.95rem;
  background: var(--bg-panel); color: var(--txt);
}


/* ════════════════ TABLET (>= 600 px) ════════════════ */
@media (min-width: 600px) {
  .user-chip .user-name { display: inline; max-width: 140px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .actions-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .view-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
  }
  .view-header h2 { font-size: 1.4rem; flex: 1; min-width: 200px; }
  .inline-form {
    flex-direction: row; flex-wrap: wrap; align-items: stretch;
  }
  .inline-form input, .inline-form select { width: auto; flex: 1; min-width: 200px; }
}


/* ════════════════ DESKTOP (>= 900 px) ════════════════ */
@media (min-width: 900px) {
  body {
    display: grid;
    grid-template:
      "header header" var(--topbar-h)
      "side main" 1fr
      / var(--sidebar-w) 1fr;
  }
  .topbar {
    grid-area: header; position: sticky;
    padding: 0 1.5rem;
    gap: 1.2rem;
  }
  .brand-name { font-size: 1.05rem; }
  .search-wrap {
    flex: 0 1 480px;
    margin: 0 auto;
  }
  .user-chip {
    margin-left: auto;
    padding-left: 0.4rem;
  }
  .user-chip .user-name { max-width: 180px; }
  .hamburger { display: none; }
  .sidebar {
    grid-area: side;
    position: static;
    transform: none;
    height: auto;
  }
  .sidebar-backdrop { display: none !important; }
  .content { grid-area: main; padding: 1.5rem 2.5rem; max-width: none; overflow-x: hidden; }
  .quiz-actions > span { display: block; flex: 1; }
  .toast {
    left: 50%; right: auto;
    transform: translateX(-50%); bottom: 2rem;
    text-align: left; min-width: 240px;
  }
  .auth-card { margin-top: 3rem; padding: 2rem; }
}

/* ── Repaso espaciado ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  min-width: 1.4em;
  padding: 0.1em 0.45em;
  margin-left: 0.35em;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 0.75em;
  line-height: 1.3;
  font-weight: 600;
  text-align: center;
  vertical-align: middle;
}
.badge.calma { background: var(--txt-soft); }

/* ── Config modal ── */
.config-section h4 {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--txt-soft); margin-bottom: 10px;
}
.config-section + .config-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.config-section.danger-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.theme-toggle { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-option {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--bg-soft);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  color: var(--txt); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.theme-option input { display: none; }
.theme-option:has(input:checked) {
  background: var(--pri-soft);
  border-color: var(--pri);
  color: var(--pri-d);
  font-weight: 700;
}

/* Reset repasos: bien diferenciado del resto */
.reset-repasos {
  padding: 14px;
  border: 1.5px dashed var(--danger);
  border-radius: 12px;
  background: var(--danger-soft);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.reset-repasos-copy {
  display: flex; flex-direction: column; gap: 4px;
  flex: 1 1 220px; min-width: 0;
}
.reset-repasos-copy strong { font-size: 14px; color: var(--danger); }

/* Ritmo cards */
.ritmo-opciones {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.8rem;
}
.ritmo-card {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  background: var(--bg-panel);
  color: var(--txt);
  transition: border-color 0.15s, background 0.15s;
}
.ritmo-card:hover { border-color: var(--pri); }
.ritmo-card.active {
  border-color: var(--pri);
  background: var(--pri-soft);
}
.ritmo-card .titulo {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.ritmo-card .curva {
  font-size: 0.8rem;
  color: var(--txt-soft);
  margin-top: 0.3rem;
}
