/* Paleta institucional Universidad de Cuenca:
   azul #002856 · rojo #A51008 (mismos colores que los documentos LaTeX) */
:root {
  --ucu-azul: #002856;
  --ucu-rojo: #A51008;
  --bg: #001229;             /* fondo bajo el mapa: azul UCuenca muy oscuro */
  --panel: #002856e6;        /* paneles: azul institucional translúcido */
  --fg: #eaf1f8;
  --accent: #6db1ff;         /* azul claro legible sobre el azul institucional */
  --btn: #0d3a72;            /* botones: azul intermedio */
  --btn-hover: #14508f;
  --line: #1c4370;           /* separadores dentro de paneles */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
#map { position: absolute; inset: 0; background: var(--bg); transition: filter .35s ease; }
/* scene tint used by the light presets (dusk/night wash); never blocks clicks */
#tint { position: absolute; inset: 0; z-index: 2; pointer-events: none; transition: background .6s ease; }

/* CRT scanlines + vignette overlay for the "sensor look" selector — hidden
   unless the CRT mode is active (toggled via body[data-sensor="crt"]) */
#scanlines {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0;
  transition: opacity .35s ease;
  background:
    repeating-linear-gradient(rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.14) 3px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,.45) 100%);
}
body[data-sensor="crt"] #scanlines { opacity: 1; }
#sensor-mode { background: var(--btn); color: var(--fg); border: 0; border-radius: 6px; font-size: 12px; }

/* floating badge shown while the camera is chasing a vehicle (cockpit mode) */
#follow-badge {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 7;
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 12px;
  background: var(--panel); color: var(--fg); border-radius: 8px;
  border-top: 3px solid var(--ucu-rojo); box-shadow: 0 6px 24px #0008; backdrop-filter: blur(6px);
}
#follow-hud { opacity: .85; color: var(--accent); white-space: nowrap; }
#follow-exit {
  flex: none; width: 22px; height: 22px; padding: 0; border-radius: 6px;
  font-size: 12px; line-height: 22px; background: var(--btn);
}

#left-col {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  display: flex; flex-direction: column; gap: 12px;
  max-height: 95vh;
}
#panel, #transit-panel {
  width: 280px; padding: 14px 16px; border-radius: 12px;
  background: var(--panel); color: var(--fg);
  border-top: 3px solid var(--ucu-rojo);   /* filete rojo institucional */
  backdrop-filter: blur(6px); box-shadow: 0 6px 24px #0008;
  overflow-y: auto; overflow-x: hidden;
  transition: max-height .35s ease;
}
#panel { max-height: 60vh; }
#transit-panel { max-height: 36vh; }
#panel.collapsed, #transit-panel.collapsed { max-height: 46px; overflow: hidden; }   /* solo la barra de título */
#panel h1, #transit-panel h1 { margin: 0 0 10px; font-size: 16px; letter-spacing: .5px; }
#panel h1::after { content: "☰"; float: right; opacity: .5; font-weight: 400; }
#transit-panel h1::after { content: "🚌"; float: right; opacity: .6; font-weight: 400; }
#transit-panel select { flex: 1; min-width: 0; }
#transit-panel .tp-lbl { flex: 0 0 52px; font-size: 12px; opacity: .85; }
#transit-panel .tp-small { flex: 0 0 auto !important; padding: 7px 12px; }
#transit-info { font-size: 11.5px; opacity: .75; margin-top: 4px; line-height: 1.5; }
/* logo institucional en la cabecera del panel principal */
.uc-logo {
  height: 22px; width: 22px; vertical-align: -5px; margin-right: 8px;
  background: #fff; border-radius: 50%; padding: 2px; box-sizing: content-box;
}
.uc-sub {
  font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase;
  color: #bcd2e8; opacity: .85; margin: -4px 0 10px 0;
}
#fps-val { white-space: nowrap; min-width: 46px; text-align: right; }
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; }
button {
  flex: 1; padding: 7px 10px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--btn); color: var(--fg); font-size: 13px;
}
button:hover { background: var(--btn-hover); }
input[type=range] { flex: 1; accent-color: var(--accent); }
#topbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--panel); color: var(--fg); border-radius: 10px;
  box-shadow: 0 6px 24px #0008; backdrop-filter: blur(6px);
}
.topbar-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.topbar-slider { display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.topbar-slider .slider-ico { font-size: 15px; opacity: .8; }
.topbar-slider input[type=range] { flex: 0 0 auto; width: 110px; }
#bearing-val { font-size: 11px; min-width: 30px; text-align: right; opacity: .85; }
.icon-btn { flex: 0 0 auto; width: 36px; padding: 7px 0; font-size: 15px; line-height: 1; }
.icon-btn svg { width: 18px; height: 18px; display: block; margin: 0 auto; }
.icon-btn.active { background: var(--accent); color: #06121f; }

/* right-side historical panel (time series from the running simulation) */
#histpanel {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  width: 268px; padding: 14px 16px; border-radius: 12px;
  background: var(--panel); color: var(--fg);
  border-top: 3px solid var(--ucu-rojo);
  backdrop-filter: blur(6px); box-shadow: 0 6px 24px #0008;
  max-height: 82vh; overflow-y: auto; overflow-x: hidden;
  transition: max-height .35s ease;
}
#histpanel.collapsed { max-height: 46px; overflow: hidden; }
#histpanel h1 { margin: 0 0 10px; font-size: 16px; letter-spacing: .5px; }
#histpanel h1::after { content: "📈"; float: right; opacity: .6; font-weight: 400; }
.h-block { margin: 10px 0; }
.h-title { font-size: 12px; margin-bottom: 4px; }
.h-title b { color: var(--accent); float: right; }
.h-block canvas { display: block; width: 100%; height: 66px; background: #001a3a; border-radius: 6px; }
.h-legend { font-size: 10.5px; opacity: .8; margin-top: 3px; }
.h-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin: 0 3px 0 8px; vertical-align: -1px; }
.h-legend i:first-child { margin-left: 0; }
#h-types { font-size: 11px; line-height: 1.7; }
#h-types b { color: var(--accent); float: right; }

/* right-click inspector popup (SUMO stats for the picked object) */
#popup {
  position: absolute; display: none; z-index: 8; min-width: 190px; max-width: 270px;
  padding: 10px 12px; border-radius: 10px; font-size: 12px; line-height: 1.55;
  background: var(--panel); color: var(--fg); box-shadow: 0 6px 24px #000a;
  backdrop-filter: blur(6px); pointer-events: none;
}
#popup h3 { margin: 0 0 6px; font-size: 12.5px; color: var(--accent); }
#popup b { color: #fff; }

/* pin de paneles: fija un panel para que no se auto-colapse */
.pin {
  float: right; cursor: pointer; margin-left: 8px;
  opacity: .35; filter: grayscale(1); user-select: none;
}
.pin.on { opacity: 1; filter: none; }
/* modo presentación: botón degradado arriba a la derecha que oculta todos los
   paneles y controles, dejando solo el mapa y la simulación */
#btn-zen {
  position: absolute; top: 14px; right: 14px; z-index: 30;
  flex: none; width: 32px; height: 32px; padding: 0;
  border-radius: 8px; font-size: 16px; line-height: 32px; text-align: center;
  background: var(--panel); color: var(--fg);
  opacity: .3; transition: opacity .25s ease;
  box-shadow: 0 4px 14px #0007; backdrop-filter: blur(6px);
}
#btn-zen:hover { opacity: 1; }
body.zen #left-col, body.zen #histpanel,
body.zen #topbar { display: none; }
body.zen #btn-zen { opacity: .5; }

#stats { margin-top: 12px; font-size: 13px; line-height: 1.7; border-top: 1px solid var(--line); padding-top: 10px; }
#veh-count, #sim-time { color: var(--accent); }
#conn { font-size: 11px; margin-top: 4px; }
#conn.online { color: #6ee7a0; }
#conn.offline { color: #ff8a8a; }
#legend { margin-top: 12px; font-size: 11px; }
.ramp { display: flex; align-items: center; gap: 3px; margin-top: 6px; flex-wrap: wrap; }
.ramp i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

/* --- realismo visual (realismo.js) ---------------------------------------- */
/* indicador de fps (?fps=1 o casilla del panel) */
#fps-badge {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  z-index: 5; padding: 4px 10px; border-radius: 6px;
  font: 600 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #d8f7e0; background: rgba(8, 18, 32, .72); pointer-events: none;
  white-space: nowrap;
}
#panel .hint { margin-left: 6px; font-size: 11px; opacity: .7; }
/* atribución de los datos del tileset (asset.copyright / extras) */
#tiles-attrib {
  position: absolute; left: 8px; bottom: 6px; z-index: 4; max-width: 60vw;
  padding: 2px 8px; border-radius: 4px; font: 11px/1.4 system-ui, sans-serif;
  color: #1c2533; background: rgba(255, 255, 255, .72); pointer-events: none;
}

/* ===================== barra principal (vista simplificada) ===================== */
#mainbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: none; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: center;
  padding: 0; width: max-content; max-width: calc(100vw - 24px);
}
body.simple #mainbar { display: flex; }
body.simple #left-col, body.simple #histpanel, body.simple #topbar,
body.simple #btn-zen { display: none !important; }
body.simple #follow-badge { top: 74px; }
/* botones con relieve: degradado, filo de luz arriba, canto inferior oscuro y
   sombra proyectada; al pasar el ratón se elevan y al pulsar se hunden */
.mb-item {
  position: relative; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 13px; border-radius: 11px; cursor: pointer;
  font-size: 13px; font-weight: 700; letter-spacing: .2px; line-height: 1.1; white-space: nowrap;
  color: #f4f8ff; text-shadow: 0 1px 1px rgba(0, 0, 0, .45);
  background: linear-gradient(180deg, #2a64ab 0%, #154a8c 48%, #0d3a72 52%, #0a2f5e 100%);
  border: 1px solid #071f3f; border-top-color: #4d86cc;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .28),      /* filo de luz superior */
    inset 0 -2px 0 rgba(0, 0, 0, .25),           /* canto inferior */
    0 3px 0 #05162d,                              /* grosor del botón */
    0 6px 14px rgba(0, 0, 0, .40);               /* sombra proyectada */
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
}
.mb-item:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #3574bf 0%, #1c579f 48%, #134583 52%, #0e3870 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .32), inset 0 -2px 0 rgba(0, 0, 0, .25),
    0 4px 0 #05162d, 0 9px 18px rgba(0, 0, 0, .45);
}
.mb-item:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .45), 0 1px 0 #05162d, 0 2px 5px rgba(0, 0, 0, .35);
}
/* activado: botón «encendido», claro y hundido, con el filete rojo UCuenca */
.mb-item.active {
  color: #06121f; text-shadow: 0 1px 0 rgba(255, 255, 255, .45);
  background: linear-gradient(180deg, #c9e4ff 0%, #8cc4ff 50%, #6db1ff 51%, #5aa2f2 100%);
  border-color: #2b6cb8; border-bottom: 3px solid var(--ucu-rojo);
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .22), inset 0 -1px 0 rgba(255, 255, 255, .35),
              0 2px 0 #05162d, 0 4px 10px rgba(0, 0, 0, .35);
}
.mb-item.active:hover { transform: translateY(0); }
.mb-select select {
  background: transparent; color: inherit; border: none; font: inherit; cursor: pointer;
  outline: none; padding: 0 2px; width: 138px; text-overflow: ellipsis;
}
.mb-select select option { color: #0f172a; }
/* mini-información al pasar el ratón */
.mb-item[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 260px; white-space: normal; text-align: left;
  padding: 8px 11px; border-radius: 8px; z-index: 40; pointer-events: none;
  background: #0b1d33f5; color: #fff; font-size: 12px; font-weight: 400; line-height: 1.45;
  box-shadow: 0 6px 18px #000a; border-top: 2px solid var(--accent);
}
.mb-wrap { position: relative; }
.mb-wrap.open .mb-item[data-tip]:hover::after { display: none; }
#mb-transit-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
}
#mb-transit-pop #transit-panel { max-height: none !important; }
#mb-transit-pop #transit-panel h1 { display: none; }
#mb-legend {
  position: absolute; bottom: 30px; left: 12px; z-index: 6;
  padding: 8px 10px; border-radius: 10px; font-size: 12px;
  background: var(--panel); color: var(--fg); box-shadow: 0 4px 14px #0007;
}
#mb-loading {
  position: absolute; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: #001229cc; color: #fff; font-size: 15px; text-align: center; padding: 20px;
}
#mb-loading[hidden] { display: none; }
.mb-spin {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid #ffffff33; border-top-color: var(--accent);
  animation: mbspin 0.9s linear infinite;
}
@keyframes mbspin { to { transform: rotate(360deg); } }
#mb-place { width: 178px; }
