:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  --online:  #22c55e;
  --idle:    #f59e0b;
  --offline: #8b95a5;

  --p-ysf: #3b82f6;
  --p-fcs: #a855f7;
  --p-xlx: #14b8a6;
  --p-bm:  #f97316;
  --p-dmr: #ec4899;

  --radius: 14px;
  --panel-w: 390px;
}

[data-theme="dark"] {
  --bg:        #0b0f14;
  --panel:     rgba(17, 22, 30, .86);
  --panel-solid: #11161e;
  --card:      rgba(255, 255, 255, .04);
  --card-hi:   rgba(255, 255, 255, .08);
  --line:      rgba(255, 255, 255, .08);
  --text:      #e8edf3;
  --text-2:    #a3adbb;
  --text-3:    #6b7686;
  --accent:    #38bdf8;
  --shadow:    0 20px 50px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .06);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg:        #eef1f5;
  --panel:     rgba(255, 255, 255, .88);
  --panel-solid: #ffffff;
  --card:      rgba(15, 23, 42, .035);
  --card-hi:   rgba(15, 23, 42, .07);
  --line:      rgba(15, 23, 42, .09);
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #8a94a6;
  --accent:    #0284c7;
  --shadow:    0 20px 50px rgba(15, 23, 42, .18), 0 0 0 1px rgba(15, 23, 42, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

#map { position: fixed; inset: 0; }

/* ── Panel ─────────────────────────────────────────────────────────────── */

.panel {
  position: fixed;
  top: 16px; left: 16px; bottom: 16px;
  width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-radius: 20px;
  box-shadow: var(--shadow);
  z-index: 2;
  overflow: hidden;
}
.sheet-handle { display: none; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { width: 40px; height: 40px; border-radius: 11px; object-fit: cover; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-title span { color: var(--accent); }
.brand-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--online);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: live 2s infinite;
}
.live-dot.stale { background: var(--offline); animation: none; }
@keyframes live { 70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }

.head-actions { display: flex; gap: 6px; }
.icon-btn {
  height: 34px; min-width: 34px; padding: 0 8px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: var(--card); color: var(--text-2);
  font-size: 12px; font-weight: 600;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--card-hi); color: var(--text); }
[data-theme="dark"] .i-moon, [data-theme="light"] .i-sun { display: none; }

.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 16px; }
.stat {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 10px 12px 9px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card);
  text-align: left;
  transition: opacity .15s, border-color .15s, background .15s;
}
.stat::before {
  content: ""; position: absolute; top: 12px; right: 12px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--c);
}
.stat[data-status="online"]  { --c: var(--online); }
.stat[data-status="idle"]    { --c: var(--idle); }
.stat[data-status="offline"] { --c: var(--offline); }
.stat b { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.stat:not(.on) { opacity: .42; }
.stat:hover { background: var(--card-hi); }

/* Búsqueda */
.search {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 16px 10px; padding: 0 12px;
  height: 42px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card);
  color: var(--text-3);
  transition: border-color .15s;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; }
.search input::placeholder { color: var(--text-3); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 99px;
  background: transparent; color: var(--text-2);
  font-size: 12px; font-weight: 600;
  transition: all .15s;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--text-3)); }
.chip:hover { background: var(--card-hi); }
.chip.on { background: color-mix(in srgb, var(--c, var(--accent)) 18%, transparent);
           border-color: color-mix(in srgb, var(--c, var(--accent)) 55%, transparent);
           color: var(--text); }

.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px 8px;
  font-size: 12px; color: var(--text-3);
  border-bottom: 1px solid var(--line);
}
.list-head select {
  border: 0; background: transparent; color: var(--text-2);
  font-size: 12px; cursor: pointer; outline: 0;
}
.list-head select option { background: var(--panel-solid); }

/* Lista */
.list { list-style: none; margin: 0; padding: 6px 8px 8px; overflow-y: auto; flex: 1; min-height: 0; }
.list, #detail { scrollbar-width: thin; scrollbar-color: var(--card-hi) transparent; }
.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-thumb { background: var(--card-hi); border-radius: 8px; }
.node {
  display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px;
  align-items: center;
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .12s;
}
.node:hover, .node.hover { background: var(--card-hi); }
.node .dot { grid-row: span 2; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.node .dot.online { box-shadow: 0 0 0 4px color-mix(in srgb, var(--online) 22%, transparent); }
.node .call { font-weight: 700; letter-spacing: .01em; }
.node .ago { font-size: 11.5px; color: var(--text-3); text-align: right; white-space: nowrap; }
.node .sub {
  grid-column: 2 / 4;
  display: flex; align-items: center; gap: 8px; min-width: 0;
  font-size: 12px; color: var(--text-2);
}
.node .sub .ref { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .sub .mono { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.empty { padding: 40px 16px; text-align: center; color: var(--text-3); }

.proto {
  display: inline-flex; align-items: center;
  height: 18px; padding: 0 6px;
  border-radius: 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent);
  flex: none;
}

/* Detalle */
.back {
  display: inline-flex; align-items: center; gap: 4px;
  margin: 0 12px 4px; padding: 6px 8px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--text-2); font-size: 13px; align-self: flex-start;
}
.back:hover { background: var(--card); color: var(--text); }
#detail { overflow-y: auto; padding: 4px 16px 16px; flex: 1; min-height: 0; }

.d-hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.d-call { font-size: 30px; font-weight: 700; letter-spacing: -.01em; line-height: 1.05; }
.d-call a { color: inherit; text-decoration: none; }
.d-call a:hover { color: var(--accent); }
.d-model { color: var(--text-2); font-size: 13px; margin-top: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--c); background: color-mix(in srgb, var(--c) 15%, transparent);
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }

.d-freq {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line); border-radius: var(--radius); overflow: hidden;
  margin-bottom: 12px;
}
.d-freq > div { background: var(--panel-solid); padding: 12px 14px; }
.d-freq small { display: block; font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.d-freq b { font-family: var(--mono); font-size: 19px; font-weight: 500; }
.d-freq b em { font-style: normal; font-size: 12px; color: var(--text-3); margin-left: 3px; }

.d-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin-bottom: 12px; }
.d-card h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0; padding: 11px 14px 8px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3);
}
.d-card h3 svg { width: 14px; height: 14px; }
.d-row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.d-row span { color: var(--text-2); }
.d-row b { font-weight: 500; text-align: right; overflow-wrap: anywhere; }
.d-row b.mono { font-family: var(--mono); font-size: 12.5px; }
.badge-warn { margin-left: 6px; font-size: 10.5px; font-weight: 700; color: var(--idle); }
.badge-ok { margin-left: 6px; font-size: 10.5px; font-weight: 700; color: var(--online); }

.panel-foot {
  padding: 10px 16px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--text-3);
}
.panel-foot a { color: var(--text-2); text-decoration: none; }
.panel-foot a:hover { color: var(--accent); }

/* ── Mapa ──────────────────────────────────────────────────────────────── */

.maplibregl-ctrl-group {
  background: var(--panel) !important;
  backdrop-filter: blur(12px);
  border-radius: 12px !important;
  box-shadow: var(--shadow) !important;
}
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-attrib { background: var(--panel) !important; color: var(--text-2) !important; font-size: 11px; }
.maplibregl-ctrl-attrib a { color: var(--text-2) !important; }
[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }

.maplibregl-popup-content {
  background: var(--panel-solid); color: var(--text);
  padding: 8px 12px; border-radius: 10px;
  box-shadow: var(--shadow);
  font: 12px/1.35 var(--font);
}
.maplibregl-popup-tip { display: none; }
.tip-call { font-weight: 700; font-size: 13px; }
.tip-sub { color: var(--text-2); }

/* ── Móvil: bottom sheet ───────────────────────────────────────────────── */

@media (max-width: 760px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto; height: 46vh;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transition: height .25s ease;
  }
  .panel.expanded { height: 88vh; }
  .panel.collapsed { height: 132px; }
  .sheet-handle {
    display: grid; place-items: center;
    height: 20px; border: 0; background: transparent; flex: none;
  }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 4px; background: var(--text-3); opacity: .5; }
  .panel-head { padding-top: 2px; }
  .panel-foot { display: none; }
  .maplibregl-ctrl-top-right { top: 0; }
}
