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

:root {
    --bg: #090D16;
    --bg2: #111827;
    --bg3: #1F2937;
    --border: #2D3748;
    --text: #F3F4F6;
    --muted: #9CA3AF;
    --green: #00FF66;
    --red: #FF0055;
    --amber: #FFB800;
    --blue: #00F0FF;
    --green-dim: rgba(0, 255, 102, 0.1);
    --red-dim: rgba(255, 0, 85, 0.12);
    --amber-dim: rgba(255, 184, 0, 0.12);
    --blue-dim: rgba(0, 240, 255, 0.1);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    min-height: 100vh;
    overflow-x: hidden;
}

#fiber-bar {
    height: 3px;
    width: 100%;
    background: linear-gradient(90deg, var(--green), var(--blue), var(--green));
    background-size: 200% 100%;
    animation: fiber-flow 3s linear infinite;
    box-shadow: 0 0 10px var(--blue);
    transition: all 0.5s ease;
}
#fiber-bar.alerta {
    background: linear-gradient(90deg, var(--red), var(--amber), var(--red));
    background-size: 200% 100%;
    animation: fiber-flow 0.8s linear infinite;
    box-shadow: 0 0 15px var(--red);
}
@keyframes fiber-flow { 0% { background-position: 0% 0%; } 100% { background-position: 200% 0%; } }

header {
    padding: 16px 24px;
    background: rgba(17, 24, 39, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.logo {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo-accent { color: var(--blue); text-shadow: 0 0 8px rgba(0,240,255,0.4); }
.logo span { color: var(--muted); font-weight: 400; }

#estado-global {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    background: var(--bg3);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
}
.radar-box { position: relative; width: 10px; height: 10px; display: flex; align-items: center; justify-content: center; }
#dot-status { width: 8px; height: 8px; border-radius: 50%; background: var(--green); z-index: 2; }
.ping { position: absolute; width: 100%; height: 100%; border-radius: 50%; background: var(--green); animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite; opacity: 0.7; }
@keyframes ping { 75%, 100% { transform: scale(2.5); opacity: 0; } }
#dot-status.alerta, .ping.alerta { background: var(--red); }

#temp-banner {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 24px;
    background: var(--red);
    color: #fff;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 49;
    animation: temp-blink 1s ease-in-out infinite;
}
@keyframes temp-blink { 0%, 100% { background: var(--red); } 50% { background: #A8003D; } }
#btn-silenciar {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
}
#btn-silenciar:hover { background: rgba(255,255,255,0.25); }

#resumen-sedes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding: 20px 24px;
    background: var(--bg);
}
.sede-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.sede-card:hover { transform: translateY(-3px); border-color: var(--muted); }
.sede-card.activa { border-color: var(--blue); box-shadow: 0 0 15px rgba(0, 240, 255, 0.15); background: var(--bg3); }
.sede-card.alerta-critica { border-color: var(--red); box-shadow: 0 0 15px rgba(255, 0, 85, 0.2); }
.sede-card.alerta-media { border-color: var(--amber); box-shadow: 0 0 15px rgba(255, 184, 0, 0.15); }

.sede-nombre { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center;}
.sede-nums { display: flex; align-items: baseline; gap: 8px; }
.num-caidos { font-family: 'JetBrains Mono', monospace; font-size: 32px; font-weight: 700; color: var(--red); line-height: 1; text-shadow: 0 0 10px rgba(255,0,85,0.3); }
.num-caidos.ok { color: var(--green); text-shadow: 0 0 10px rgba(0,255,102,0.3); }
.num-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.sede-bar { margin-top: 14px; height: 4px; background: rgba(255,255,255,0.05); border-radius: 4px; overflow: hidden; }
.sede-bar-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease; }

#controles {
    padding: 0 24px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.control-group {
    display: flex;
    background: var(--bg2);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
    gap: 4px;
}
.btn-filtro {
    padding: 6px 14px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}
.btn-filtro:hover { color: var(--text); }
.btn-filtro.activo { background: var(--bg3); color: var(--text); font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.btn-filtro.los.activo { background: var(--red-dim); color: var(--red); border: 1px solid rgba(255,0,85,0.3); }
.btn-filtro.senal.activo { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(255,184,0,0.3); }
.btn-filtro.dup.activo { background: rgba(180,100,255,0.12); color: #B464FF; border: 1px solid rgba(180,100,255,0.35); }

#buscar {
    margin-left: auto;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--text);
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    width: 240px;
    outline: none;
    transition: all 0.2s;
}
#buscar:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,240,255,0.1); }
#buscar::placeholder { color: var(--muted); }

#btn-refresh {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}
#btn-refresh:hover { border-color: var(--blue); color: var(--blue); }
#btn-refresh.cargando { animation: spin 1s linear infinite; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

#btn-probar-alarma {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255,0,85,0.35);
    background: var(--red-dim);
    color: var(--red);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}
#btn-probar-alarma:hover { background: rgba(255,0,85,0.2); }

#tabla-wrap { overflow-x: auto; padding: 0 24px 30px; }
table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
thead th:hover { color: var(--blue); }
thead th.sort-asc::after { content: ' ↑'; color: var(--blue); }
thead th.sort-desc::after { content: ' ↓'; color: var(--blue); }

tbody tr {
    background: var(--bg2);
    transition: all 0.2s;
    animation: fadeIn 0.3s ease forwards;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

tbody tr:hover {
    background: var(--bg3);
    transform: scale(1.002);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
tbody td { padding: 12px 14px; vertical-align: middle; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
tbody tr td:first-child { border-left: 1px solid var(--border); border-radius: 8px 0 0 8px; }
tbody tr td:last-child { border-right: 1px solid var(--border); border-radius: 0 8px 8px 0; }

tbody tr.row-los td:first-child { border-left: 4px solid var(--red); }
tbody tr.row-senal td:first-child { border-left: 4px solid var(--amber); }

.cod { font-family: 'JetBrains Mono', monospace; font-size: 13px; font-weight: 700; color: var(--blue); }
.cliente-nombre { color: var(--text); font-weight: 500; font-size: 13px; }
.cliente-zona { color: var(--muted); font-size: 11px; margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; font-family: 'JetBrains Mono', monospace; white-space: nowrap; }
.badge-los { background: var(--red-dim); color: var(--red); border: 1px solid rgba(255,0,85,0.3); }
.badge-senal { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(255,184,0,0.3); }
.badge-sede { background: var(--blue-dim); color: var(--blue); border: 1px solid rgba(0,240,255,0.2); }

.tiempo-cell { font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tiempo-critico { color: var(--red); text-shadow: 0 0 8px rgba(255,0,85,0.4); display: flex; align-items: center; gap: 6px; }
.tiempo-medio { color: var(--amber); }
.tiempo-reciente { color: var(--blue); }
.pulse-tag { background: var(--red); color: #000; font-size: 9px; padding: 1px 5px; border-radius: 3px; font-weight: 800; animation: pulse-tag 1s infinite alternate; }
@keyframes pulse-tag { from { opacity: 0.8; } to { opacity: 1; box-shadow: 0 0 8px var(--red); } }

.pon-cell { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); background: rgba(0,0,0,0.2); padding: 4px 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.05); }
#empty { display: none; padding: 60px 24px; text-align: center; color: var(--muted); background: var(--bg2); border-radius: 12px; border: 1px dashed var(--border); margin-top: 10px; }
#empty .icon { font-size: 40px; margin-bottom: 12px; }
#empty p { font-size: 14px; font-weight: 500; }

#panel-duplicados { display: none; padding: 0 24px 30px; }
.dup-card { background: var(--bg2); border: 1px solid rgba(180,100,255,0.3); border-radius: 10px; padding: 14px 18px; margin-bottom: 12px; }
.dup-ip { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 700; color: #B464FF; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.dup-clientes { display: flex; flex-wrap: wrap; gap: 8px; }
.dup-cliente { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 12px; }
.dup-cliente .cod { display: block; }
.dup-cliente .nombre { color: var(--muted); font-size: 11px; margin-top: 2px; }

#footer { position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 24px; background: var(--bg2); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--muted); z-index: 10; }
#footer strong { color: var(--text); }
#loading { position: fixed; inset: 0; background: rgba(9, 13, 22, 0.9); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 100; font-family: 'JetBrains Mono', monospace; color: var(--blue); font-size: 15px; font-weight: 600; letter-spacing: 0.1em; transition: opacity 0.3s; }
#loading.oculto { opacity: 0; pointer-events: none; }