/* ── Variables de tema ────────────────────────────────────────────── */
    :root {
      --sidebar-bg:   #1a1f2e;
      --sidebar-card: #252c3e;
      --sidebar-w:    300px;
      --accent:       #4a9eff;
      --alerta-rojo:  #e74c3c;
      --alerta-amar:  #f39c12;
      --alerta-verde: #27ae60;
      --texto-prim:   #e8ecf4;
      --texto-sec:    #8a9bbf;
      --borde:        #2e3a4e;
      --slider-h:     60px;
      --font:         'Segoe UI', system-ui, sans-serif;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: var(--font);
      background: #0d1117;
      color: var(--texto-prim);
      display: flex;
      height: 100vh;
      overflow: hidden;
      padding-top: 48px;  /* espacio para la barra superior fija */
    }

    /* ── Panel lateral ───────────────────────────────────────────────── */
    #sidebar {
      width: var(--sidebar-w);
      min-width: var(--sidebar-w);
      background: var(--sidebar-bg);
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      border-right: 1px solid var(--borde);
      z-index: 1000;
    }

    .sidebar-section {
      padding: 12px 14px;
      border-bottom: 1px solid var(--borde);
    }

    .section-title {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 1.5px;
      text-transform: uppercase;
      color: var(--texto-sec);
      margin-bottom: 8px;
    }

    /* ── Header / título ──────────────────────────────────────────────── */
    #header {
      padding: 16px 14px 12px;
      background: linear-gradient(135deg, #1a2744, #252c3e);
      border-bottom: 1px solid var(--borde);
    }

    #header p {
      font-size: 11px;
      color: var(--texto-sec);
      margin-top: 3px;
    }

    #estado-badge {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      margin-top: 7px;
      font-size: 11px;
      color: var(--texto-sec);
    }

    #estado-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: #888;
      transition: background 0.5s;
    }

    #estado-dot.ok    { background: var(--alerta-verde); }
    #estado-dot.error { background: var(--alerta-rojo); }

    /* ── Selector de contaminante ─────────────────────────────────────── */
    .cont-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 6px;
    }

    .cont-btn {
      padding: 8px 6px;
      border-radius: 6px;
      border: 1px solid var(--borde);
      background: var(--sidebar-card);
      color: var(--texto-sec);
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      text-align: center;
      transition: all 0.2s;
    }

    .cont-btn:hover  { border-color: var(--accent); color: var(--texto-prim); }
    .cont-btn.active {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
    }

    /* ── Info meteorológica ───────────────────────────────────────────── */
    .meteo-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 6px;
    }

    .meteo-card {
      background: var(--sidebar-card);
      border-radius: 6px;
      padding: 8px;
      border: 1px solid var(--borde);
    }

    .meteo-label { font-size: 9px; color: var(--texto-sec); text-transform: uppercase; letter-spacing: 1px; }
    .meteo-val   { font-size: 16px; font-weight: 700; color: var(--texto-prim); margin-top: 2px; }
    .meteo-unit  { font-size: 10px; color: var(--texto-sec); }

    #clase-badge {
      display: inline-block;
      padding: 3px 10px;
      border-radius: 12px;
      font-size: 13px;
      font-weight: 700;
      text-transform: uppercase;
    }

    /* ── Panel de alertas ─────────────────────────────────────────────── */
    #alertas-container {
      border-radius: 6px;
      overflow: hidden;
      border: 1px solid var(--borde);
    }

    #alertas-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 10px;
      background: var(--sidebar-card);
    }

    .alerta-item {
      padding: 7px 10px;
      font-size: 11px;
      border-top: 1px solid var(--borde);
      display: flex;
      justify-content: space-between;
    }

    .alerta-item.ALERTA { background: rgba(231,76,60,0.1); }
    .alerta-item.AVISO  { background: rgba(243,156,18,0.1); }

    .nivel-badge {
      padding: 1px 6px;
      border-radius: 4px;
      font-size: 9px;
      font-weight: 700;
      text-transform: uppercase;
    }

    .nivel-badge.ALERTA { background: var(--alerta-rojo); color: white; }
    .nivel-badge.AVISO  { background: var(--alerta-amar); color: #111; }
    .nivel-badge.NORMAL { background: #333; color: var(--texto-sec); }

    /* ── Estadísticas ─────────────────────────────────────────────────── */
    .stats-row {
      display: flex;
      justify-content: space-between;
      font-size: 12px;
      padding: 4px 0;
      border-bottom: 1px solid var(--borde);
    }

    .stats-row:last-child { border-bottom: none; }
    .stats-val { font-weight: 600; color: var(--texto-prim); }

    /* ── Área del mapa y slider ──────────────────────────────────────── */
    #map-area {
      flex: 1;
      display: flex;
      flex-direction: column;
      position: relative;
    }

    #map {
      flex: 1;
      z-index: 1;
    }

    /* ── Panel de control temporal expandido ──────────────────────────── */
    #slider-bar {
      height: calc(var(--slider-h) * 1.2);
      background: var(--sidebar-bg);
      border-top: 1px solid var(--borde);
      display: flex;
      align-items: center;
      padding: 8px 16px;
      gap: 20px;
      z-index: 500;
      position: relative;
      overflow: hidden;
    }

    /* Indicador de estado en el border del panel */
    #slider-bar::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 2px;
      background: var(--borde);
      transition: background 0.3s ease;
    }

    #slider-bar.live::before {
      background: linear-gradient(90deg, var(--alerta-verde), var(--alerta-verde));
    }

    #slider-bar.historical::before {
      background: linear-gradient(90deg, var(--accent), var(--accent));
    }

    #slider-bar.playing::before {
      background: linear-gradient(90deg,
        var(--accent) 0%,
        var(--alerta-verde) 50%,
        var(--accent) 100%);
      animation: playingPulse 2s ease-in-out infinite;
    }

    #slider-bar.paused::before {
      background: linear-gradient(90deg, var(--alerta-amar), var(--alerta-amar));
      animation: pausedBlink 1s ease-in-out infinite alternate;
    }

    @keyframes playingPulse {
      0%, 100% { opacity: 0.7; }
      50% { opacity: 1.0; }
    }

    @keyframes pausedBlink {
      0% { opacity: 0.4; }
      100% { opacity: 0.8; }
    }

    /* ── Selector de fecha ──────────────────────────────────────────── */
    #date-selector {
      display: flex;
      align-items: center;
      gap: 8px;
      min-width: 200px;
    }

    .date-label {
      font-size: 16px;
      cursor: pointer;
    }

    .date-picker {
      background: var(--sidebar-card);
      color: var(--texto-prim);
      border: 1px solid var(--borde);
      border-radius: 4px;
      padding: 4px 8px;
      font-size: 12px;
      cursor: pointer;
      min-width: 120px;
    }

    .date-picker:focus {
      border-color: var(--accent);
      outline: none;
    }

    /* ── Badge de estado dinámico ───────────────────────────────────── */
    .status-indicator {
      display: flex;
      align-items: center;
      gap: 4px;
      padding: 3px 8px;
      border-radius: 12px;
      font-size: 10px;
      font-weight: 600;
      text-transform: uppercase;
      transition: all 0.3s ease;
      min-width: 80px;
      justify-content: center;
    }

    .status-indicator.live {
      background: rgba(39, 174, 96, 0.2);
      color: var(--alerta-verde);
      border: 1px solid var(--alerta-verde);
    }

    .status-indicator.historical {
      background: rgba(74, 158, 255, 0.2);
      color: var(--accent);
      border: 1px solid var(--accent);
    }

    .status-indicator.playing {
      background: rgba(74, 158, 255, 0.3);
      color: var(--accent);
      border: 1px solid var(--accent);
      animation: playingPulse 1.5s ease-in-out infinite;
    }

    .status-indicator.paused {
      background: rgba(243, 156, 18, 0.2);
      color: var(--alerta-amar);
      border: 1px solid var(--alerta-amar);
    }

    /* ── Controles de reproducción ──────────────────────────────────── */
    #playback-controls {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .control-btn {
      background: var(--sidebar-card);
      color: var(--texto-prim);
      border: 1px solid var(--borde);
      border-radius: 6px;
      padding: 6px 10px;
      font-size: 14px;
      cursor: pointer;
      transition: all 0.2s ease;
      min-width: 36px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .control-btn:hover {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
      transform: translateY(-1px);
    }

    .control-btn:active {
      transform: translateY(0);
    }

    .control-btn:disabled {
      opacity: 0.5;
      cursor: not-allowed;
      transform: none;
    }

    .control-btn.active {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
    }

    /* ── Slider temporal mejorado ───────────────────────────────────── */
    #temporal-section {
      display: flex;
      align-items: center;
      gap: 12px;
      flex: 1;
      min-width: 200px;
    }

    #slider-ts-min, #slider-ts-max {
      font-size: 10px;
      color: var(--texto-sec);
      min-width: 45px;
    }

    #slider-ts-max { text-align: right; }

    #slider-container {
      position: relative;
      flex: 1;
    }

    #progress-track {
      position: absolute;
      top: 50%;
      left: 0;
      right: 0;
      height: 4px;
      background: var(--borde);
      border-radius: 2px;
      transform: translateY(-50%);
      z-index: 1;
    }

    #progress-fill {
      height: 100%;
      background: linear-gradient(90deg,
        var(--alerta-verde) 0%,
        var(--alerta-amar) 50%,
        var(--alerta-rojo) 100%);
      border-radius: 2px;
      width: 100%;
      transition: width 0.3s ease;
    }

    #ts-slider {
      position: relative;
      z-index: 2;
      background: transparent;
      width: 100%;
      accent-color: var(--accent);
      cursor: pointer;
    }

    /* ── Indicadores de tiempo y velocidad ──────────────────────────── */
    #time-controls {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .timestamp-container {
      text-align: center;
      min-width: 70px;
    }

    .time-display {
      font-size: 14px;
      font-weight: 700;
      color: var(--accent);
      line-height: 1;
    }

    .date-display {
      font-size: 9px;
      color: var(--texto-sec);
      text-transform: uppercase;
      line-height: 1;
      margin-top: 1px;
    }

    /* Diferentes estilos según el modo */
    .timestamp-container.live .time-display {
      color: var(--alerta-verde);
      animation: livePulse 2s ease-in-out infinite alternate;
    }

    .timestamp-container.historical .time-display {
      color: var(--accent);
    }

    .timestamp-container.playing .time-display {
      color: var(--accent);
      animation: playingTick 1s ease-in-out infinite;
    }

    @keyframes livePulse {
      0% { opacity: 0.8; }
      100% { opacity: 1.0; }
    }

    @keyframes playingTick {
      0%, 90% { transform: scale(1); }
      95% { transform: scale(1.05); }
      100% { transform: scale(1); }
    }

    /* ── Selector de velocidad ──────────────────────────────────────── */
    .speed-display {
      display: flex;
      align-items: center;
      gap: 4px;
      opacity: 0.8;
      transition: opacity 0.3s ease;
    }

    .speed-display.active {
      opacity: 1;
    }

    .speed-select {
      background: var(--sidebar-card);
      color: var(--accent);
      border: 1px solid var(--borde);
      border-radius: 3px;
      padding: 4px 8px;
      font-size: 10px;
      font-weight: 600;
      cursor: pointer;
      min-width: 50px;
    }

    .speed-select:focus {
      outline: none;
      border-color: var(--accent);
    }

    /* ── Sistema de tooltips ────────────────────────────────────────── */
    .tooltip-container {
      position: absolute;
      background: var(--sidebar-bg);
      border: 1px solid var(--borde);
      border-radius: 6px;
      padding: 8px 10px;
      max-width: 200px;
      z-index: 10000;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease, transform 0.2s ease;
      transform: translateY(-5px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }

    .tooltip-container.visible {
      opacity: 1;
      transform: translateY(0);
    }

    .tooltip-arrow {
      position: absolute;
      width: 0;
      height: 0;
      border: 5px solid transparent;
    }

    .tooltip-container.bottom .tooltip-arrow {
      top: -10px;
      left: 50%;
      transform: translateX(-50%);
      border-bottom-color: var(--sidebar-bg);
    }

    .tooltip-container.top .tooltip-arrow {
      bottom: -10px;
      left: 50%;
      transform: translateX(-50%);
      border-top-color: var(--sidebar-bg);
    }

    .tooltip-content {
      color: var(--texto-prim);
    }

    .tooltip-title {
      font-size: 11px;
      font-weight: 600;
      color: var(--accent);
      margin-bottom: 3px;
      line-height: 1.2;
    }

    .tooltip-description {
      font-size: 10px;
      color: var(--texto-sec);
      line-height: 1.3;
      margin-bottom: 4px;
    }

    .tooltip-shortcut {
      font-size: 9px;
      color: var(--alerta-amar);
      font-family: monospace;
      background: rgba(255,255,255,0.1);
      padding: 1px 3px;
      border-radius: 2px;
      margin-top: 4px;
      display: inline-block;
    }

    /* ── Responsividad del panel ────────────────────────────────────── */
    @media (max-width: 1200px) {
      #slider-bar {
        flex-wrap: wrap;
        height: auto;
        min-height: calc(var(--slider-h) * 1.5);
        padding: 12px 16px;
      }
      
      #temporal-section {
        order: 3;
        width: 100%;
        margin-top: 8px;
      }
    }

    @media (max-width: 800px) {
      .control-btn {
        padding: 4px 6px;
        font-size: 12px;
        min-width: 30px;
        height: 28px;
      }
      
      .status-indicator {
        font-size: 9px;
        padding: 2px 6px;
      }
    }

    /* ── Modal del gráfico ───────────────────────────────────────────── */
    #chart-modal {
      position: fixed;
      bottom: calc(var(--slider-h) + 10px);
      right: 10px;
      width: 420px;
      background: var(--sidebar-bg);
      border: 1px solid var(--borde);
      border-radius: 10px;
      padding: 14px;
      z-index: 2000;
      display: none;
      box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    }

    #chart-modal.visible { display: block; }

    #chart-modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;
    }

    #chart-modal-title { font-size: 13px; font-weight: 600; }

    #chart-close-btn {
      background: none;
      border: none;
      color: var(--texto-sec);
      cursor: pointer;
      font-size: 16px;
      line-height: 1;
    }

    #chart-canvas { width: 100% !important; }

    /* ── Escala de colores ─────────────────────────────────────────────── */
    #leyenda {
      position: absolute;
      bottom: calc(var(--slider-h) + 10px);
      left: 10px;
      background: rgba(26,31,46,0.92);
      border: 1px solid var(--borde);
      border-radius: 6px;
      padding: 8px 12px;
      z-index: 500;
      font-size: 11px;
    }

    #leyenda .grad-bar {
      height: 8px;
      width: 120px;
      border-radius: 4px;
      background: linear-gradient(to right, #32145f, #3f5aa8, #209caa, #f1e51d, #f39c12, #c94332, #5b0a0a);
      margin: 4px 0;
    }

    #leyenda .grad-labels {
      display: flex;
      justify-content: space-between;
      color: var(--texto-sec);
    }

    /* ── Indicador de viento en el mapa ─────────────────────────────────── */
    #wind-indicator {
      position: absolute;
      top: 10px;
      right: 10px;
      width: 90px;
      height: 90px;
      background: rgba(26, 31, 46, 0.92);
      border: 2px solid var(--accent);
      border-radius: 50%;
      z-index: 500;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    #wind-indicator .wind-arrow-container {
      width: 50px;
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
    }

    #wind-indicator .wind-arrow {
      width: 0;
      height: 0;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      border-bottom: 30px solid var(--accent);
      transform-origin: center center;
      transition: transform 0.5s ease;
    }

    #wind-indicator .wind-speed {
      font-size: 11px;
      font-weight: 700;
      color: var(--texto-prim);
      margin-top: 4px;
      text-align: center;
    }

    #wind-indicator .wind-speed-unit {
      font-size: 9px;
      color: var(--texto-sec);
      text-align: center;
    }

    /* ── Modal de Emisiones (Tabla) ───────────────────────────────────── */
    #emisiones-modal {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 80%;
      max-width: 900px;
      max-height: 80vh;
      background: var(--sidebar-bg);
      border: 1px solid var(--borde);
      border-radius: 12px;
      padding: 20px;
      z-index: 4000;
      display: none;
      box-shadow: 0 20px 60px rgba(0,0,0,0.7);
      flex-direction: column;
    }

    #emisiones-modal.visible { display: flex; }

    #emisiones-modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
      padding-bottom: 10px;
      border-bottom: 1px solid var(--borde);
    }

    .tabla-container {
      overflow-y: auto;
      flex: 1;
    }

    table {
      width: 100%;
      border-collapse: collapse;
      font-size: 12px;
    }

    th {
      position: sticky;
      top: 0;
      background: var(--sidebar-card);
      padding: 10px;
      text-align: left;
      color: var(--texto-sec);
      font-weight: 600;
      border-bottom: 2px solid var(--borde);
    }

    td {
      padding: 8px 10px;
      border-bottom: 1px solid var(--borde);
      color: var(--texto-prim);
    }

    tr:hover { background: rgba(255,255,255,0.03); }

    .btn-mas {
      background: var(--accent);
      color: white;
      border: none;
      border-radius: 4px;
      width: 20px;
      height: 20px;
      cursor: pointer;
      font-weight: bold;
      margin-left: 10px;
      vertical-align: middle;
    }

    /* ── Selector de chimeneas (radio buttons) ──────────────────────────── */
    #chimeneas-selector {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin-bottom: 6px;
    }

    .chimenea-radio {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 3px 8px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 11px;
      background: var(--sidebar-card);
      color: var(--texto-sec);
      border: 1px solid var(--borde);
      transition: all 0.15s ease;
      user-select: none;
    }

    .chimenea-radio:hover {
      border-color: var(--accent);
      opacity: 0.85;
    }

    .chimenea-radio input[type="radio"] {
      display: none;
    }

    #chimeneas-detalle {
      font-size: 11px;
      color: var(--texto-sec);
      background: var(--sidebar-card);
      border-radius: 6px;
      padding: 8px;
      line-height: 1.5;
    }

    /* ── Cargando overlay ──────────────────────────────────────────────── */
    #loading {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: rgba(26,31,46,0.9);
      border-radius: 8px;
      padding: 16px 24px;
      font-size: 13px;
      color: var(--texto-sec);
      z-index: 3000;
      display: none;
    }

    #loading.visible { display: block; }

    .spinner {
      display: inline-block;
      width: 12px;
      height: 12px;
      border: 2px solid var(--borde);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
      margin-right: 8px;
      vertical-align: middle;
    }

    @keyframes spin { to { transform: rotate(360deg); } }

    /* ── Responsive: ocultar sidebar en pantallas pequeñas ────────────── */
    @media (max-width: 600px) {
      #sidebar { display: none; }
    }

    /* ── Pantalla de login ────────────────────────────────────────────── */
    #login-screen {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: linear-gradient(135deg, #0d1117 0%, #1a1f2e 50%, #0d1117 100%);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 10000;
    }
    #login-screen.visible { display: flex; }
    #login-box {
      background: var(--sidebar-card);
      border: 1px solid var(--borde);
      border-radius: 12px;
      padding: 40px;
      width: 380px;
      max-width: 90vw;
      box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    }
    #login-header { text-align: center; margin-bottom: 28px; }
    #login-header h1 { font-size: 28px; color: var(--accent); margin-bottom: 6px; }
    #login-header p { font-size: 13px; color: var(--texto-sec); }
    .login-field { margin-bottom: 16px; }
    .login-field label {
      display: block; font-size: 11px; font-weight: 600;
      text-transform: uppercase; letter-spacing: 1px;
      color: var(--texto-sec); margin-bottom: 6px;
    }
    .login-field input {
      width: 100%; padding: 10px 14px;
      background: var(--sidebar-bg);
      border: 1px solid var(--borde); border-radius: 6px;
      color: var(--texto-prim); font-size: 14px; outline: none;
      transition: border-color 0.2s;
    }
    .login-field input:focus { border-color: var(--accent); }
    .login-field input::placeholder { color: #555; }
    #login-btn {
      width: 100%; padding: 12px;
      background: var(--accent); color: white;
      border: none; border-radius: 6px;
      font-size: 14px; font-weight: 600; cursor: pointer;
      transition: background 0.2s; margin-top: 8px;
    }
    #login-btn:hover { background: #3a8ee8; }
    #login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
    .login-error {
      background: rgba(231,76,60,0.15);
      border: 1px solid var(--alerta-rojo);
      border-radius: 6px; padding: 10px 14px;
      margin-bottom: 16px; font-size: 13px;
      color: var(--alerta-rojo); text-align: center;
    }

    /* ── Selector de empresa (admin) ──────────────────────────────────── */
    #empresa-selector-screen {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: linear-gradient(135deg, #0d1117 0%, #1a1f2e 50%, #0d1117 100%);
      display: none;
      align-items: center; justify-content: center;
      z-index: 10000;
    }
    #empresa-selector-screen.visible { display: flex; }
    #empresa-selector-box {
      background: var(--sidebar-card);
      border: 1px solid var(--borde); border-radius: 12px;
      padding: 40px; width: 480px; max-width: 90vw;
      max-height: 80vh; overflow-y: auto;
      box-shadow: 0 8px 32px rgba(0,0,0,0.5);
      text-align: center;
    }
    #empresa-selector-header h1 { font-size: 22px; color: var(--accent); margin-bottom: 6px; }
    #empresa-selector-header p { font-size: 12px; color: var(--texto-sec); margin-bottom: 20px; }
    #empresa-selector-list { display: flex; flex-direction: column; gap: 10px; }
    .empresa-selector-btn {
      display: flex; justify-content: space-between; align-items: center;
      padding: 16px 20px; background: var(--sidebar-bg);
      border: 1px solid var(--borde); border-radius: 8px;
      color: var(--texto-prim); font-size: 14px; font-weight: 600;
      cursor: pointer; transition: all 0.2s; text-align: left;
    }
    .empresa-selector-btn:hover { border-color: var(--accent); background: rgba(74,158,255,0.1); }
    #app-content {
      display: none;
      flex: 1;
      min-width: 0;
      min-height: 0;
    }
    #app-content.visible { display: flex; }

    /* ── Barra de menú superior ──────────────────────────────────────────── */
    #top-bar {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 48px;
      background: linear-gradient(135deg, #1a2744, #252c3e);
      border-bottom: 1px solid var(--borde);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20px;
      z-index: 2000;
    }

    #topbar-left {
      display: flex;
      align-items: center;
    }

    #topbar-left h1 {
      font-size: 15px;
      font-weight: 700;
      color: var(--accent);
      letter-spacing: 0.5px;
      margin: 0;
    }

    /* ── Botones de empresa en la barra superior ──────────────────────────── */
    #empresa-buttons {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-left: 14px;
      padding-left: 14px;
      border-left: 1px solid var(--borde);
    }

    .empresa-btn {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      border: 2px solid var(--borde);
      background: var(--sidebar-card);
      color: var(--texto-prim);
      font-size: 11px;
      font-weight: 700;
      cursor: pointer;
      transition: all 0.2s ease;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .empresa-btn:hover {
      border-color: var(--accent);
      color: var(--accent);
    }

    .empresa-btn.activa {
      border-color: var(--accent);
      background: var(--accent);
      color: white;
    }

    #topbar-right {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    /* ── Grupo de botones por empresa (real + simulación) ──────────────────── */
    .empresa-btn-group {
      display: flex;
      align-items: center;
      gap: 3px;
    }

    .empresa-btn-sim {
      width: 26px;
      height: 26px;
      border-radius: 50%;
      border: 2px solid var(--borde);
      background: var(--sidebar-card);
      font-size: 12px;
      cursor: pointer;
      transition: all 0.2s ease;
      display: flex;
      align-items: center;
      justify-content: center;
      line-height: 1;
      padding: 0;
    }

    .empresa-btn-sim:hover {
      border-color: #9b59b6;
      background: rgba(155, 89, 182, 0.2);
      transform: scale(1.1);
    }

    /* ── Modal de simulación ──────────────────────────────────────────── */
    #simulacion-modal {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.7);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 5000;
    }

    #simulacion-modal.visible { display: flex; }

    #simulacion-modal-content {
      background: var(--sidebar-bg);
      border: 1px solid var(--borde);
      border-radius: 12px;
      width: 560px;
      max-width: 95vw;
      max-height: 90vh;
      display: flex;
      flex-direction: column;
      box-shadow: 0 20px 60px rgba(0,0,0,0.7);
    }

    #simulacion-modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 16px 20px;
      border-bottom: 1px solid var(--borde);
    }

    #simulacion-modal-header h2 {
      font-size: 16px;
      color: var(--accent);
      margin: 0;
    }

    #simulacion-close-btn {
      background: none;
      border: none;
      color: var(--texto-sec);
      font-size: 18px;
      cursor: pointer;
      padding: 4px;
    }

    #simulacion-close-btn:hover { color: var(--texto-prim); }

    #simulacion-modal-body {
      flex: 1;
      overflow-y: auto;
      padding: 16px 20px;
    }

    #simulacion-fechas {
      display: flex;
      gap: 16px;
      margin-bottom: 16px;
      padding-bottom: 16px;
      border-bottom: 1px solid var(--borde);
    }

    .sim-fecha-group {
      display: flex;
      flex-direction: column;
      gap: 4px;
      flex: 1;
    }

    .sim-fecha-group label {
      font-size: 10px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--texto-sec);
    }

    .sim-date-input, .sim-time-input {
      background: var(--sidebar-card);
      color: var(--texto-prim);
      border: 1px solid var(--borde);
      border-radius: 4px;
      padding: 6px 10px;
      font-size: 12px;
    }

    .sim-date-input:focus, .sim-time-input:focus {
      border-color: var(--accent);
      outline: none;
    }

    #simulacion-inputs {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .sim-ch-block {
      background: var(--sidebar-card);
      border: 1px solid var(--borde);
      border-radius: 8px;
      padding: 12px;
    }

    .sim-ch-header {
      font-size: 12px;
      font-weight: 600;
      color: var(--accent);
      margin-bottom: 8px;
    }

    .sim-ch-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
      gap: 6px;
    }

    .sim-cont-field {
      display: flex;
      flex-direction: column;
      gap: 2px;
    }

    .sim-cont-field label {
      font-size: 10px;
      color: var(--texto-sec);
      font-weight: 600;
    }

    .sim-cont-input {
      background: var(--sidebar-bg);
      color: var(--texto-prim);
      border: 1px solid var(--borde);
      border-radius: 4px;
      padding: 4px 8px;
      font-size: 12px;
      width: 100%;
    }

    .sim-cont-input:focus {
      border-color: var(--accent);
      outline: none;
    }

    #simulacion-modal-footer {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 14px 20px;
      border-top: 1px solid var(--borde);
    }

    #simulacion-cancel-btn {
      padding: 8px 16px;
      background: transparent;
      color: var(--texto-sec);
      border: 1px solid var(--borde);
      border-radius: 6px;
      font-size: 13px;
      cursor: pointer;
      transition: all 0.2s;
    }

    #simulacion-cancel-btn:hover {
      border-color: var(--texto-sec);
      color: var(--texto-prim);
    }

    #simulacion-simular-btn {
      padding: 8px 20px;
      background: #9b59b6;
      color: white;
      border: none;
      border-radius: 6px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.2s;
    }

    #simulacion-simular-btn:hover {
      background: #8e44ad;
    }

    #simulacion-simular-btn:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    /* ── Indicador de modo simulación en el mapa ──────────────────────── */
    #simulacion-indicator {
      position: absolute;
      top: 10px;
      left: 10px;
      background: rgba(155, 89, 182, 0.9);
      color: white;
      padding: 6px 12px;
      border-radius: 6px;
      font-size: 11px;
      font-weight: 600;
      z-index: 500;
      display: none;
      align-items: center;
      gap: 6px;
    }

    #simulacion-indicator.visible { display: flex; }

    /* ── Puntos de interés (receptores, etc.) ──────────────────────────── */
    .poi-marcador {
      background: transparent;
      border: none;
    }

    .poi-pin {
      display: block;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: #f59e0b;
      border: 2px solid #ffffff;
      box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.4);
      transition: transform 0.15s ease, background 0.15s ease;
    }

    .poi-marcador:hover .poi-pin {
      background: #fbbf24;
      transform: scale(1.2);
    }

    .leaflet-tooltip.poi-tooltip {
      background: var(--sidebar-card);
      border: 1px solid var(--borde);
      color: var(--texto-prim);
      font-size: 11px;
      line-height: 1.35;
      padding: 6px 8px;
      border-radius: 6px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
      white-space: nowrap;
    }

    .leaflet-tooltip.poi-tooltip::before {
      border-top-color: var(--borde);
    }

    .poi-tooltip-nombre {
      font-weight: 700;
      margin-bottom: 2px;
    }

    .poi-tooltip-coords {
      color: var(--texto-sec);
      font-size: 10px;
    }

    /* ── Ventana flotante: Puntos de interés ───────────────────────────── */
    #poi-window {
      position: fixed;
      right: 20px;
      bottom: 20px;
      width: min(400px, 92vw);
      max-height: min(52vh, 420px);
      display: none;
      flex-direction: column;
      background: #0b1220;
      border: 1px solid var(--borde);
      border-radius: 10px;
      box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
      z-index: 1400;
      overflow: hidden;
      font-size: 11px;
    }

    #poi-window.visible { display: flex; }
    #poi-window.minimizada { max-height: none; }

    #poi-window-header {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 7px 8px;
      background: #111827;
      border-bottom: 1px solid var(--borde);
      cursor: grab;
      touch-action: none;
      user-select: none;
    }

    #poi-window-header.dragging { cursor: grabbing; }

    #poi-window-title {
      font-weight: 700;
      color: var(--texto-prim);
      white-space: nowrap;
    }

    #poi-window-subtitle {
      flex: 1;
      color: var(--texto-sec);
      font-size: 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    #poi-window-min,
    #poi-window-close {
      background: transparent;
      border: none;
      color: var(--texto-sec);
      cursor: pointer;
      line-height: 1;
      padding: 2px 4px;
      font-size: 13px;
    }

    #poi-window-min { font-size: 12px; }

    #poi-window-min:hover,
    #poi-window-close:hover { color: var(--texto-prim); }

    #poi-window.minimizada #poi-window-subtitle,
    #poi-window.minimizada #poi-window-body { display: none; }

    #poi-window-body {
      overflow: auto;
      min-height: 40px;
    }

    #poi-window table {
      width: 100%;
      table-layout: fixed;
      border-collapse: collapse;
    }

    #poi-window th,
    #poi-window td {
      padding: 4px 8px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
      white-space: nowrap;
    }

    #poi-window thead th {
      position: sticky;
      top: 0;
      z-index: 2;
      background: #111827;
      color: var(--texto-sec);
      font-size: 10px;
      font-weight: 600;
      text-align: right;
    }

    #poi-window thead th.poi-nombre { text-align: left; }

    #poi-window td.poi-punto {
      text-align: left;
      color: var(--texto-prim);
      overflow: hidden;
      text-overflow: ellipsis;
    }

    #poi-window th.poi-valor,
    #poi-window td.poi-valor {
      width: 96px;
      text-align: right;
      font-variant-numeric: tabular-nums;
      font-weight: 600;
    }

    #poi-window td.poi-valor.poi-sin-dato {
      background: #0b1220;
      color: var(--texto-sec);
      font-style: italic;
      font-weight: 400;
    }

    #poi-window .poi-vacio {
      padding: 10px 12px;
      color: var(--texto-sec);
      font-style: italic;
    }

    /* Botones de paso de la simulación (desactivados en los extremos) */
    #sim-prev:disabled,
    #sim-next:disabled {
      opacity: 0.35;
      cursor: default;
    }
