/* ================================================================
   FEIA - Universidades Ecuador  |  Main Stylesheet
   ================================================================ */

:root {
  /* Brand */
  --feia-blue:      #0047AB;
  --feia-blue-dark: #003080;
  --feia-gold:      #F5A623;
  --feia-green:     #1B8A4C;

  /* Neutrals */
  --bg:          #F0F4F8;
  --surface:     #FFFFFF;
  --surface2:    #F8FAFC;
  --border:      #E2E8F0;
  --text:        #1E293B;
  --text-muted:  #64748B;
  --text-light:  #94A3B8;

  /* Semantic */
  --success:  #16A34A;
  --warning:  #D97706;
  --error:    #DC2626;
  --info:     #0891B2;

  /* Radii & Shadows */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);

  /* Transitions */
  --t: 220ms ease;
}

/* Dark mode */
[data-theme="dark"] {
  --bg:         #0F172A;
  --surface:    #1E293B;
  --surface2:   #172032;
  --border:     #334155;
  --text:       #F1F5F9;
  --text-muted: #94A3B8;
  --text-light: #64748B;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 16px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--t), color var(--t);
}
img { max-width: 100%; display: block; }
a  { color: var(--feia-blue); text-decoration: none; }

/* ── Typography ─────────────────────────────────────────────── */
h1 { font-size: clamp(1.5rem, 3vw, 2rem);   font-weight: 700; line-height: 1.2; }
h2 { font-size: clamp(1.1rem, 2vw, 1.35rem); font-weight: 700; line-height: 1.3; }
h3 { font-size: 1rem;  font-weight: 600; }
h4 { font-size: .9rem; font-weight: 600; }
small { font-size: .8rem; }

/* ── Layout ─────────────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 0 1.5rem; }

/* ── Topbar ─────────────────────────────────────────────────── */
#topbar {
  background: linear-gradient(135deg, var(--feia-blue-dark), var(--feia-blue));
  color: #fff;
  position: sticky; top: 0; z-index: 1000;
  box-shadow: 0 2px 10px rgba(0,0,80,.25);
}
#topbar .inner {
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.5rem; max-width: 1400px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--feia-gold); display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.1rem; color: var(--feia-blue-dark);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 1rem; font-weight: 800; color: #fff; }
.brand-sub  { font-size: .65rem; color: rgba(255,255,255,.75); letter-spacing: .05em; }

.topbar-nav { display: flex; gap: .25rem; margin-left: 1rem; }
.topbar-nav a {
  color: rgba(255,255,255,.8); font-size: .85rem; padding: .35rem .75rem;
  border-radius: 6px; transition: background var(--t), color var(--t);
}
.topbar-nav a:hover, .topbar-nav a.active {
  background: rgba(255,255,255,.15); color: #fff;
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
#global-search-wrap { position: relative; }
#global-search {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 30px; padding: .35rem 1rem .35rem 2.2rem;
  font-size: .85rem; width: 220px; outline: none; transition: var(--t);
}
#global-search::placeholder { color: rgba(255,255,255,.6); }
#global-search:focus { background: rgba(255,255,255,.22); width: 260px; }
.search-icon {
  position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,.7); pointer-events: none;
}
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 320px; overflow-y: auto; z-index: 2000; display: none;
}
#search-results .sr-item {
  padding: .6rem 1rem; cursor: pointer; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem; font-size: .85rem;
  transition: background var(--t);
}
#search-results .sr-item:last-child { border-bottom: none; }
#search-results .sr-item:hover { background: var(--bg); }
.sr-badge {
  font-size: .7rem; padding: .15rem .45rem; border-radius: 20px; font-weight: 600;
  white-space: nowrap;
}
.sr-badge.universidad { background: #DBEAFE; color: #1D4ED8; }
.sr-badge.carrera     { background: #D1FAE5; color: #065F46; }

#btn-theme {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  border-radius: 8px; padding: .4rem .6rem; cursor: pointer; font-size: .9rem;
  transition: background var(--t);
}
#btn-theme:hover { background: rgba(255,255,255,.25); }

/* ── Hero Banner ─────────────────────────────────────────────── */
#hero {
  background: linear-gradient(160deg, var(--feia-blue) 0%, #0d6efd 50%, var(--feia-green) 100%);
  color: #fff; padding: 2.5rem 1.5rem 1.5rem;
  position: relative; overflow: hidden;
}
#hero::before {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
#hero .container { position: relative; }
#hero h1 { font-size: clamp(1.4rem, 3vw, 2.2rem); margin-bottom: .4rem; }
#hero p  { font-size: .95rem; opacity: .85; max-width: 560px; }
.hero-meta {
  display: flex; gap: 1.5rem; margin-top: .9rem; flex-wrap: wrap;
}
.hero-meta span { font-size: .8rem; opacity: .8; display: flex; align-items: center; gap: .3rem; }

/* ── Stat Cards ─────────────────────────────────────────────── */
#stats-row {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin: 1.5rem 0;
}
.stat-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent; transition: var(--t);
  position: relative; overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-clickable { cursor: pointer; }
.stat-clickable:hover .sc-hint { opacity: 1; }
.sc-hint { font-size: .68rem; color: var(--feia-blue); margin-top: .3rem; opacity: 0; transition: opacity .2s; }
.stat-card .sc-icon {
  font-size: 1.6rem; margin-bottom: .4rem;
}
.stat-card .sc-value {
  font-size: 1.7rem; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-card .sc-label { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
.stat-card .sc-sub   { font-size: .72rem; color: var(--text-light); margin-top: .4rem; }
.sc-niveles { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .45rem; }
.sc-nivel-badge {
  font-size: .64rem; font-weight: 600; padding: .1rem .35rem;
  border-radius: 3px; white-space: nowrap; line-height: 1.5;
}
.sc-nivel-grado     { background: #7C3AED18; color: #7C3AED; border: 1px solid #7C3AED44; }
.sc-nivel-maestria  { background: #05966918; color: #059669; border: 1px solid #05966944; }
.sc-nivel-doctorado { background: #D9770618; color: #D97706; border: 1px solid #D9770644; }

/* ── Section Headers ─────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: .5rem; flex-wrap: wrap;
}
.section-title { font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.section-title span { font-size: 1.1rem; }

/* ── Filter Bar ─────────────────────────────────────────────── */
#filter-bar {
  background: var(--surface); border-radius: var(--radius);
  padding: 1rem 1.2rem; margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: .3rem; flex: 1; min-width: 140px; }
.filter-group label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.filter-group select,
.filter-group input {
  padding: .45rem .7rem; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-size: .85rem; outline: none; transition: var(--t);
}
.filter-group select:focus,
.filter-group input:focus { border-color: var(--feia-blue); box-shadow: 0 0 0 3px rgba(0,71,171,.1); }
.btn-reset {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 8px; padding: .45rem 1rem; cursor: pointer; font-size: .83rem;
  transition: var(--t); white-space: nowrap; align-self: flex-end;
}
.btn-reset:hover { border-color: var(--error); color: var(--error); }

/* ── Grid Layouts ─────────────────────────────────────────────── */
.grid-2 { display: grid; gap: 1.25rem; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 1.25rem; grid-template-columns: 1fr 1fr 1fr; }
.grid-1-2 { display: grid; gap: 1.25rem; grid-template-columns: 1fr 2fr; }
.grid-2-1 { display: grid; gap: 1.25rem; grid-template-columns: 2fr 1fr; }

/* ── Card ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 1.2rem;
  transition: var(--t);
}
.card:hover { box-shadow: var(--shadow); }
.card-title {
  font-size: .85rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: .9rem;
  display: flex; align-items: center; gap: .4rem;
}

.btn-toggle-sm {
  font-size: .65rem; font-weight: 600; padding: .2rem .55rem;
  border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text-muted);
  cursor: pointer; white-space: nowrap; line-height: 1.4;
  transition: background .15s, color .15s;
}
.btn-toggle-sm:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Charts ─────────────────────────────────────────────────── */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; }

/* ── Map ─────────────────────────────────────────────────────── */
#map-ecuador {
  height: 420px; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
.leaflet-container { font-family: inherit; }

/* ── Data Table ─────────────────────────────────────────────── */
.data-table-wrap {
  overflow-x: auto; overflow-y: auto;
  max-height: calc(100vh - 190px);
  border-radius: var(--radius-sm);
}
.data-table {
  width: 100%; min-width: 680px; border-collapse: collapse; font-size: .84rem;
}
.data-table th {
  padding: .6rem .8rem; text-align: left;
  background: var(--bg); color: var(--text-muted);
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 2px solid var(--feia-blue); white-space: nowrap;
  cursor: pointer; user-select: none;
  position: sticky; top: 0; z-index: 5;
  box-shadow: 0 2px 4px rgba(0,0,0,.08);
}
.data-table th:hover { color: var(--feia-blue); }
.data-table th .sort-arrow { opacity: .4; margin-left: .2rem; }
.data-table th.sorted .sort-arrow { opacity: 1; color: var(--feia-blue); }
.data-table td {
  padding: .55rem .8rem; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.data-table .rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: .7rem; font-weight: 800;
}
.rank-1 { background: #FFD700; color: #78350F; }
.rank-2 { background: #C0C0C0; color: #374151; }
.rank-3 { background: #CD7F32; color: #fff; }
.rank-n { background: var(--bg); color: var(--text-muted); }

/* ── Progress bar ─────────────────────────────────────────────── */
.progress-bar-wrap { background: var(--bg); border-radius: 4px; height: 6px; overflow: hidden; min-width: 60px; }
.progress-bar { height: 100%; border-radius: 4px; transition: width .6s ease; }

/* ── Area Badge ─────────────────────────────────────────────── */
.area-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .55rem; border-radius: 20px; font-size: .72rem; font-weight: 600;
}
.area-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── University Card ─────────────────────────────────────────── */
.uni-cards-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.uni-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 1rem;
  cursor: pointer; transition: var(--t);
  position: relative; overflow: hidden;
}
.uni-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: var(--feia-blue); border-radius: 4px 0 0 4px;
}
.uni-card.publico::before { background: var(--feia-green); }
.uni-card.cofinanciado::before { background: var(--feia-gold); }
.uni-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--feia-blue); }
.uni-card-name { font-weight: 700; font-size: .88rem; margin-bottom: .4rem; line-height: 1.3; }
.uni-card-meta { font-size: .77rem; color: var(--text-muted); display: flex; gap: .8rem; flex-wrap: wrap; }
.uni-card-stats {
  display: flex; gap: .6rem; margin-top: .7rem; flex-wrap: wrap;
}
.uni-chip {
  background: var(--bg); border-radius: 6px; padding: .25rem .5rem;
  font-size: .73rem; font-weight: 600; color: var(--text-muted);
  display: flex; align-items: center; gap: .25rem;
}

/* ── Modal ─────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 3000; display: none; align-items: flex-start;
  justify-content: center; padding: 2rem 1rem; overflow-y: auto;
}
#modal-overlay.open { display: flex; }
#modal-box {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 760px; box-shadow: var(--shadow-lg);
  position: relative; animation: slideUp .25s ease;
}
@keyframes slideUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:none; } }
#modal-close {
  position: absolute; right: 1rem; top: 1rem;
  background: var(--bg); border: none; border-radius: 50%;
  width: 32px; height: 32px; font-size: 1.1rem; cursor: pointer;
  color: var(--text-muted); display: flex; align-items: center; justify-content: center;
  transition: var(--t);
}
#modal-close:hover { background: var(--error); color: #fff; }
#modal-header {
  padding: 1.4rem 1.4rem .8rem;
  border-bottom: 1px solid var(--border);
}
#modal-body { padding: 1.2rem 1.4rem 1.4rem; }
.modal-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.modal-tab {
  padding: .5rem 1rem; border: none; background: none; cursor: pointer;
  font-size: .83rem; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent;
  transition: var(--t);
}
.modal-tab.active { color: var(--feia-blue); border-bottom-color: var(--feia-blue); }

/* ── Tabs (main) ─────────────────────────────────────────────── */
.view-tabs { display: flex; gap: .3rem; flex-wrap: wrap; }
.view-tab {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 8px; padding: .4rem .9rem;
  font-size: .82rem; font-weight: 600; cursor: pointer; transition: var(--t);
}
.view-tab.active {
  background: var(--feia-blue); color: #fff; border-color: var(--feia-blue);
}

/* ── Comparador ─────────────────────────────────────────────── */
#comparador-select {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem;
}
.comp-tag {
  display: flex; align-items: center; gap: .4rem;
  background: #DBEAFE; color: #1D4ED8; border-radius: 20px;
  padding: .25rem .6rem .25rem .8rem; font-size: .8rem; font-weight: 600;
}
.comp-tag button {
  background: none; border: none; cursor: pointer; color: #1D4ED8;
  display: flex; align-items: center; padding: 0;
}

/* ── PND Alignment ─────────────────────────────────────────── */
.pnd-card {
  background: linear-gradient(135deg, #F0FDF4, #DCFCE7);
  border: 1px solid #BBF7D0; border-radius: var(--radius); padding: 1rem;
}
[data-theme="dark"] .pnd-card {
  background: linear-gradient(135deg, #052e16, #14532d);
  border-color: #166534;
}
.pnd-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--feia-green); color: #fff;
  border-radius: 20px; padding: .2rem .6rem; font-size: .73rem; font-weight: 700;
}

/* ── Loader ─────────────────────────────────────────────────── */
.loader {
  display: flex; align-items: center; justify-content: center;
  gap: .5rem; padding: 2rem; color: var(--text-muted); font-size: .9rem;
}
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--feia-blue); border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  background: var(--text); color: var(--surface);
  border-radius: var(--radius); padding: .7rem 1.2rem;
  font-size: .85rem; box-shadow: var(--shadow-lg);
  transform: translateY(80px); opacity: 0;
  transition: transform .3s ease, opacity .3s ease;
  max-width: 320px;
}
#toast.show { transform: none; opacity: 1; }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .grid-1-2, .grid-2-1 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar-nav { display: none; }
  #global-search { width: 160px; }
  #global-search:focus { width: 190px; }
  #hero { padding: 1.5rem 1rem 1rem; }
  .section-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
  #stats-row { grid-template-columns: 1fr 1fr; }
  .stat-card .sc-value { font-size: 1.4rem; }
}

/* ── Page sections ─────────────────────────────────────────── */
.page-section { display: none; }
.page-section.active { display: block; }

/* ── Stat Detail Modal ───────────────────────────────────────── */
#stat-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.65); backdrop-filter: blur(2px);
  z-index: 2000;
  align-items: flex-start; justify-content: center;
  padding: 2rem 1rem; overflow-y: auto;
}
#stat-modal-overlay.open { display: flex; }
#stat-modal-box {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: 0 25px 70px rgba(0,0,0,.35); width: 100%; max-width: 950px;
  padding: 0; position: relative; overflow: hidden;
  animation: statModalIn .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes statModalIn { from { opacity:0; transform:translateY(16px) scale(.98); } to { opacity:1; transform:none; } }
#stat-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0; padding: 1.3rem 1.6rem;
  background: linear-gradient(120deg, var(--feia-blue), var(--feia-blue-dark));
  position: relative; overflow: hidden;
}
#stat-modal-header::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,.08);
}
#stat-modal-header h2 { margin: 0; font-size: 1.2rem; color: #fff; font-weight: 800; letter-spacing: -.01em; position: relative; z-index: 1; }
#stat-modal-close {
  background: rgba(255,255,255,.15); border: none; border-radius: 8px;
  width: 34px; height: 34px; cursor: pointer; font-size: 1rem;
  color: #fff; display: flex; align-items: center; justify-content: center;
  transition: var(--t); position: relative; z-index: 1;
}
#stat-modal-close:hover { background: rgba(255,255,255,.3); transform: rotate(90deg); }
.btn-print {
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 8px;
  padding: .4rem 1rem; font-size: .8rem; font-weight: 600; cursor: pointer; display: flex;
  align-items: center; gap: .35rem; transition: var(--t); position: relative; z-index: 1;
}
.btn-print:hover { background: rgba(255,255,255,.28); }
#stat-modal-body { max-height: 70vh; overflow-y: auto; padding: 1.4rem 1.6rem 1.6rem; }
#stat-modal-body table { width: 100%; border-collapse: collapse; font-size: .82rem; }
#stat-modal-body th {
  background: var(--bg); padding: .6rem .7rem; text-align: left;
  font-size: .72rem; color: var(--text-muted); text-transform: uppercase;
  font-weight: 800; letter-spacing: .05em; position: sticky; top: 0; z-index: 2;
  border-bottom: 2px solid var(--feia-blue); white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,.06);
}
#stat-modal-body td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
#stat-modal-body tbody tr:nth-child(even) td { background: var(--surface2); }
#stat-modal-body tr:hover td { background: #DBEAFE !important; }
[data-theme="dark"] #stat-modal-body tr:hover td { background: #1e3a5f !important; }
.stat-summary-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1.4rem;
}
.stat-summary-item {
  background: linear-gradient(150deg, var(--surface2), var(--bg));
  border-radius: 12px; padding: .9rem .8rem; text-align: center;
  border: 1px solid var(--border); min-width: 0; overflow: hidden;
  transition: var(--t);
}
.stat-summary-item:hover { border-color: var(--feia-blue); box-shadow: var(--shadow-sm); transform: translateY(-2px); }
.stat-summary-item .val { font-size: 1.5rem; font-weight: 900; color: var(--feia-blue); letter-spacing: -.02em; }
.stat-summary-item .lbl { font-size: .71rem; color: var(--text-muted); margin-top: .25rem; font-weight: 600; }

/* ── Tarjetas-filtro clickeables (modal de universidades) ──────── */
.stat-summary-grid--filters .stat-summary-item {
  cursor: pointer; user-select: none; position: relative;
}
.stat-summary-grid--filters .stat-summary-item:focus-visible {
  outline: 2px solid var(--feia-blue); outline-offset: 2px;
}
.stat-summary-grid--filters .stat-summary-item.active {
  background: linear-gradient(150deg, var(--feia-blue), var(--feia-blue-dark));
  border-color: var(--feia-blue-dark); box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.stat-summary-grid--filters .stat-summary-item.active .val,
.stat-summary-grid--filters .stat-summary-item.active .lbl { color: #fff; }
.stat-summary-grid--filters .stat-summary-item.active .lbl { opacity: .85; }

/* ── Tabla con scroll horizontal permanente y visible ──────────── */
.stat-table-wrap {
  overflow-x: scroll; overflow-y: auto; -webkit-overflow-scrolling: touch;
  max-height: 46vh; /* acota la altura para que la barra horizontal quede siempre cerca, sin bajar hasta el final */
  border-radius: 10px; border: 1px solid var(--border);
  scrollbar-color: var(--feia-blue) var(--bg); /* Firefox */
  scrollbar-width: auto;
}
.stat-table-wrap::-webkit-scrollbar { height: 12px; }
.stat-table-wrap::-webkit-scrollbar-track {
  background: var(--bg); border-radius: 0 0 10px 10px;
}
.stat-table-wrap::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, var(--feia-blue), var(--feia-gold));
  border-radius: 6px; border: 2px solid var(--bg);
}
.stat-table-wrap::-webkit-scrollbar-thumb:hover { background: var(--feia-blue-dark); }
.stat-table-wrap table { min-width: 760px; }
.stat-table-wrap table.table-fixed-uni {
  table-layout: fixed; width: 100%; min-width: 820px;
}
.table-fixed-uni td, .table-fixed-uni th { overflow: hidden; }
.table-fixed-uni td:nth-child(2) { white-space: normal; line-height: 1.25; }
@media (max-width: 600px) {
  .stat-summary-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Print ───────────────────────────────────────────────────── */
@media print {
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  body > *:not(#stat-modal-overlay) { display: none !important; }
  #stat-modal-overlay {
    display: block !important; position: static !important;
    background: none !important; padding: 0 !important; overflow: visible !important;
  }
  #stat-modal-box {
    box-shadow: none !important; padding: 1rem !important; max-width: 100% !important;
    border: none !important;
  }
  #stat-modal-close, .btn-print { display: none !important; }
  #stat-modal-body { max-height: none !important; overflow: visible !important; }
  .stat-table-wrap { overflow: visible !important; }
  #stat-modal-body table { font-size: .75rem !important; }
  #stat-modal-body th {
    background: #EFF6FF !important; color: #1e3a5f !important;
    border-bottom: 2px solid #0047AB !important;
  }
  #stat-modal-body td { border-bottom: 1px solid #e2e8f0 !important; }
  #stat-modal-header {
    border-bottom: 3px solid #0047AB !important; padding-bottom: .6rem !important;
    margin-bottom: .8rem !important;
  }
  #stat-modal-header h2 { color: #0047AB !important; font-size: 1rem !important; }
  .stat-summary-grid { grid-template-columns: repeat(4, 1fr) !important; gap: .5rem !important; }
  .stat-summary-item {
    border: 1px solid #cbd5e1 !important; background: #f8fafc !important;
    padding: .5rem !important;
  }
  .stat-summary-item .val { font-size: 1.1rem !important; color: #0047AB !important; }
  #stat-modal-body::after {
    content: "Fuente: SENESCYT SIAU 2024 · FEIA — www.feiaal.org · Generado: " attr(data-date);
    display: block; margin-top: 1rem; font-size: .68rem; color: #64748b;
    border-top: 1px solid #e2e8f0; padding-top: .4rem;
  }
}

/* ── Animate on appear ─────────────────────────────────────── */
.fade-in {
  animation: fadeIn .4s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Footer ─────────────────────────────────────────────────── */
footer {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 1.5rem; text-align: center; margin-top: 3rem;
  font-size: .8rem; color: var(--text-muted);
}
footer a { color: var(--feia-blue); }

#stat-print-copy { display: none; }

@media print {
  @page { size: landscape; margin: 10mm; }

  body.stat-printing > * { display: none !important; }
  body.stat-printing > #stat-print-copy {
    display: block !important; color: #172033 !important; background: #fff !important;
    font-family: Arial, Helvetica, sans-serif !important; width: 100% !important;
  }
  body.stat-printing > #stat-modal-overlay,
  body.stat-printing > #modal-overlay,
  body.stat-printing > main,
  body.stat-printing > header,
  body.stat-printing > footer,
  body.stat-printing > #toast { display: none !important; }

  body.stat-printing #stat-print-copy h1 {
    margin: 0 0 10px !important; color: #0047AB !important; font-size: 18px !important;
    border-bottom: 3px solid #0047AB !important; padding-bottom: 8px !important;
  }
  body.stat-printing #stat-print-copy .stat-summary-grid {
    display: grid !important; grid-template-columns: repeat(4, 1fr) !important;
    gap: 6px !important; margin-bottom: 12px !important;
  }
  body.stat-printing #stat-print-copy .stat-summary-item {
    border: 1px solid #cbd5e1 !important; background: #f8fafc !important;
    padding: 7px !important; text-align: center !important; border-radius: 6px !important;
    box-shadow: none !important; transform: none !important;
  }
  body.stat-printing #stat-print-copy .stat-summary-item.active {
    border-color: #0047AB !important; background: #EFF6FF !important;
  }
  body.stat-printing #stat-print-copy .stat-summary-item .val {
    font-size: 16px !important; font-weight: 800 !important; color: #0047AB !important;
  }
  body.stat-printing #stat-print-copy .stat-summary-item .lbl {
    font-size: 10px !important; color: #475569 !important; margin-top: 2px !important; font-weight: 700 !important;
  }
  body.stat-printing #stat-print-copy .stat-table-wrap {
    overflow: visible !important; max-height: none !important; border: 0 !important;
  }
  body.stat-printing #stat-print-copy table {
    width: 100% !important; border-collapse: collapse !important; table-layout: auto !important; font-size: 10px !important;
  }
  body.stat-printing #stat-print-copy .table-fixed-uni {
    table-layout: fixed !important; min-width: 0 !important;
  }
  body.stat-printing #stat-print-copy th {
    background: #EFF6FF !important; color: #1e3a5f !important; border-bottom: 2px solid #0047AB !important;
    padding: 5px 6px !important; text-align: left !important; text-transform: uppercase !important; font-size: 9px !important;
    position: static !important; white-space: normal !important; box-shadow: none !important;
  }
  body.stat-printing #stat-print-copy td {
    border-bottom: 1px solid #e2e8f0 !important; padding: 5px 6px !important; vertical-align: top !important;
  }
  body.stat-printing #stat-print-copy tr:nth-child(even) td { background: #f8fafc !important; }
  body.stat-printing #stat-print-copy strong { font-weight: 800 !important; }
  body.stat-printing #stat-print-copy .rank-badge {
    display: inline-block !important; min-width: 18px !important; text-align: center !important; font-weight: 700 !important;
  }
  body.stat-printing #stat-print-copy a { color: #0047AB !important; text-decoration: none !important; }
  body.stat-printing #stat-print-copy .print-footer {
    margin-top: 12px !important; padding-top: 6px !important; border-top: 1px solid #e2e8f0 !important;
    color: #64748b !important; font-size: 9px !important;
  }
}

/* ── Stat modal — carrera detail side panel ─────────────────────── */
#stat-modal-box { position: relative; overflow: hidden; }

.stat-carrera-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 100%;
  background: var(--surface);
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  z-index: 10;
  box-shadow: -4px 0 24px rgba(0,0,0,.12);
}
.stat-carrera-panel-open { transform: translateX(0); }

.scp-header {
  display: flex; align-items: center; gap: .6rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.scp-back {
  background: var(--surface-alt); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: .25rem .6rem;
  font-size: .82rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.scp-back:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.scp-title-text {
  font-size: .82rem; font-weight: 700; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}

.scp-body {
  flex: 1; overflow-y: auto; padding: .9rem 1rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.scp-meta-chips {
  display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .9rem;
}
.scp-chip {
  font-size: .7rem; font-weight: 600; padding: .18rem .5rem;
  border-radius: 20px; background: var(--surface-alt);
  color: var(--text-muted); border: 1px solid var(--border);
  display: inline-flex; align-items: center;
}

.scp-unis-list { display: flex; flex-direction: column; gap: .8rem; }

.scp-prov { }
.scp-prov-label {
  font-size: .7rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: .35rem; padding-bottom: .2rem;
  border-bottom: 1px solid var(--border);
}

.scp-uni-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; padding: .55rem .65rem;
  background: var(--bg); border-radius: 8px; margin-bottom: .3rem;
  border: 1px solid var(--border);
  transition: border-color .15s, box-shadow .15s;
}
.scp-uni-card:hover { border-color: var(--primary); box-shadow: 0 1px 6px rgba(0,0,0,.08); }

.scp-uni-info { flex: 1; min-width: 0; }
.scp-uni-name {
  font-size: .78rem; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: .2rem;
}
.scp-uni-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.scp-nivel-tag {
  font-size: .62rem; font-weight: 700; padding: .05rem .3rem; border-radius: 3px;
}
.scp-city { font-size: .68rem; color: var(--text-muted); }
.scp-prog { font-size: .68rem; color: var(--text-muted); }

.scp-web-btn {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .72rem; font-weight: 600; padding: .3rem .6rem;
  border-radius: 6px; background: var(--primary); color: #fff;
  text-decoration: none; white-space: nowrap; flex-shrink: 0;
  transition: opacity .15s;
}
.scp-web-btn:hover { opacity: .85; }
.scp-no-web {
  font-size: .67rem; color: var(--text-muted); flex-shrink: 0;
  padding: .3rem .4rem; white-space: nowrap;
}

.carrera-row { cursor: pointer; transition: background .12s; }
.carrera-row:hover td { background: var(--surface-alt) !important; }
.carrera-row-active td { background: var(--primary-bg, #EFF6FF) !important; }

@media (max-width: 700px) {
  /* En móvil el panel ocupa toda la pantalla (fixed) para escapar del overflow:hidden del modal */
  .stat-carrera-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    border-left: none;
    border-top: none;
    transform: translateY(100%);
    border-radius: 0;
    z-index: 9999;
  }
  .stat-carrera-panel-open {
    transform: translateY(0);
  }
  .scp-web-btn span { display: none; }
  .scp-header { padding: 1rem; }
  .scp-back { font-size: .85rem; padding: .35rem .8rem; }
}
