:root {
  --bg: #070b16;
  --bg2: #0b1222;
  --panel: rgba(18, 27, 48, .72);
  --panel-solid: #121b30;
  --panel2: #18233d;
  --border: rgba(120, 140, 190, .16);
  --border-strong: rgba(120, 140, 190, .3);
  --text: #e8eeff;
  --muted: #8d99bb;
  --dim: #5f6b8c;
  --accent: #34e1c8;
  --accent-2: #7b8bff;
  --temp: #ff8a4c;
  --hum: #41b8ff;
  --ok: #3ddc84;
  --warn: #ffbe4d;
  --danger: #ff5c7a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(123, 139, 255, .14), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(52, 225, 200, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.ico { width: 20px; height: 20px; flex: none; }

/* ------------------------------------------------ layout */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 22px 16px;
  background: rgba(8, 13, 26, .85);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; color: var(--text); padding: 4px 10px; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); font-weight: 800; }
.brand-dot {
  width: 30px; height: 30px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), transparent 30%, transparent);
  border: 2px solid rgba(52, 225, 200, .5);
  animation: spin 3s linear infinite;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px;
  color: var(--muted); font-weight: 500;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: rgba(123, 139, 255, .08); color: var(--text); text-decoration: none; }
.sidebar nav a.active {
  background: linear-gradient(90deg, rgba(52, 225, 200, .16), rgba(52, 225, 200, .02));
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar nav a.active .ico { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; font-size: 13px; }
.logout { color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(61, 220, 132, .6); animation: pulse 2s infinite; }

.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 28px; font-weight: 800; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

/* ------------------------------------------------ componentes */
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.g-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.g-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.mt2 { margin-top: 28px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 16px; font-weight: 700; }
.card-head .ico { color: var(--accent); }
.card-head .right { margin-left: auto; }

.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 34px; font-weight: 800; letter-spacing: -.03em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.kpi .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.kpi::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%;
  background: var(--glow, rgba(52, 225, 200, .12)); filter: blur(10px);
}
.kpi.temp { --glow: rgba(255, 138, 76, .18); }
.kpi.temp .value { color: #ffb38a; }
.kpi.hum { --glow: rgba(65, 184, 255, .18); }
.kpi.hum .value { color: #8fd3ff; }
.kpi.plane { --glow: rgba(123, 139, 255, .2); }
.kpi.alert { --glow: rgba(255, 92, 122, .18); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: rgba(141, 153, 187, .14); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: rgba(61, 220, 132, .14); color: var(--ok); }
.badge.warn { background: rgba(255, 190, 77, .14); color: var(--warn); }
.badge.danger { background: rgba(255, 92, 122, .16); color: var(--danger); }
.badge.info { background: rgba(123, 139, 255, .16); color: #a9b4ff; }
.badge.plain::before { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 9px 16px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--panel2); color: var(--text);
  transition: transform .1s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #22b8a4); color: #04211d; border: 0; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 9px; }
.btn-ghost { background: transparent; }

.tabs { display: inline-flex; background: rgba(8, 13, 26, .6); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 2px; }
.tabs button {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  background: transparent; border: 0; padding: 7px 13px; border-radius: 9px; cursor: pointer;
}
.tabs button.on { background: var(--panel2); color: var(--text); box-shadow: 0 0 0 1px var(--border-strong); }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select {
  font: inherit; color: var(--text); background: rgba(8, 13, 26, .7);
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 225, 200, .15); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }

.table-wrap { overflow-x: auto; margin: 0 -6px; }
table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tabla th { text-align: left; color: var(--dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tabla td { padding: 10px; border-bottom: 1px solid rgba(120, 140, 190, .08); white-space: nowrap; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla tbody tr { transition: background .12s; }
.tabla tbody tr:hover { background: rgba(123, 139, 255, .06); }
.tabla .num { text-align: right; }
.empty { color: var(--dim); text-align: center; padding: 26px 10px; }

.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 220px; }

.method { font-family: var(--mono); font-size: 11px; font-weight: 600; padding: 3px 7px; border-radius: 6px; background: rgba(52, 225, 200, .14); color: var(--accent); }
.method.POST { background: rgba(255, 190, 77, .14); color: var(--warn); }
.method.DELETE { background: rgba(255, 92, 122, .14); color: var(--danger); }
.method.GETPOST { background: rgba(123, 139, 255, .16); color: #a9b4ff; }

.trend { font-weight: 600; font-size: 13px; }
.trend.acercando { color: var(--ok); }
.trend.alejando { color: var(--muted); }
.trend.estable { color: var(--warn); }

.switch { position: relative; width: 40px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--panel2); border: 1px solid var(--border-strong); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: rgba(52, 225, 200, .25); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); background: var(--accent); }

.feed { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow-y: auto; }
.feed-item { background: rgba(8, 13, 26, .55); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; white-space: pre-line; }
.feed-item .meta { display: flex; gap: 8px; align-items: center; color: var(--dim); font-size: 12px; margin-bottom: 4px; white-space: normal; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 1px dashed var(--border-strong); background: transparent; color: var(--muted); cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--text); }

/* ------------------------------------------------ toast y modal */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 2000;
  background: var(--panel-solid); border: 1px solid var(--border-strong); border-left: 4px solid var(--ok);
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow);
  transform: translateY(140%); transition: transform .25s; max-width: 360px;
}
.toast.show { transform: none; }
.toast.err { border-left-color: var(--danger); }
.modal-bg { position: fixed; inset: 0; background: rgba(3, 6, 14, .7); backdrop-filter: blur(4px); z-index: 1500; display: grid; place-items: center; padding: 16px; }
.modal { width: min(440px, 100%); background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.modal h3 { font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ------------------------------------------------ bienvenida */
.hero {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: center;
  padding: 34px 36px; border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(52, 225, 200, .10), rgba(123, 139, 255, .10)),
    var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.hero h1 { font-size: clamp(30px, 4vw, 46px); font-weight: 800; }
.hero h1 span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p.lead { color: var(--muted); font-size: 17px; margin: 14px 0 22px; max-width: 560px; }
.hero .clock { font-family: var(--mono); color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.radar {
  position: relative; width: min(300px, 70vw); aspect-ratio: 1; margin: 0 auto; border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 24%, rgba(52, 225, 200, .22) 24.4% 25%, transparent 25.4% 49%, rgba(52, 225, 200, .22) 49.4% 50%, transparent 50.4% 74%, rgba(52, 225, 200, .22) 74.4% 75%, transparent 75.4%),
    radial-gradient(circle, rgba(52, 225, 200, .08), rgba(7, 11, 22, .9) 70%);
  border: 1px solid rgba(52, 225, 200, .35);
  box-shadow: 0 0 60px rgba(52, 225, 200, .15), inset 0 0 40px rgba(52, 225, 200, .08);
}
.radar::before, .radar::after { content: ""; position: absolute; background: rgba(52, 225, 200, .18); }
.radar::before { left: 50%; top: 0; bottom: 0; width: 1px; }
.radar::after { top: 50%; left: 0; right: 0; height: 1px; }
.radar .sweep { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(from 0deg, rgba(52, 225, 200, .45), rgba(52, 225, 200, 0) 22%); animation: spin 4s linear infinite; }
.radar .blip { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: blip 4s ease-out infinite; }
.radar .center { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 14px var(--accent-2); }

.modules { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.module { display: flex; flex-direction: column; gap: 10px; color: var(--text); transition: transform .15s, border-color .15s; }
.module:hover { transform: translateY(-3px); border-color: var(--border-strong); text-decoration: none; }
.module .mi { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(52, 225, 200, .12); color: var(--accent); }
.module .mi .ico { width: 22px; height: 22px; }
.module h3 { font-size: 17px; }
.module p { margin: 0; color: var(--muted); font-size: 14px; }
.module .go { margin-top: auto; color: var(--accent); font-weight: 600; font-size: 14px; }

/* ------------------------------------------------ mapa */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; }
#mapa { height: 560px; border-radius: var(--radius); border: 1px solid var(--border); background: #0a0f1d; }
.leaflet-container { font-family: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-solid); color: var(--text); border: 1px solid var(--border-strong); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.55; }
.leaflet-control-attribution { background: rgba(7, 11, 22, .7) !important; color: var(--dim) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.plane-ico { transition: transform .4s; filter: drop-shadow(0 0 4px rgba(0, 0, 0, .8)); }
.plane-label { background: rgba(7, 11, 22, .8); border: 0; color: var(--text); font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 4px; box-shadow: none; }
.plane-label::before { display: none; }
.rx-ico { width: 16px; height: 16px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 0 0 rgba(123, 139, 255, .7); animation: pulse2 2s infinite; border: 2px solid #fff; }
.side-list { display: flex; flex-direction: column; gap: 8px; max-height: 560px; overflow-y: auto; padding-right: 2px; }
.plane-card { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 11px 13px; border-radius: 12px; background: rgba(8, 13, 26, .55); border: 1px solid var(--border); cursor: pointer; }
.plane-card:hover, .plane-card.sel { border-color: var(--accent); }
.plane-card .n { font-weight: 700; font-family: var(--mono); }
.plane-card .d { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.plane-card .s { color: var(--muted); font-size: 12.5px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ------------------------------------------------ login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 30px; }
.login-card .radar { width: 120px; margin-bottom: 4px; }
.login-card h1 { font-size: 24px; text-align: center; }
.error-msg { color: var(--danger); background: rgba(255, 92, 122, .1); border: 1px solid rgba(255, 92, 122, .3); padding: 9px 12px; border-radius: 10px; font-size: 14px; }

/* ------------------------------------------------ animaciones */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, .6); } 70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); } }
@keyframes pulse2 { 0% { box-shadow: 0 0 0 0 rgba(123, 139, 255, .7); } 70% { box-shadow: 0 0 0 14px rgba(123, 139, 255, 0); } 100% { box-shadow: 0 0 0 0 rgba(123, 139, 255, 0); } }
@keyframes blip { 0%, 100% { opacity: 0; transform: scale(.6); } 10% { opacity: 1; transform: scale(1.3); } 60% { opacity: .2; transform: scale(1); } }
.fade-in { animation: fade .4s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .map-layout { grid-template-columns: 1fr; }
  .side-list { max-height: 380px; }
  .hero { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; height: auto; z-index: 1000; flex-direction: row; align-items: center; padding: 10px 12px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand span:last-child { display: none; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 2px; flex: 1; scrollbar-width: none; }
  .sidebar nav a { padding: 9px 11px; white-space: nowrap; }
  .sidebar nav a span { display: none; }
  .sidebar nav a.active span { display: inline; }
  .sidebar-foot { margin: 0; padding: 0; }
  .sidebar-foot .live { display: none; }
  .main { padding: 18px 16px 40px; }
  .g-2 { grid-template-columns: 1fr; }
  #mapa { height: 420px; }
  .hero { padding: 24px 20px; }
  .kpi .value { font-size: 28px; }
}
