/* FiberGIS UI — sin fuentes ni assets externos */
:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent2: #2563eb;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font: inherit; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 20% 0%, #1e3a5f 0%, var(--bg) 55%); padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--bg2); padding: 2.2rem 2rem 2.4rem;
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45); text-align: center;
}
.login-card h1 { margin: .4rem 0 0; letter-spacing: .5px; }
.login-sub { color: var(--muted); margin: .3rem 0 1.4rem; font-size: .9rem; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: .8rem; color: var(--muted); margin: .9rem 0 .25rem; }
.login-card input {
  width: 100%; padding: .7rem .8rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 1rem; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; margin-top: 1.4rem; padding: .75rem; border: 0; border-radius: 8px;
  background: linear-gradient(90deg, var(--accent2), var(--accent)); color: white;
  font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-error {
  background: rgba(248,113,113,.12); color: var(--danger); border: 1px solid rgba(248,113,113,.4);
  padding: .5rem .8rem; border-radius: 8px; font-size: .85rem; margin-bottom: .4rem;
}

/* ---------- Layout ---------- */
#app { display: flex; height: 100vh; height: 100dvh; }
#sidebar {
  width: 290px; min-width: 290px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem; gap: 1.1rem; overflow-y: auto; z-index: 1200;
}
.brand { display: flex; align-items: center; gap: .6rem; font-size: 1.25rem; font-weight: 700; letter-spacing: .5px; }
.brand img { border-radius: 7px; }
.brand .icon-btn { margin-left: auto; }
#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0b1120; }
.only-mobile { display: none !important; }

/* ---------- Sidebar widgets ---------- */
section h3, .isp-switch label {
  display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  margin: 0 0 .45rem; font-weight: 600;
}
select, input, textarea { font: inherit; }
.isp-switch select {
  width: 100%; padding: .55rem .6rem; border-radius: 8px; background: var(--bg3);
  color: var(--text); border: 1px solid var(--border);
}
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.stat { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .7rem; }
.stat b { display: block; font-size: 1.2rem; }
.stat span { font-size: .72rem; color: var(--muted); }

.layer-row {
  display: flex; align-items: center; gap: .6rem; padding: .38rem .35rem; border-radius: 8px;
  cursor: pointer; font-size: .92rem;
}
.layer-row:hover { background: var(--bg3); }
.layer-row input { accent-color: var(--accent); width: 16px; height: 16px; }
.layer-row .count { margin-left: auto; color: var(--muted); font-size: .78rem; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.swatch.line { height: 4px; width: 16px; border-radius: 2px; }
.swatch.square { border-radius: 3px; }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.tool {
  display: flex; align-items: center; gap: .45rem;
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .5rem; font-size: .83rem; cursor: pointer; text-align: left;
}
.tool .ti { width: 1.2em; text-align: center; color: var(--accent); font-weight: 700; }
.tool:hover { border-color: var(--accent); }
.tool.active { border-color: var(--accent); background: rgba(56,189,248,.14); }
.hint { font-size: .8rem; color: var(--accent); min-height: 1em; margin: .5rem 0 0; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: .8rem; font-size: .85rem; }
.userline { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.role-badge { background: var(--bg3); border: 1px solid var(--border); padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; color: var(--accent); }
.footlink { color: var(--muted); text-decoration: none; margin-right: .9rem; }
.footlink:hover { color: var(--text); }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; }

/* ---------- Topbar / búsqueda ---------- */
#topbar {
  position: absolute; top: 12px; left: 56px; right: 12px; z-index: 1000;
  display: flex; gap: .5rem; align-items: flex-start; pointer-events: none; max-width: 560px;
}
#topbar > * { pointer-events: auto; }
.search { position: relative; flex: 1; }
.search input {
  width: 100%; padding: .65rem .9rem; border-radius: 10px; border: 1px solid var(--border);
  background: rgba(30,41,59,.96); color: var(--text); box-shadow: 0 8px 24px rgba(0,0,0,.35); outline: none;
}
.search input:focus { border-color: var(--accent); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 10px; max-height: 50vh; overflow-y: auto;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
}
.search-item { padding: .55rem .8rem; cursor: pointer; display: flex; gap: .6rem; align-items: center; border-bottom: 1px solid var(--border); }
.search-item:last-child { border-bottom: 0; }
.search-item:hover, .search-item.sel { background: var(--bg3); }
.search-item small { color: var(--muted); display: block; font-size: .76rem; }
.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 10px; border: 1px solid var(--border);
  background: rgba(30,41,59,.96); color: var(--text); font-size: 1.15rem; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); }

#status-bar { position: absolute; left: 56px; top: 62px; z-index: 999; display: flex; gap: .4rem; flex-wrap: wrap; }
.badge { border-radius: 999px; padding: .25rem .7rem; font-size: .78rem; border: 1px solid; background: var(--bg2); cursor: default; }
button.badge { cursor: pointer; }
.badge-warn { color: var(--warn); border-color: rgba(251,191,36,.5); }
.badge-info { color: var(--accent); border-color: rgba(56,189,248,.5); }
.badge-trace { color: #fde047; border-color: rgba(253,224,71,.6); }

/* ---------- Panel lateral / bottom sheet ---------- */
.panel {
  position: absolute; top: 12px; right: 12px; width: 350px; max-height: calc(100% - 24px);
  overflow-y: auto; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.5); z-index: 1001;
}
.panel-head, .modal-head {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg2); z-index: 2;
}
.panel-head h3, .modal-head h3 { margin: 0; font-size: 1rem; flex: 1; }
.grip { display: none; }
#panel-close, #modal-close { background: none; border: 0; color: var(--muted); font-size: 1.5rem; cursor: pointer; line-height: 1; }
#panel-body, #modal-body { padding: .9rem 1rem 1.1rem; }
label.f { display: block; font-size: .75rem; color: var(--muted); margin: .7rem 0 .2rem; }
.fin, #panel-body select, #panel-body textarea, #modal-body select, #modal-body input[type=text],
#modal-body input[type=number], #modal-body input[type=file] {
  width: 100%; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: .92rem;
}
#panel-body input { width: 100%; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
#panel-body input[type=color] { height: 38px; padding: 2px; }
#panel-body textarea { resize: vertical; min-height: 60px; }
.btn-row { display: flex; gap: .5rem; margin-top: 1.1rem; flex-wrap: wrap; }
.btn {
  flex: 1; padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); cursor: pointer; font-size: .88rem; white-space: nowrap;
  text-decoration: none; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: linear-gradient(90deg, var(--accent2), var(--accent)); border: 0; font-weight: 600; color: #fff; }
.btn-danger { color: var(--danger); border-color: rgba(248,113,113,.5); }
.btn-sm { flex: none; padding: .3rem .55rem; font-size: .78rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; font-size: .88rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.meter { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: .3rem; }
.meter > i { display: block; height: 100%; background: var(--ok); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(2,6,23,.65); z-index: 3000; display: grid; place-items: center; padding: 16px; }
.modal-card {
  width: min(980px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal-card.narrow { width: min(460px, 100%); }

/* ---------- Gestor de empalmes ---------- */
.sp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.sp-card { background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: .75rem .8rem; margin-bottom: .8rem; }
.sp-card h4 { margin: 0 0 .5rem; font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.sp-card h4 small { color: var(--muted); font-weight: 400; }
.tube { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 6px; }
.tube-tag { font-size: .7rem; color: var(--muted); width: 32px; display: flex; align-items: center; gap: 3px; }
.tube-tag i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.chip {
  min-width: 30px; height: 28px; padding: 0 5px; border-radius: 7px; border: 2px solid transparent;
  display: inline-grid; place-items: center; font-size: .72rem; font-weight: 700; cursor: pointer;
  color: #0f172a; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.chip.dark { color: #fff; }
.chip.used { opacity: .35; }
.chip.used::after { content: ""; }
.chip.sel { border-color: #fde047; box-shadow: 0 0 0 3px rgba(253,224,71,.35); opacity: 1; }
.chip.port { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.chip.port.used { background: #14532d; color: #bbf7d0; opacity: 1; }
.chip.port.sel { border: 2px solid #fde047; }
.conn-list { width: 100%; border-collapse: collapse; font-size: .84rem; }
.conn-list td { padding: .4rem .3rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.conn-list td:last-child { text-align: right; white-space: nowrap; }
.dotc { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 4px; vertical-align: middle; box-shadow: 0 0 0 1px rgba(255,255,255,.3); }
.sel-bar { background: rgba(253,224,71,.1); border: 1px solid rgba(253,224,71,.4); color: #fde047; border-radius: 8px; padding: .45rem .7rem; font-size: .84rem; margin-bottom: .8rem; }
.inline-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: flex-end; }
.inline-form > div { flex: 1; min-width: 90px; }
.muted { color: var(--muted); font-size: .84rem; }

/* ---------- Validación ---------- */
.v-sum { display: flex; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.v-sum span { padding: .25rem .6rem; border-radius: 6px; font-size: .82rem; font-weight: 600; }
.sev-error { background: rgba(248,113,113,.15); color: var(--danger); }
.sev-warning { background: rgba(251,191,36,.15); color: var(--warn); }
.sev-info { background: rgba(56,189,248,.15); color: var(--accent); }
.v-item { padding: .55rem .6rem; border-radius: 8px; cursor: pointer; border: 1px solid var(--border); margin-bottom: .4rem; font-size: .85rem; }
.v-item:hover { border-color: var(--accent); }
.v-item b { display: block; }
.v-item small { color: var(--muted); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: calc(16px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 4000; display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; }
.toast { background: var(--bg2); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: .6rem 1rem; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: .88rem; max-width: 90vw; animation: tin .2s ease-out; }
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Leaflet overrides (tema oscuro) ---------- */
.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.55); }
.leaflet-container { font: inherit; }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--bg2); color: var(--text); border-bottom-color: var(--border); }
.leaflet-control-attribution { background: rgba(15,23,42,.75) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-tooltip { background: var(--bg2); color: var(--text); border: 1px solid var(--border); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.leaflet-tooltip-top:before { border-top-color: var(--border); }
.leaflet-top.leaflet-left { top: 0; }
.marker-label { background: transparent; border: 0; }
.mk { display: grid; place-items: center; color: #fff; font-size: 10px; font-weight: 800; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.mk-site { background: #f59e0b; width: 24px; height: 24px; border-radius: 6px; }
.mk-cto { background: #38bdf8; width: 20px; height: 20px; border-radius: 5px; }
.mk-ceo { background: #0284c7; width: 20px; height: 20px; border-radius: 50%; }
.mk-cabinet { background: #14b8a6; width: 22px; height: 22px; border-radius: 4px; }
.mk-odf { background: #a855f7; width: 22px; height: 22px; border-radius: 4px; }
.mk-infra { background: #64748b; width: 13px; height: 13px; border-radius: 50%; }
.mk-slack { background: #eab308; width: 16px; height: 16px; border-radius: 50%; border-style: dashed; }
.mk-client { background: #f472b6; width: 15px; height: 15px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.mk-client.off { background: #9ca3af; }
.mk-me { background: #3b82f6; width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 6px rgba(59,130,246,.3); }
.mk.full { box-shadow: 0 0 0 3px rgba(248,113,113,.8); }

/* ---------- Móvil ---------- */
@media (max-width: 800px) {
  .only-mobile { display: grid !important; }
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 86vw; max-width: 330px; min-width: 0;
    transform: translateX(-105%); transition: transform .22s ease; box-shadow: 20px 0 50px rgba(0,0,0,.5);
    padding-bottom: calc(1rem + var(--safe-b));
  }
  #sidebar.open { transform: none; }
  #scrim { position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 1100; }
  #topbar { left: 12px; top: calc(10px + env(safe-area-inset-top, 0px)); }
  #status-bar { left: 12px; top: calc(60px + env(safe-area-inset-top, 0px)); }
  .leaflet-top.leaflet-left { top: 96px; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh;
    border-radius: 18px 18px 0 0; padding-bottom: var(--safe-b);
  }
  .grip { display: block; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 2px; background: var(--border); }
  .modal { padding: 0; place-items: end stretch; }
  .modal-card, .modal-card.narrow { width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0; padding-bottom: var(--safe-b); }
  .sp-grid { grid-template-columns: 1fr; }
  .chip { min-width: 34px; height: 32px; }
  .leaflet-draw-tooltip { display: none; }
}
