/* =========================
   VARIABLES DE TEMA
   ========================= */

:root {
  --bg: #f4f4f4;
  --text: #111111;

  --panel: #ffffff;
  --panel-soft: #f1f3f7;

  --curso-base: #e4ecff;
  --curso-disponible: #2f5ea8;
  --curso-hover: #2e75b6;
  --curso-tachado: #b5b5b5;

  --badge-bg: #ffffff;
  --badge-text: #1b2a41;

  --control-bg: #24508f;
  --control-bg-hover: #2e75b6;
}

body.dark {
  --bg: #000000;
  --text: #ffffff;

  --panel: rgba(0, 0, 0, 0.2);
  --panel-soft: #222222;

  --curso-base: #1b2a41;
  --curso-disponible: #24508f;
  --curso-hover: #2e75b6;
  --curso-tachado: #888888;

  --badge-bg: #ffffff;
  --badge-text: #1b2a41;

  --control-bg: #24508f;
  --control-bg-hover: #2e75b6;
}

/* =========================
   RESETEO BÁSICO
   ========================= */

* {
  box-sizing: border-box;
}

/* =========================
   BODY + LAYOUT GENERAL
   ========================= */

body {
  font-family: Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1;
}

/* =========================
   HEADER + TÍTULO
   ========================= */

header {
  text-align: center;
  padding: 22px 10px 10px 10px;
}

h1 {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.title-main {
  font-size: 2.3rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #2e75b6, #0f4c81);
  background-clip: text;
  -webkit-background-clip: text;   /* Safari / Chrome */
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.title-sub {
  font-size: 0.95rem;
  color: #555555;
}

body.dark .title-sub {
  color: #bbbbbb;
}

/* =========================
   BARRA SUPERIOR (SELECTOR + SWITCH)
   ========================= */

.top-bar {
  width: 95vw;
  max-width: 1200px;
  margin: 0 auto 10px auto;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.selector-carrera select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #ffffff;
  color: #222;
  font-size: 0.9rem;
  outline: none;
  transition: 0.25s;
}

/* Hover / Focus */
.selector-carrera select:hover,
.selector-carrera select:focus {
  border-color: #2e75b6;
  box-shadow: 0 0 4px rgba(46,117,182,.6);
}

/* ===== MODO OSCURO ===== */

body.dark .selector-carrera select {
  background: #111827;
  color: #e5e7eb;
  border: 1px solid #3b495f;
}

body.dark .selector-carrera select:hover,
body.dark .selector-carrera select:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 6px rgba(96,165,250,.5);
}

/* Color de opciones del menú desplegable */
body.dark select option {
  background: #0f172a;
  color: #e5e7eb;
}

/* =========================
   SWITCH ANDROID
   ========================= */

.theme-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.3s;
}

.slider:before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked + .slider {
  background: var(--control-bg);
}

.switch input:checked + .slider:before {
  transform: translateX(20px);
}

/* =========================
   CONTENEDOR PRINCIPAL + MALLA
   ========================= */

.container {
  width: 95vw;                     /* aprovecha casi todo el ancho */
  margin: 10px auto 25px auto;
  padding: 15px;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.malla {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  padding: 10px;
  gap: 12px;
  justify-content: flex-start;
  overflow-x: auto;   /* solo aparecerá la barra si realmente no cabe */
  overflow-y: hidden;
}

/* =========================
   COLUMNA DE SEMESTRE
   ========================= */

.semestre {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--panel-soft);
  padding: 6px;
  border-radius: 8px;
  border: 1px solid #d6dbe6;

  min-width: 120px;
  max-width: 120px;
  flex: 0 0 120px;   /* todas las columnas del mismo ancho */
}

body.dark .semestre {
  border-color: #333333;
}

.titulo-semestre {
  font-weight: bold;
  font-size: 1em;
  margin-bottom: 6px;
  text-align: center;
}

.cursos {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* =========================
   TARJETAS DE CURSO
   ========================= */

.curso {
  width: 100%;
  min-height: 105px;
  padding: 6px;

  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 3px;

  background: var(--curso-base);
  border-radius: 10px;
  border: 2px solid #ffffff;

  color: var(--text);
  text-align: center;
  font-size: 0.78em;
  line-height: 1.15;

  cursor: pointer;
  transition: 0.25s;
  opacity: 0.75;
}

.curso span.clave,
.curso span.creditos {
  font-weight: bold;
  font-size: 0.7em;
}

.curso span.clave {
  align-self: flex-start;
  padding: 2px 4px;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
}

.curso span.nombre {
  display: block;
  margin-top: 4px;
  margin-bottom: 4px;
  white-space: normal;
}

.curso span.creditos {
  align-self: flex-end;
  padding: 2px 4px;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
}

/* Hover suave */
.curso:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

/* Cursos disponibles (prerrequisitos cumplidos) */
.curso.disponible {
  background: var(--curso-disponible);
  border-color: #1d4076;
  color: #ffffff;
  opacity: 1;
}

/* No disponibles (por defecto, suaves) */
.curso:not(.disponible) {
  background: #e9eef7;
  border-color: #d6dff0;
}

body.dark .curso:not(.disponible) {
  background: #1b2a41;
  border-color: #333333;
}

/* Curso tachado (aprobado) */
.curso.tachado {
  text-decoration: line-through;
  background: var(--curso-tachado);
  color: #f5f5f5;
  opacity: 1;
}

/* =========================
   CONTROLES
   ========================= */

.controls {
  margin-top: 10px;
  text-align: center;
}

.controls button {
  padding: 8px 12px;
  font-size: 0.9em;
  cursor: pointer;
  border: none;
  background: var(--control-bg);
  color: #ffffff;
  border-radius: 5px;
  transition: background 0.3s, transform 0.2s;
}

.controls button:hover {
  background: var(--control-bg-hover);
  transform: translateY(-1px);
}

/* =========================
   COLORES ESPECIALES DE CURSOS
   ========================= */

/* Cursos de especialidad ICM/IME disponibles */
.ime-curso.disponible,
.icm-curso.disponible {
  background: #ff9800;
  border-color: #c26c00;
  opacity: 1;
}

/* Física */
.fis-curso.disponible {
  background: #067017;
  border-color: #03440e;
  opacity: 1;
}

/* EIQ */
.eiq-curso.disponible {
  background: #5e0443;
  border-color: #3b022b;
  opacity: 1;
}

/* Cursos que inician con "ING" */
.ing-curso.disponible {
  background: #2ecc71;
  border-color: #1d8f4b;
  opacity: 1;
}

/* Tachados especiales */
.fis-curso.tachado,
.eiq-curso.tachado,
.ime-curso.tachado,
.icm-curso.tachado,
.ing-curso.tachado {
  background: var(--curso-tachado);
  text-decoration: line-through;
  opacity: 1;
}

/* =========================
   BANNER DE COOKIES
   ========================= */

#cookie-banner {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: var(--panel-soft);
  color: var(--text);
  padding: 12px 10px;
  text-align: center;
  z-index: 9999;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.5);

  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

#cookie-banner p {
  margin: 0;
}

#aceptar-cookies {
  padding: 8px 12px;
  border: none;
  background-color: var(--control-bg);
  color: white;
  border-radius: 5px;
  cursor: pointer;
}

#aceptar-cookies:hover {
  background-color: var(--control-bg-hover);
}

/* =========================
   FOOTER
   ========================= */

footer {
  text-align: center;
  font-size: 0.8em;
  color: #777777;
  margin: 10px 0 35px 0;
}

body.dark footer {
  color: #bbbbbb;
}

/* =========================
   MENSAJES DE ERROR
   ========================= */

.error {
  margin: 10px 0;
  padding: 10px;
  background: #ffe6e6;
  color: #a10000;
  border-radius: 6px;
  text-align: left;
}

body.dark .error {
  background: #3a0000;
  color: #ffb3b3;
}

/* =========================
   RESPONSIVE
   ========================= */

@media (max-width: 600px) {
  .curso {
    width: 95px;
    min-height: 100px;
    font-size: 0.7em;
  }

  .semestre {
    min-width: 115px;
  }

  .container {
    padding: 10px;
  }
}

#curso-tooltip {
  position: absolute;
  display: none;
  max-width: 280px;
  padding: 10px 12px;

  background: #ffffff;
  color: #111827;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);

  font-size: 0.8em;
  line-height: 1.4;
  z-index: 10000;
  pointer-events: none;
  white-space: pre-line;   /* respeta \n, funciona también con <br> */
}

body.dark #curso-tooltip {
  background: #f9fafb;
  color: #111827;
  border-color: #4b5563;
}

/* ====== LAYOUT RESPONSIVE PARA CELULAR ====== */
@media (max-width: 900px) {
  .semestre {
    min-width: 140px;
    max-width: 140px;
    flex: 0 0 140px;
  }
}

/* ===== Panel informativo tipo bottom sheet (móvil) ===== */

.info-movil {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 9999;

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
}

.info-movil.visible {
  opacity: 1;
  pointer-events: auto;
}

.info-movil-content {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 24px);
  width: 92%;
  max-width: 480px;
  max-height: 60vh;
  background: #ffffff;
  color: #111;
  border-radius: 18px 18px 0 0;
  padding: 14px 18px 18px 18px;
  box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.35);
  overflow-y: auto;
  transition: transform 0.25s ease-out;
}

.info-movil.visible .info-movil-content {
  transform: translate(-50%, 0);
}

body.dark .info-movil-content {
  background: #222;
  color: #eee;
}

.cerrar-info {
  border: none;
  background: #24508f;
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 0.8rem;
}

.cerrar-info:hover {
  background: #2e75b6;
}

#info-movil-texto {
  white-space: pre-wrap;
  font-family: system-ui, sans-serif;
  font-size: 0.9em;
}

.info-movil-handle {
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  margin: 0 auto 10px auto;
}

body.dark .info-movil-handle {
  background: rgba(255, 255, 255, 0.28);
}

/* ===== Evitar selección de texto en tarjetas (móvil) ===== */
@media (max-width: 900px) {
  .curso {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
}
