/* ══════════════════════════════════════════════════════════════════════════
   UNED Dashboard — v2 Design System
   Palette:
     Primary blue  : #2563eb  (UNED-brand active)
     Danger/hard   : #dc2626
     Warning       : #e67e22
     Success/good  : #16a34a
     Accent purple : #7c3aed
     Accent teal   : #0891b2
     Neutral bg    : #f4f6fa
     Card bg       : #ffffff
     Border        : #e2e8f0
     Text primary  : #1e2d3d
     Text muted    : #64748b
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f4f6fa;
  color: #1e2d3d;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Site header ──────────────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1a3456 0%, #1e40af 60%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  position: relative;
  z-index: 10;
}

.header-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.header-logo {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.25));
}

.header-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.72);
  margin-top: 0.1rem;
}

.header-badge {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0.3rem 0.85rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
}

/* ── Sticky filters bar ───────────────────────────────────────────────── */
.filters-bar {
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 9;
}

.filters-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0.65rem 2rem;
  display: flex;
  align-items: center;
  gap: 1.4rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/* Pill-style segmented toggle */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.pill {
  padding: 0.28rem 0.75rem;
  border: 1.5px solid #cbd5e1;
  border-radius: 20px;
  background: transparent;
  color: #64748b;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  line-height: 1.3;
}

.pill:hover {
  border-color: #2563eb;
  color: #2563eb;
  background: #eff6ff;
}

.pill.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  box-shadow: 0 1px 4px rgba(37,99,235,0.25);
}

/* Año select */
.filter-select {
  padding: 0.32rem 0.65rem;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: #1e2d3d;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 150px;
}

.filter-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
  background: #fff;
}

.filter-status {
  margin-left: auto;
  font-size: 0.78rem;
  color: #94a3b8;
  font-style: italic;
}

/* ── Main content area ────────────────────────────────────────────────── */
.main-content {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

/* Two-column side-by-side layout */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.6rem;
}

@media (max-width: 1024px) {
  .two-col-grid { grid-template-columns: 1fr; }
}

/* ── Generic section block (card) ─────────────────────────────────────── */
.section-block {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  padding: 1.5rem 1.75rem;
  border: 1px solid #e2e8f0;
}

.section-header {
  margin-bottom: 1.1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid #f1f5f9;
}

.section-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: #1e2d3d;
  margin-bottom: 0.18rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.section-desc {
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.45;
}

/* ── KPI cards ────────────────────────────────────────────────────────── */
#kpiSection {
  background: transparent;
  box-shadow: none;
  border: none;
  padding: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  padding: 1.1rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.15s;
}

.kpi-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

/* Top accent border */
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--kpi-accent, #2563eb);
  border-radius: 12px 12px 0 0;
}

.kpi-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: 0.1rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--kpi-accent, #1e2d3d);
}

.kpi-sub {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.3;
}

.kpi-card.skeleton .kpi-value { color: #d0d9e5; }

/* ── Chart wrap variants ──────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  width: 100%;
  max-height: 460px;
}

.chart-wrap canvas { max-height: 460px; }

.chart-wrap-md {
  max-height: 340px;
}
.chart-wrap-md canvas { max-height: 340px; }

.chart-wrap-sq {
  max-height: 400px;
}
.chart-wrap-sq canvas { max-height: 400px; }

.chart-wrap-sm {
  max-height: 220px;
}
.chart-wrap-sm canvas { max-height: 220px; }

/* ── Ranking table ────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.ranking-table thead th {
  background: #f8fafc;
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  overflow: visible;
  position: relative;
}

.ranking-table thead th.sortable { cursor: pointer; user-select: none; }
.ranking-table thead th.sortable:hover { color: #2563eb; background: #eff6ff; }

.sort-arrow {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-left: 0.1rem;
}

.ranking-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.13s;
}

.ranking-table tbody tr:hover { background: #f8fafc; }

.ranking-table tbody tr.row-expanded { background: #eff6ff; }

.ranking-table tbody td {
  padding: 0.65rem 0.75rem;
  vertical-align: middle;
}

/* Rank badge */
.rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: 0.76rem;
  font-weight: 700;
  background: #f1f5f9;
  color: #64748b;
}

.rank-num.top-3 {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #78350f;
  box-shadow: 0 1px 4px rgba(245,158,11,0.35);
}

/* Name + curso dot */
.name-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.curso-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.subj-name {
  font-weight: 600;
  color: #1e2d3d;
  line-height: 1.3;
}

.subj-headline {
  font-size: 0.76rem;
  color: #64748b;
  margin-top: 0.18rem;
  font-style: italic;
  line-height: 1.35;
}

/* Curso badge */
.curso-badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
}

/* Difficulty bar */
.diff-cell { min-width: 130px; }

.diff-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.28rem;
}

.diff-bar-bg {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
  min-width: 50px;
}

.diff-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.35s ease;
}

.diff-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1e2d3d;
  min-width: 2.2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Severity colors */
.sev-low  { background: #16a34a; }
.sev-mid  { background: #e67e22; }
.sev-high { background: #dc2626; }

.sev-text-low  { color: #16a34a; }
.sev-text-mid  { color: #e67e22; }
.sev-text-high { color: #dc2626; }

/* Severity badges (in table) */
.sev-badge {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.sev-badge-low  { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.sev-badge-mid  { background: #ffedd5; color: #c2410c; border: 1px solid #fed7aa; }
.sev-badge-high { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* Percentage cells */
.pct-cell {
  font-size: 0.84rem;
  font-weight: 500;
  color: #1e2d3d;
  white-space: nowrap;
}

.tabnum { font-variant-numeric: tabular-nums; }

/* Column widths */
.col-rank { width: 2.5rem; }
.col-curso { width: 4rem; }

/* Expanded factors row */
.factors-row td {
  background: #f8fafc;
  padding: 0.5rem 0.75rem 0.85rem 2rem;
  border-top: none;
  cursor: default;
}
.factors-row:hover { background: #f8fafc !important; }

.factors-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.4rem;
}

.factor-chip {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.4rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.32rem 0.6rem;
  font-size: 0.77rem;
  line-height: 1.4;
  max-width: 320px;
}

.factor-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.28rem;
}

.factor-text { color: #3d4f63; }

/* ── Insights grid ────────────────────────────────────────────────────── */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 1rem;
}

.insight-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.insight-card-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
}

.insight-icon { font-size: 1.25rem; line-height: 1; }

.insight-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e2d3d;
}

.insight-desc {
  font-size: 0.74rem;
  color: #64748b;
  margin-top: -0.2rem;
  margin-bottom: 0.35rem;
  line-height: 1.4;
}

.insight-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.insight-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.28rem 0.5rem;
  background: #fff;
  border-radius: 7px;
  border: 1px solid #eef2f7;
  font-size: 0.79rem;
}

.insight-item-name {
  color: #1e2d3d;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.insight-item-anio {
  font-size: 0.7rem;
  color: #94a3b8;
  white-space: nowrap;
}

.insight-item-val {
  font-weight: 700;
  font-size: 0.83rem;
  white-space: nowrap;
  min-width: 3.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.val-danger  { color: #dc2626; }
.val-warning { color: #e67e22; }
.val-info    { color: #0891b2; }
.val-purple  { color: #7c3aed; }
.val-good    { color: #16a34a; }

/* ── Chat section ─────────────────────────────────────────────────────── */
.chat-section { border-top: 4px solid #2563eb; }

#historial {
  max-height: 520px;
  overflow-y: auto;
  margin-bottom: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.2rem 0;
}

.msg {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.msg.user { flex-direction: row-reverse; }

.avatar {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  line-height: 2rem;
  text-align: center;
  font-size: 1rem;
  border-radius: 50%;
  background: #e8eef6;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.bubble {
  max-width: 78%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
}

.msg.user .bubble {
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(37,99,235,0.22);
}

.msg.bot .bubble {
  background: #f4f7fb;
  border-left: 4px solid #2563eb;
  border-bottom-left-radius: 4px;
  color: #1e2d3d;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.bubble.error-bubble {
  background: #fef2f2;
  border-left-color: #dc2626;
  color: #dc2626;
}

.bubble.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.65rem 1rem;
  min-width: 3.5rem;
}

.bubble.typing-indicator span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #2563eb;
  border-radius: 50%;
  opacity: 0.4;
  animation: bounce 1.2s infinite ease-in-out;
}
.bubble.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.bubble.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.bubble.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* Markdown inside bot bubbles */
.msg.bot .bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  margin: 0.6rem 0;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.msg.bot .bubble th,
.msg.bot .bubble td { border: 1px solid #e2e8f0; padding: 0.32rem 0.55rem; text-align: left; }
.msg.bot .bubble th { background: #eff6ff; font-weight: 700; color: #1e40af; }
.msg.bot .bubble tr:nth-child(even) td { background: #f8fafc; }
.msg.bot .bubble strong { color: #1e2d3d; font-weight: 700; }
.msg.bot .bubble h1, .msg.bot .bubble h2,
.msg.bot .bubble h3, .msg.bot .bubble h4 { margin: 0.55rem 0 0.28rem; color: #1e40af; line-height: 1.3; }
.msg.bot .bubble h1 { font-size: 1.05rem; }
.msg.bot .bubble h2 { font-size: 0.98rem; }
.msg.bot .bubble h3, .msg.bot .bubble h4 { font-size: 0.92rem; }
.msg.bot .bubble p { margin: 0.28rem 0; }
.msg.bot .bubble p:first-child { margin-top: 0; }
.msg.bot .bubble p:last-child  { margin-bottom: 0; }
.msg.bot .bubble ul, .msg.bot .bubble ol { margin: 0.28rem 0 0.28rem 1.2rem; padding: 0; }
.msg.bot .bubble li { margin: 0.18rem 0; }
.msg.bot .bubble code { background: #eff6ff; padding: 0.1em 0.32em; border-radius: 4px; font-size: 0.86em; font-family: "Consolas", "Menlo", monospace; }
.msg.bot .bubble pre { background: #1e2937; color: #e2e8f0; padding: 0.7rem 0.9rem; border-radius: 8px; overflow-x: auto; font-size: 0.84em; margin: 0.45rem 0; }
.msg.bot .bubble pre code { background: none; padding: 0; color: inherit; }
.msg.bot .bubble hr { border: none; border-top: 1px solid #e2e8f0; margin: 0.55rem 0; }

/* Chat form */
.chat-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.chat-input {
  flex: 1;
  padding: 0.55rem 0.85rem;
  border: 1.5px solid #cbd5e1;
  border-radius: 9px;
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  background: #f8fafc;
  color: #1e2d3d;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
  background: #fff;
}

.chat-btn {
  padding: 0.55rem 1.25rem;
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: #fff;
  border: 0;
  border-radius: 9px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.chat-btn:hover  { opacity: 0.88; }
.chat-btn:active { transform: scale(0.97); }

/* ── Loading / empty states ───────────────────────────────────────────── */
.loading-msg {
  text-align: center;
  color: #94a3b8;
  font-size: 0.86rem;
  padding: 2rem;
}

/* ── Site footer ──────────────────────────────────────────────────────── */
.site-footer {
  background: #f1f5f9;
  border-top: 1px solid #e2e8f0;
  margin-top: 1rem;
}
.footer-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0.85rem 2rem;
  font-size: 0.77rem;
  color: #94a3b8;
  text-align: center;
}

/* ── Tooltip system ───────────────────────────────────────────────────── */
.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05em;
  height: 1.05em;
  font-size: 0.75rem;
  font-style: normal;
  font-weight: 700;
  color: #94a3b8;
  border: 1.5px solid #cbd5e1;
  border-radius: 50%;
  line-height: 1;
  cursor: default;
  vertical-align: middle;
  margin-left: 0.3em;
  flex-shrink: 0;
  position: relative;
  isolation: isolate;
  z-index: 0;
  transition: color 0.13s, border-color 0.13s;
  transform: translateZ(0);
}

.info:hover, .info:focus {
  color: #2563eb;
  border-color: #2563eb;
  outline: none;
}

.info::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e2d3d;
  color: #f0f4f8;
  font-size: 0.74rem;
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  min-width: 140px;
  padding: 0.45rem 0.65rem;
  border-radius: 7px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.13s, visibility 0.13s;
  text-align: left;
}

.info::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1e2d3d;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.13s, visibility 0.13s;
}

.info:hover::after, .info:focus::after,
.info:hover::before, .info:focus::before {
  opacity: 1;
  visibility: visible;
}

/* Flip: below */
.info.tip-below::after  { bottom: auto; top: calc(100% + 7px); }
.info.tip-below::before { bottom: auto; top: calc(100% + 1px); border-top-color: transparent; border-bottom-color: #1e2d3d; }

/* Align left */
.info.tip-left::after  { left: 0; transform: translateX(0); }
.info.tip-left::before { left: 0.5rem; transform: translateX(0); }

/* Align right */
.info.tip-right::after  { left: auto; right: 0; transform: translateX(0); }
.info.tip-right::before { left: auto; right: 0.5rem; transform: translateX(0); }

.ranking-table thead th { overflow: visible; }

/* ── Titulación summary panel ─────────────────────────────────────────── */
.titulacion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(295px, 1fr));
  gap: 1rem;
}

.tit-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.tit-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e40af;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.45rem;
}

.tit-metrics {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  font-size: 0.81rem;
}

.tit-metrics dt {
  color: #64748b;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.22rem;
}

.tit-metrics dd {
  font-weight: 700;
  color: #1e2d3d;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tit-null-cap {
  font-weight: 400;
  font-size: 0.71rem;
  color: #94a3b8;
  font-style: italic;
}

/* ── Per-asignatura detail panel (row expand) ─────────────────────────── */
.detail-expand-row td {
  background: #f4f8ff;
  padding: 0 0.75rem 0.75rem 0.75rem;
  cursor: default;
  border-top: none;
}

.detail-expand-row:hover { background: #f4f8ff !important; }

.detail-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  padding: 0.5rem 0;
}

.detail-section {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.75rem 0.95rem;
  min-width: 210px;
  flex: 1 1 210px;
  max-width: 360px;
}

.detail-section-hdr {
  font-size: 0.74rem;
  font-weight: 700;
  color: #1e40af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.detail-dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.7rem;
  font-size: 0.79rem;
}

.detail-dl dt {
  color: #64748b;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.22rem;
}

.detail-dl dd {
  font-weight: 600;
  color: #1e2d3d;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Stacked grade bar */
.grade-bar-wrap {
  display: flex;
  height: 9px;
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 0.55rem;
  background: #e2e8f0;
}

.grade-bar-seg {
  height: 100%;
  min-width: 2px;
  transition: width 0.3s;
}

/* ── Encuestas section ────────────────────────────────────────────────── */
.encuesta-subsection { margin-bottom: 1.3rem; }

.encuesta-sub-hdr {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1e40af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.corr-list { display: flex; flex-direction: column; gap: 0.4rem; }

.corr-item {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  font-size: 0.83rem;
}

.corr-badge {
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.1em 0.5em;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

.corr-green { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.corr-red   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.corr-blue  { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.corr-texto { color: #3d4f63; line-height: 1.4; flex: 1; }

/* Aspectos grid */
.encuesta-aspectos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
}

@media (max-width: 768px) { .encuesta-aspectos { grid-template-columns: 1fr; } }

.aspecto-col {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.85rem 0.95rem;
}

.aspecto-hdr-green { color: #166534; }
.aspecto-hdr-red   { color: #991b1b; }

.aspecto-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.aspecto-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.3rem 0.5rem;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #eef2f7;
  font-size: 0.79rem;
}

.aspecto-text {
  color: #1e2d3d;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.aspecto-media {
  font-weight: 700;
  font-size: 0.79rem;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.aspecto-media-green { color: #16a34a; }
.aspecto-media-red   { color: #dc2626; }

/* ── Per-asignatura survey & evolucion (inside expand row) ────────────── */
.detail-section-wide { flex: 1 1 100%; max-width: 100%; }

.encuesta-global-val {
  font-size: 0.87rem;
  font-weight: 700;
  color: #1e2d3d;
  margin-bottom: 0.65rem;
}

/* Radar chart wrap */
.radar-wrap {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto 0.8rem;
}

.radar-wrap canvas { max-height: 300px; }

.encuesta-items-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  margin-bottom: 0.75rem;
}

.encuesta-item-row {
  display: grid;
  grid-template-columns: 1fr 120px 2.8rem;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
}

.encuesta-item-label {
  color: #3d4f63;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.encuesta-item-bar-outer {
  height: 7px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.encuesta-item-bar-inner {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.encuesta-item-val {
  font-size: 0.76rem;
  font-weight: 700;
  color: #1e2d3d;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.encuesta-com-hdr {
  font-size: 0.74rem;
  font-weight: 700;
  color: #1e40af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.encuesta-com-box {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  padding: 0.45rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.encuesta-com-entry {
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 0.45rem;
  font-size: 0.79rem;
}
.encuesta-com-entry:last-child { border-bottom: none; padding-bottom: 0; }

.encuesta-com-pregunta { font-weight: 700; color: #1e40af; margin-bottom: 0.18rem; }
.encuesta-com-texto    { color: #3d4f63; line-height: 1.45; }

/* ── Heatmap (CSS grid, no plugin) ───────────────────────────────────── */
.heatmap-grid {
  display: grid;
  gap: 3px;
  margin-bottom: 0.75rem;
  overflow-x: auto;
}

.heatmap-corner { /* empty top-left cell */
  background: transparent;
}

.heatmap-col-hdr {
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  text-align: center;
  padding: 0.3rem 0.2rem 0.1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.heatmap-row-hdr {
  font-size: 0.73rem;
  font-weight: 600;
  color: #1e2d3d;
  padding: 0.2rem 0.55rem 0.2rem 0;
  white-space: nowrap;
  align-self: center;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.heatmap-cell {
  border-radius: 6px;
  padding: 0.45rem 0.3rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 52px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.12s;
}

.heatmap-cell:hover { filter: brightness(0.92); cursor: default; }

.heatmap-empty {
  background: #f1f5f9;
  color: #cbd5e1;
  border: 1px dashed #e2e8f0;
  border-radius: 6px;
  min-width: 52px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.45rem;
}

.heatmap-legend-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.heatmap-legend-entry {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  font-size: 0.73rem;
  color: #64748b;
}

.heatmap-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-inner { padding: 0.75rem 1rem; }
  .header-badge { display: none; }
  .filters-inner { padding: 0.55rem 1rem; gap: 0.65rem; }
  .filter-status { display: none; }
  .main-content { padding: 0.9rem; gap: 1.1rem; }
  .section-block { padding: 1rem 0.9rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .insights-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 92%; }
  .pill { padding: 0.22rem 0.55rem; font-size: 0.74rem; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 1.6rem; }
  .ranking-table { font-size: 0.77rem; }
}
