/* ============================================================
   FiberMap Pro v10 — Layout GIS moderno
   Barra superior + paneles laterales + barra de estado
   ============================================================ */

:root {
  /* Paleta neutra: una sola capa de fondo, un solo acento, cero ruido */
  --bg-base: #0b0d10;
  --bg-base-2: #0f1115;
  --bg-surface: #111318;
  --bg-card: #15181e;
  --bg-card-solid: #15181e;
  --bg-input: #0d0f13;
  --border-color: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text-main: #eceef2;
  --text-muted: #8b909a;
  --brand-primary: #4ea8ff;
  --brand-primary-2: #4ea8ff;
  --brand-success: #3fbf8f;
  --brand-warning: #d9a441;
  --brand-danger: #e26d6d;
  --brand-purple: #9a8cf5;
  --grad-brand: #4ea8ff;
  --grad-active: #4ea8ff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.36);
  --shadow-glow: none;
  --radius: 9px;
  --radius-sm: 6px;
  --topbar-h: 56px;
  --statusbar-h: 34px;
  --panel-l-w: 268px;
  --panel-r-w: 336px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(148,163,184,.28) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(78, 168, 255, 0.45); background-clip: padding-box; }

/* Animaciones */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes pulseSoft {
  0%, 100% { box-shadow: 0 0 0 0 rgba(78, 168, 255, 0.35); }
  50%      { box-shadow: 0 0 0 7px rgba(78, 168, 255, 0); }
}
@keyframes floatIn {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

kbd {
  font-family: inherit;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom-width: 2px;
  color: #cbd5e1;
  white-space: nowrap;
}

/* Iconos SVG (set propio) */
:where([data-icon]) { display: inline-flex; align-items: center; gap: 6px; }
.ic { flex-shrink: 0; display: block; }

/* ══════════════════════ BARRA SUPERIOR ══════════════════════ */
#topbar {
  min-height: var(--topbar-h);
  height: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  /* Por encima de los paneles (z 20 / 60 en móvil) para que el menú
     "Exportar" no quede tapado al desplegarse sobre el panel derecho. */
  z-index: 70;
  position: relative;
}

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  font-size: 18px;
  color: var(--brand-primary);
  background: rgba(78, 168, 255, 0.1);
  border: 1px solid rgba(78, 168, 255, 0.24);
  border-radius: var(--radius-sm);
}
.brand-text h1 {
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: -0.025em;
  color: var(--text-main);
  line-height: 1.1;
  white-space: nowrap;
}
.brand-grad { color: var(--brand-primary); }
.brand-text p { font-size: 0.62rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.brand-badge {
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  margin-top: 2px;
}

/* Toolbar de herramientas */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  /* Si no cabe en una fila, pasa a la siguiente: el encabezado crece y NADA se
     corta (antes se envolvía dentro de una franja fija de 62 px y se recortaba).
     En pantalla pequeña sí se usa una sola fila deslizable (bloque @media). */
  justify-content: center;
  flex-wrap: wrap;
  row-gap: 6px;
  column-gap: 10px;
}
.toolbar > .toolbar-group, .toolbar > .toolbar-sep { flex-shrink: 0; }
.toolbar-group { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.toolbar-label {
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--text-muted);
}
.toolbar-sep {
  width: 1px;
  height: 28px;
  background: var(--border-color);
  flex-shrink: 0;
}
.tool-grid { display: flex; gap: 6px; }
/* Panel lateral: los botones fluyen a la siguiente fila y nunca se cortan */
.panel-section .tool-grid { flex-wrap: wrap; }
.panel-section .tool-grid .btn { flex: 1 1 auto; min-width: min-content; }

/* Acciones derechas */
.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-top {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 550;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.btn-top:hover { background: #1b1f26; border-color: var(--border-strong); }
.btn-top:active { background: #0d0f13; }
.btn-top.primary {
  background: var(--grad-active);
  border-color: transparent;
  color: #06121e;
  font-weight: 650;
  box-shadow: none;
}
.btn-top.primary:hover { background: #6bb7ff; }

/* Botón partido: Guardar (local + nube) | ▾ (exportaciones) */
.export-wrap { display: flex; }
.export-wrap .btn-guardar { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.export-wrap .btn-export-caret {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-left: -1px;
  padding: 8px 9px;
  font-size: 0.7rem;
}
.btn-top:disabled {
  opacity: 0.38;
  cursor: default;
  pointer-events: none;
  transform: none;
  box-shadow: none;
}
.btn-top kbd { opacity: 0.6; }

/* ══════════════════════ ÁREA DE TRABAJO ══════════════════════ */
#workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* Paneles laterales */
#sidebar, #right-panel {
  width: var(--panel-l-w);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
}
#sidebar { border-right: 1px solid var(--border-color); }
#right-panel {
  width: var(--panel-r-w);
  border-left: 1px solid var(--border-color);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  font-size: 0.7rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-main);
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.panel-head-icon { font-size: 0.95rem; }
.panel-close {
  display: none;
  margin-left: auto;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 24px; height: 24px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
}
.panel-close:hover { background: rgba(248, 113, 113, 0.2); color: #fff; }

.content {
  padding: 12px;
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: none;
}

.section-title {
  font-size: 0.64rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 650;
  letter-spacing: 0.09em;
  display: flex;
  align-items: center;
  flex-wrap: wrap;          /* si no caben los botones, pasan a la línea siguiente */
  row-gap: 6px;
  column-gap: 7px;
  margin-bottom: 10px;
}
.section-title::before {
  content: '';
  width: 3px; height: 12px;
  border-radius: 2px;
  background: var(--brand-primary);
  flex-shrink: 0;
}
.section-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}
.section-actions .btn-mini { flex-shrink: 0; }

/* ══════════════════════ BOTONES ══════════════════════ */
.btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 550;
  font-size: 0.73rem;
  font-family: inherit;
  text-align: center;
  transition: background 0.14s ease, border-color 0.14s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}
.btn:hover { background: #1b1f26; border-color: var(--border-strong); }
.btn:active { background: #0d0f13; }
.btn.active {
  background: var(--grad-active);
  border-color: transparent;
  color: #06121e;
  font-weight: 650;
  box-shadow: none;
}
.btn.danger {
  background: rgba(226, 109, 109, 0.12);
  border-color: rgba(226, 109, 109, 0.3);
  color: #f0a0a0;
}

/* Variantes de acento */
.btn-warn { border-color: rgba(217, 164, 65, 0.32); }
.btn-warn:hover { border-color: rgba(217, 164, 65, 0.6); }
.btn-warn.active { background: var(--brand-warning); color: #1c1404; border-color: transparent; }
.btn-danger { border-color: rgba(226, 109, 109, 0.32); }
.btn-danger:hover { border-color: rgba(226, 109, 109, 0.6); }
.btn-danger.active { background: var(--brand-danger); color: #1c0505; border-color: transparent; }
.btn-purple { background: rgba(154, 140, 245, 0.14); border-color: rgba(154, 140, 245, 0.3); color: #c4baf9; }
.btn-purple:hover { border-color: rgba(154, 140, 245, 0.55); }
.btn-success { background: rgba(63, 191, 143, 0.14); border-color: rgba(63, 191, 143, 0.3); color: #8fdcc0; font-weight: 650; }
.btn-success:hover { border-color: rgba(63, 191, 143, 0.55); }

.btn-mini {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  white-space: nowrap;
}
.btn-mini:hover { background: #1b1f26; border-color: var(--border-strong); color: var(--text-main); }
.btn-mini.active, .btn-mini.view-mode-btn.active {
  background: var(--grad-active); color: #06121e; border-color: transparent; font-weight: 650;
}
.btn-mini.danger { background: rgba(226, 109, 109, 0.12); border-color: rgba(226, 109, 109, 0.3); color: #f0a0a0; }

/* ══════════════════════ FORMULARIOS ══════════════════════ */
.form-group { margin-bottom: 10px; }
.form-group input[type="file"] { width: 100%; font-size: 0.66rem; }
label {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
select, input, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  box-sizing: border-box;
  font-size: 0.78rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: rgba(78, 168, 255, 0.65);
  box-shadow: 0 0 0 2px rgba(78, 168, 255, 0.12);
  background: var(--bg-input);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234ea8ff' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 26px;
  cursor: pointer;
}
input[type="color"] { padding: 3px; cursor: pointer; border-radius: 8px; height: 36px; }
textarea { resize: vertical; min-height: 54px; }
input::placeholder, textarea::placeholder { color: rgba(139, 154, 192, 0.55); }

/* Inspector */
.inspector-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
}
#inspect-empty {
  font-size: 0.73rem;
  color: var(--text-muted);
  text-align: center;
  padding: 18px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  line-height: 1.55;
}
#inspect-empty strong { color: var(--brand-primary); }

.hidden { display: none !important; }

/* Presupuesto óptico */
.budget-card {
  background: rgba(63, 191, 143, 0.07);
  border: 1px solid rgba(63, 191, 143, 0.22);
  border-radius: var(--radius-sm);
  padding: 11px;
  margin-top: 11px;
}

/* Capas */
.layers-list { display: flex; flex-direction: column; gap: 5px; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  color: #c3cfee;
}
.layer-row:hover { background: rgba(78, 168, 255, 0.07); border-color: rgba(78, 168, 255, 0.22); }
.layer-row input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--brand-primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* ══════════════════════ MAPA ══════════════════════ */
#map-container {
  flex: 1;
  position: relative;
  z-index: 0;          /* los botones/avisos del mapa nunca tapan los paneles */
  min-width: 0;
  height: 100%;
  background: var(--bg-base-2);
  box-shadow: none;
}
#map { width: 100%; height: 100%; }

/* Aviso de modo actual: dentro de la barra de estado */
#status-overlay {
  display: inline-block;
  vertical-align: middle;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 8px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  pointer-events: none;
}

/* Botón para plegar el panel: visible en todas las pantallas (en escritorio
   oculta el panel del todo y le deja el ancho al mapa; en táctil lo desliza) */
.sidebar-toggle {
  display: grid;
  place-items: center;
  position: absolute;
  top: auto;
  bottom: 58px;
  left: 12px;
  z-index: 40;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(7, 11, 22, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(78, 168, 255, 0.35);
  color: #9fc9e8;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 0.18s ease;
}
.sidebar-toggle:hover { background: #10203a; color: #fff; }
/* Botón de Propiedades (panel derecho) */
.panel-toggle-der {
  display: grid; place-items: center; position: absolute; top: 14px; right: 14px; z-index: 40;
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer;
  background: rgba(7, 11, 22, 0.9); border: 1px solid rgba(78, 168, 255, 0.35); color: #9fc9e8;
  box-shadow: var(--shadow-md); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: all 0.18s ease;
}
.panel-toggle-der:hover { background: #10203a; color: #fff; }
#workspace:has(#right-panel.open) .panel-toggle-der { color: #fff; border-color: rgba(78, 168, 255, 0.75); }

/* ══════════════════════ BARRA DE ESTADO ══════════════════════ */
#statusbar {
  height: var(--statusbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 14px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  font-size: 0.68rem;
  color: var(--text-muted);
  z-index: 50;
}
.statusbar-group { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.chip {
  background: rgba(78, 168, 255, 0.08);
  border: 1px solid rgba(78, 168, 255, 0.18);
  color: #9fc9e8;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.66rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip .ic { vertical-align: -2px; }

/* Chip de "Materiales en uso" (clic → detalle) */
.chip-mat {
  background: rgba(52, 211, 153, 0.10);
  border-color: rgba(52, 211, 153, 0.30);
  color: #8ff0cd;
  font-family: inherit;
  cursor: pointer;
  max-width: 46vw;
}
.chip-mat:hover {
  background: rgba(52, 211, 153, 0.20);
  border-color: rgba(52, 211, 153, 0.55);
  color: #c8fcec;
}
.chip-mat .mat-text {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tabla de materiales (modal de detalle) */
#materials-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
#materials-table thead th {
  text-align: left;
  color: var(--brand-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 8px;
  font-weight: 700;
  white-space: nowrap;
}
#materials-table thead th.num, #materials-table td.num { text-align: right; }
#materials-table tbody td {
  padding: 5px 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}
#materials-table td.mat-grupo { color: var(--brand-primary); font-weight: 700; white-space: nowrap; }
#materials-table td.mat-item { color: #dbe4ff; font-weight: 600; white-space: nowrap; }
#materials-table tr.mat-groupstart td { border-top: 1px solid rgba(78, 168, 255, 0.16); }

/* Fila individual: una caja o un splitter listado bajo su subtotal */
#materials-table tr.mat-individual td.mat-item {
  position: relative;
  padding-left: 22px;
  white-space: normal;
  color: var(--text-muted);
  font-weight: 500;
}
#materials-table tr.mat-individual td.mat-item::before {
  content: '└';
  position: absolute;
  left: 8px;
  color: #475569;
}
#materials-table tr.mat-individual td:last-child { color: #94a3b8; }

/* Modal "¿Usar este cable y sangrarlo?" */
.tap-list { display: flex; flex-direction: column; gap: 6px; }
.tap-cand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.74rem;
  background: rgba(255, 255, 255, 0.02);
}
.tap-cand:hover { border-color: rgba(78, 168, 255, 0.45); background: rgba(78, 168, 255, 0.07); }
.tap-cand.is-sel { border-color: rgba(52, 211, 153, 0.55); background: rgba(52, 211, 153, 0.10); }
/* El input del radio NO hereda el width:100% global de los inputs */
.tap-cand input[type="radio"] { width: auto; flex: 0 0 auto; accent-color: #22c55e; cursor: pointer; }
.tap-cand-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.tap-cand-main .muted { font-size: 0.68rem; }
.tap-cand-libres {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-size: 0.66rem;
  color: #8ff0cd;
  white-space: nowrap;
  font-weight: 700;
}
.tap-cand-libres span { font-size: 0.6rem; color: var(--text-muted); font-weight: 600; }
.tap-resumen {
  font-size: 0.72rem;
  line-height: 1.5;
  background: rgba(78, 168, 255, 0.08);
  border: 1px dashed rgba(78, 168, 255, 0.35);
  border-radius: 6px;
  padding: 7px 9px;
  margin-top: 10px;
}
/* Detalle auditable: por qué cada hilo NO está libre */
.tap-ocupados {
  font-size: 0.68rem;
  line-height: 1.55;
  color: var(--text-muted);
  border-top: 1px dashed var(--border-color);
  margin-top: 7px;
  padding-top: 7px;
}
.tap-ocupados b { color: #cbd5e1; }
.tap-ocup-code {
  display: inline-block;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 4px;
  padding: 0 4px;
  margin-right: 2px;
  font-weight: 700;
  color: #e2e8f0;
}
/* Selector de hilo dentro de la ventana de sangrado */
.tap-hilo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}
.tap-hilo-lbl {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}
.tap-hilo select { flex: 1 1 auto; min-width: 0; }
/* El hilo elegido ya está usado en otra parte → se avisa, pero se permite */
.tap-aviso {
  font-size: 0.68rem;
  line-height: 1.5;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.08);
  border: 1px dashed rgba(251, 191, 36, 0.4);
  border-radius: 6px;
  padding: 6px 8px;
  margin-top: 7px;
}
/* Dato informativo: hilos empalmados en paso (NO ocupan el tramo) */
.tap-nota {
  font-size: 0.68rem;
  line-height: 1.55;
  color: var(--text-muted);
  border-top: 1px dashed var(--border-color);
  margin-top: 7px;
  padding-top: 7px;
}
.tap-nota b { color: #a5f3d0; }

.statusbar-hints {
  display: flex;
  gap: 16px;
  align-items: center;
  font-weight: 600;
  overflow: hidden;
}
.statusbar-hints span { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.statusbar-brand {
  font-weight: 700;
  color: rgba(139, 154, 192, 0.55);
  letter-spacing: 0.04em;
  flex-shrink: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}
.statusbar-brand b {
  color: rgba(78, 168, 255, 0.85);
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ══════════════════════ MODALES ══════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
  max-height: calc(100vh - 36px);
  /* Ningún modal puede salirse de la pantalla: los que llevan ancho fijo
     (tap, cable, cloud…) se adaptan en móviles estrechos. */
  max-width: 96vw;
}
#box-editor-modal .modal-content { width: 90vw; height: 85vh; max-width: 1200px; }
.modal-header {
  padding: 14px 20px;
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 1rem; font-weight: 800; letter-spacing: -0.01em; }
.modal-body {
  flex-grow: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.modal-footer {
  padding: 11px 20px;
  background: rgba(7, 11, 22, 0.7);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ══════════════════════ BOX EDITOR ══════════════════════ */
.box-mode-bar {
  background: rgba(7, 11, 22, 0.7);
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}
/* Leyenda del editor: los mismos colores que el diagrama lógico */
.be-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 6px 20px;
  background: rgba(10, 16, 32, 0.55);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.be-legend > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; border: 1px solid rgba(255,255,255,0.45); }
.lg-dot.libre { background: #24314f; }
.lg-dot.fusion { background: #a855f7; }
.lg-dot.splitter { background: #eab308; }
.lg-dot.pon { background: #10b981; }
.lg-line { width: 18px; height: 0; border-top: 2px solid; display: inline-block; }
.lg-line.fusion { border-color: #a855f7; }
.lg-line.splitter { border-color: #eab308; }
.lg-line.pon { border-color: #10b981; }

/* Estado de cada hilo junto a su número (chip tipo diagrama) */
.be-fiber-state {
  margin-left: auto;
  font-size: 0.58rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: var(--text-muted);
  white-space: nowrap;
}
.be-fiber-state.fu { color: #d8b4fe; border-color: rgba(168, 85, 247, 0.45); background: rgba(168, 85, 247, 0.1); }
.be-fiber-state.sp { color: #fde68a; border-color: rgba(234, 179, 8, 0.45); background: rgba(234, 179, 8, 0.1); }
.be-fiber-state.pon { color: #6ee7b7; border-color: rgba(16, 185, 129, 0.45); background: rgba(16, 185, 129, 0.1); }
.be-fiber-state.odf { color: #9fc9e8; border-color: rgba(78, 168, 255, 0.45); background: rgba(78, 168, 255, 0.1); }
.be-fiber-state.cn { color: #67e8f9; border-color: rgba(6, 182, 212, 0.45); background: rgba(6, 182, 212, 0.1); }

.be-trace-btn {
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid rgba(78, 168, 255, 0.4);
  background: rgba(78, 168, 255, 0.12);
  color: #7dd3fc;
  font-size: 0.7rem;
  line-height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.be-trace-btn:hover { background: rgba(78, 168, 255, 0.25); color: #fff; }

.be-note-btn {
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  font-size: 0.7rem;
  line-height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.be-note-btn.con-nota { background: rgba(245, 158, 11, 0.35); color: #fff; }
.be-note-btn:hover { background: rgba(245, 158, 11, 0.3); color: #fff; }

.box-editor-workspace {
  flex-grow: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.editor-side {
  width: 280px;
  border-right: 1px solid var(--border-color);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow-y: auto;
  background: rgba(7, 11, 22, 0.65);
  flex-shrink: 0;
}
.editor-side.right { border-right: none; border-left: 1px solid var(--border-color); }
.editor-canvas {
  flex-grow: 1;
  background: var(--bg-base-2);
  overflow: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-content: start;
  min-width: 0;
}
.canvas-toolbar {
  grid-column: 1 / span 3;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  background: rgba(20, 29, 51, 0.9);
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 10px;
}
.splitter-center {
  grid-column: 2;
  width: 300px;
  padding: 10px;
  border: 1px dashed rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
}
.connections-strip {
  grid-column: 1 / span 3;
  padding: 10px;
  border-top: 1px solid var(--border-color);
  margin-top: 10px;
}

/* Cables y fibras */
.cable-col {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 11px;
  margin-bottom: 15px;
  box-shadow: var(--shadow-sm);
}
.cable-col-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 8px;
  font-size: 0.7rem;
  font-weight: 800;
  color: #9cdcff;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
  margin-bottom: 9px;
}
/* Por qué está el cable en la caja (aunque sus extremos no estén anclados) */
.be-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
.be-tag.be-tap {
  color: #9fc9e8;
  background: rgba(125, 211, 252, 0.12);
  border: 1px solid rgba(125, 211, 252, 0.35);
}
.be-tag.be-pasa {
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.3);
}
/* ── Verificación del hilo alimentador (misma regla que potencia/diagrama) ── */
.be-audit {
  border-radius: 6px;
  padding: 5px 8px;
  font-weight: 600;
  line-height: 1.35;
}
.be-audit.ok {
  color: #86efac;
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.be-audit.fail {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.38);
}
/* Presupuesto óptico no calculable: se explica el MOTIVO, no un "Sin ruta" */
.budget-alert {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.38);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
}
.budget-ok {
  color: #86efac;
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.32);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.73rem;
  font-weight: 600;
  margin-bottom: 5px;
}
.loose-tube {
  border: 1px dashed rgba(148, 163, 184, 0.3);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 9px;
  padding: 8px;
  margin-bottom: 8px;
}
.loose-label { font-size: 0.63rem; color: var(--text-muted); margin-bottom: 5px; font-weight: 700; }
.fiber-row { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.fiber-row-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.7rem;
  transition: background 0.12s ease;
}
.fiber-row-item:hover { background: rgba(78, 168, 255, 0.07); }
.fiber-dot {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: linear-gradient(180deg, #24314f, #1b1f26);
  border: 1px solid rgba(148, 163, 184, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  font-size: 0.58rem;
  font-weight: 800;
  flex-shrink: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.fiber-dot:hover { transform: scale(1.15); box-shadow: 0 0 10px rgba(78, 168, 255, 0.5); }
.fiber-dot.selected { border: 2px solid #fff; box-shadow: 0 0 10px #fff; transform: scale(1.15); }
.fiber-dot.fiber-used { background: linear-gradient(180deg, #3b82f6, #2563eb); }
.fiber-dot.fiber-fusion { background: linear-gradient(180deg, #a855f7, #7c3aed); }
.fiber-dot.fiber-connector { background: linear-gradient(180deg, #06b6d4, #0891b2); }
.fiber-dot.fiber-splitter { background: linear-gradient(180deg, #eab308, #ca8a04); }
.fiber-dot.fiber-to-port { background: linear-gradient(180deg, #10b981, #059669); }
.fiber-dot.fiber-illuminated { box-shadow: 0 0 14px #facc15; border: 2px solid #facc15; }
.fiber-label { pointer-events: none; }
.fiber-label.off { opacity: 0.3; }

/* Splitters */
.splitter-card {
  background: var(--bg-card);
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 11px;
  padding: 11px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.splitter-title {
  font-size: 0.76rem;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  color: #fde68a;
}
.cnx-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.7rem;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.cnx-head {
  width: 100%;
  font-size: 0.68rem;
  color: var(--text-muted);
  padding-bottom: 4px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.25);
  margin-bottom: 2px;
}
.cnx-pair { flex: 1 1 100%; word-break: break-word; line-height: 1.35; }
.cnx-meta { color: var(--text-muted); font-size: 0.64rem; white-space: nowrap; margin-left: auto; }
/* Los enganches del splitter (🟡 entrada / 🟢 salida) se diferencian de las
   fusiones (🔁) con un filito verde, pero forman parte del mismo registro */
.cnx-row.cnx-sp {
  border-left: 2px solid rgba(52, 211, 153, 0.4);
  padding-left: 6px;
  border-radius: 3px;
  background: rgba(52, 211, 153, 0.045);
}
.cnx-row.cnx-sp .cnx-pair { color: #d1fae5; }

/* ── ODF interno de la central: rejilla de posiciones ── */
/* Pestañas de bastidor ODF en el editor de la central (nodo multi-ODF) */
.odf-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.odf-tab {
  padding: 3px 10px; border-radius: 8px 8px 0 0; font: inherit; font-size: 0.72rem; font-weight: 700;
  cursor: pointer; color: var(--text-muted); background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-color); border-bottom: none;
}
.odf-tab:hover { color: var(--text-main); }
.odf-tab.active { color: #e8eefc; background: rgba(78, 168, 255, 0.18); border-color: rgba(78, 168, 255, 0.5); }

/* Vista del Nodo (rack y cascada de fibras) */
.nv-tab {
  padding: 4px 12px; border-radius: 8px; border: 1px solid var(--border-color);
  background: transparent; color: var(--text-muted); font: inherit; font-size: 0.75rem;
  font-weight: 700; cursor: pointer;
}
.nv-tab.active { color: #e8eefc; background: rgba(78, 168, 255, 0.18); border-color: rgba(78, 168, 255, 0.5); }
.nv-scroll { overflow: auto; max-height: 74vh; background: #0a1020; border-radius: 8px; cursor: grab; }
.nv-scroll:active { cursor: grabbing; }
#node-view-svg .nv-sched-t { fill: #9fc9e8; font-weight: 700; font-size: 10px; }
#node-view-svg .nv-sched { fill: #cbd5e1; font-size: 9px; }

.odf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 2px;
}
.odf-pos {
  position: relative;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.6);
  padding: 3px 3px 4px;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  min-height: 34px;
}
.odf-pos:hover { border-color: #4ea8ff; }
.odf-pos.libre .odf-num { color: var(--text-muted); }
.odf-pos.ocupada {
  border-color: rgba(52, 211, 153, 0.65);
  background: rgba(52, 211, 153, 0.1);
}
.odf-num { display: block; font-size: 0.62rem; font-weight: 700; color: #9fc9e8; }
.odf-que {
  display: block;
  font-size: 0.56rem;
  line-height: 1.15;
  color: #d1fae5;
  word-break: break-word;
}
.odf-x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  opacity: 0;
  transition: opacity .12s;
}
.odf-pos:hover .odf-x { opacity: 1; }

/* ── Presupuesto: estado de cada potencia (datos / TV) ── */
.budget-range {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 8px;
  font-size: 0.66rem;
  font-weight: 600;
}
.budget-range.ok   { background: rgba(16, 185, 129, 0.16); color: #34d399; }
.budget-range.warn { background: rgba(234, 179, 8, 0.16);  color: #fcd34d; }
.budget-range.fail { background: rgba(239, 68, 68, 0.16);  color: #fca5a5; }
.budget-range.na   { background: rgba(148, 163, 184, 0.14); color: var(--text-muted); }

/* ── OTDR: controles, indicadores y tabla de eventos ── */
.otdr-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 8px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  margin-bottom: 8px;
}
.otdr-controls label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.otdr-controls select { min-width: 130px; }
.otdr-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
}
.otdr-kpis .kpi {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 0.7rem;
}
.otdr-kpis .kpi span { display: block; color: var(--text-muted); font-size: 0.64rem; }
.otdr-kpis .kpi strong { display: block; margin-top: 2px; font-size: 0.82rem; color: #e2e8f0; }
.otdr-break {
  margin-top: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  font-size: 0.72rem;
  font-weight: 600;
}
.otdr-table { width: 100%; border-collapse: collapse; font-size: 0.7rem; }
.otdr-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  position: sticky;
  top: 0;
  background: #0b1220;
}
.otdr-table td { padding: 4px 6px; border-bottom: 1px solid rgba(148, 163, 184, 0.09); }
.otdr-table tr.rotura td { background: rgba(239, 68, 68, 0.12); color: #fecaca; }
.otdr-table tr.zona td { opacity: 0.72; }

/* ── Box Editor: modo asignación de hilos a splitters ── */.box-assign-hint {
  font-size: 0.66rem;
  text-align: center;
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.08);
  border: 1px dashed rgba(148, 163, 184, 0.3);
  border-radius: 7px;
  padding: 5px 8px;
  margin-bottom: 8px;
  transition: all 0.15s ease;
}
.box-assign-hint.active {
  color: #fde047;
  border-color: #eab308;
  background: rgba(234, 179, 8, 0.12);
  animation: pulseHint 1.2s ease-in-out infinite;
}
@keyframes pulseHint { 50% { opacity: 0.6; } }

.fiber-dot.assignable { outline: 1px dashed #fbbf24; outline-offset: 2px; }
.fiber-dot.mode-on { color: #4ade80; }
.fiber-dot.mode-off { color: #94a3b8; opacity: 0.7; }
.fiber-dot.mode-sp { color: #fde047; }
.fiber-dot.mode-fu { color: #e9d5ff; }

/* ── Salidas PON de los splitters ── */
.sp-outs { display: flex; flex-direction: column; gap: 3px; }
.sp-out {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  padding: 3px 5px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 6px;
}
.sp-out.assigning { border-color: #eab308; background: rgba(234, 179, 8, 0.12); }
.sp-port { font-weight: 800; color: #fde047; min-width: 54px; font-size: 0.64rem; flex-shrink: 0; }
.sp-dest { flex: 1; word-break: break-word; line-height: 1.3; }

/* ── Registro global de fusiones ── */
.log-row { transition: background 0.12s ease; }
.log-row:hover { background: rgba(78, 168, 255, 0.06); }

/* ══════════════════════ BÚSQUEDA ══════════════════════ */
#search-modal .modal-content { width: 520px; height: 420px; }
.search-row {
  padding: 9px 13px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.09);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.12s ease;
}
.search-row:hover {
  background: linear-gradient(90deg, rgba(78, 168, 255, 0.14), transparent);
  padding-left: 17px;
}

/* ══════════════════════ DIAGRAMA ══════════════════════ */
#diagram-modal .modal-content { width: 80vw; height: 70vh; }
/* ══════════════════════ REGISTRO DE FUSIONES ══════════════════════ */
#fusions-log-modal .modal-content { width: min(880px, 94vw); }
#diagram-svg {
  width: 100%;
  height: 100%;
  background: var(--bg-base-2);
}

.muted { color: var(--text-muted); }

/* El mapa crea su propio contexto de apilamiento: sus capas internas
   (Leaflet usa z-index 200–1000) no deben tapar la UI de la aplicación */
.leaflet-container { z-index: 0; }

/* ══════════════════════ LISTA DE PROYECTOS ══════════════════════ */
.projects-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 34vh;
  overflow-y: auto;
  padding-right: 2px;
}
.project-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 6px 8px;
  transition: background 0.15s, border-color 0.15s;
}
.project-row:hover {
  background: rgba(78, 168, 255, 0.07);
  border-color: rgba(78, 168, 255, 0.25);
}
.project-row.is-current {
  border-color: rgba(78, 168, 255, 0.5);
  background: rgba(78, 168, 255, 0.1);
  box-shadow: none;
}
.project-main {
  flex: 1 1 100%;
  min-width: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.project-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: #e8eefc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.project-tag {
  font-size: 0.52rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--brand-primary, #4ea8ff);
  color: #05121f;
  padding: 1px 5px;
  border-radius: 99px;
  font-weight: 800;
  flex-shrink: 0;
}
.project-meta {
  font-size: 0.62rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-actions {
  flex: 1 1 100%;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  opacity: 1;
  margin-top: 2px;
}
.project-actions .btn-mini { padding: 4px 6px; }

/* ══════════════════════ ÁRBOL DE CARPETAS (estilo Google Earth) ══════════════════════ */
.folder-tree {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 36vh;
  overflow-y: auto;
  padding-right: 2px;
}
.ft-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 4px;
  border-radius: 6px;
  font-size: 0.7rem;
  color: #c3d0ea;
  min-width: 0;
}
.ft-row:hover { background: rgba(78, 168, 255, 0.08); }
.ft-row.is-hidden { opacity: 0.45; }

/* ── Arrastrar carpetas: zonas de suelta y estado ─────────────────── */
.ft-row.ft-folder { cursor: grab; }
.ft-row.ft-folder:active { cursor: grabbing; }
.ft-folder.is-dragging { opacity: 0.4; }
.ft-row.ft-drop-before { box-shadow: inset 0 2px 0 0 var(--brand-primary); background: rgba(78, 168, 255, 0.10); }
.ft-row.ft-drop-after { box-shadow: inset 0 -2px 0 0 var(--brand-primary); background: rgba(78, 168, 255, 0.10); }
.ft-row.ft-drop-inside { outline: 1px dashed #fbbf24; outline-offset: -2px; background: rgba(251, 191, 36, 0.14); }

/* Renombrar en línea (doble clic) */
.ft-rename-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  color: #dbe7ff;
  background: #0b1424;
  border: 1px solid var(--brand-primary);
  border-radius: 4px;
  padding: 1px 4px;
  outline: none;
}
.ft-toggle {
  width: 14px;
  flex-shrink: 0;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted, #7487ab);
  user-select: none;
}
.ft-check {
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  background: transparent;
  box-sizing: border-box;
  flex-shrink: 0;
  accent-color: #4ea8ff;
  cursor: pointer;
  margin: 0;
}
.ft-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ft-folder .ft-name { font-weight: 700; color: #dbe7ff; }
.ft-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ft-count {
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--text-muted, #7487ab);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 99px;
  padding: 0 5px;
  flex-shrink: 0;
}
.ft-sub {
  font-size: 0.58rem;
  color: var(--text-muted, #7487ab);
  flex-shrink: 0;
  white-space: nowrap;
}
.ft-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.ft-row:hover .ft-actions { opacity: 1; }
/* En táctiles no hay hover: los botones siempre visibles */
@media (hover: none) { .ft-actions { opacity: 1; } }

/* Dispositivos táctiles: zonas cómodas para el dedo AUNQUE la pantalla sea ancha
   (tablet en horizontal usa el diseño de escritorio, pero no hay ratón). */
@media (hover: none) {
  .btn-mini { min-height: 32px; min-width: 32px; padding: 5px 10px; }
  .panel-close { width: 32px; height: 32px; }
  .ft-btn { width: 30px; height: 30px; }
  #geo-go { min-height: 30px; padding: 5px 12px; }
  .toolbar .btn { min-height: 36px; }
  .panel-section .tool-grid .btn { min-height: 36px; }
}
.ft-btn {
  background: none;
  border: none;
  color: var(--text-muted, #7487ab);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: grid;
  place-items: center;
}
.ft-btn:hover { background: rgba(78, 168, 255, 0.15); color: #e8eefc; }

/* ══════════════════════ LEAFLET (tema oscuro + marcadores) ══════════════════════ */
.leaflet-container {
  background: #0a1020;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  outline: none;
}

/* Marcadores personalizados (divIcon) */
.fm-marker { background: none !important; border: none !important; }
.fm-dot {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.55));
  transition: transform 0.12s ease;
  position: relative;
}
.fm-issue-badge {
  position: absolute; top: 0; right: 0;
  width: 14px; height: 14px; border-radius: 50%;
  background: #ef4444; color: #fff; border: 1.5px solid #fff;
  font: bold 10px/11px sans-serif; text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.fm-dot:hover { transform: scale(1.12); }
/* Con una herramienta de dibujo/colocación activa (cursor de cruz), la
   estructura bajo el ratón crece más: se ve a cuál conectaría el clic. */
#map.leaflet-crosshair .fm-dot:hover { transform: scale(1.3); }
.fm-dot.is-selected { animation: markerBounce 0.65s ease-in-out infinite alternate; }
@keyframes markerBounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-10px); }
}

/* Marcador OTDR (cruz roja de rotura) */
.fm-otdr { background: none !important; border: none !important; }
.otdr-x {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #ef4444;
  font-size: 17px;
  font-weight: 900;
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.9);
  animation: pulseSoft 1.2s ease-in-out infinite;
}

/* Popups (InfoWindow) */
.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}
.leaflet-popup-tip { background: var(--bg-card); border: 1px solid var(--border-color); }
.leaflet-popup-content { margin: 11px 14px; font-size: 12px; line-height: 1.5; }
.leaflet-popup-content-wrapper a.leaflet-popup-close-button { color: #8b9ac0 !important; }
.leaflet-popup-content-wrapper a.leaflet-popup-close-button:hover { color: #fff !important; }

/* Control de zoom */
.leaflet-bar a,
.leaflet-bar a:hover {
  background: var(--bg-surface);
  color: var(--text-main);
  border-bottom-color: var(--border-color);
}
.leaflet-bar a:hover { background: #1b1f26; color: #9fc9e8; }
.leaflet-bar a.leaflet-disabled { background: var(--bg-surface); color: #475569; }
.leaflet-touch .leaflet-bar, .leaflet-touch .leaflet-control-layers { border-radius: var(--radius-sm); }

/* Selector de capas base */
.leaflet-control-layers {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  color: var(--text-main);
}
.leaflet-control-layers-expanded {
  background: var(--bg-surface);
  color: var(--text-main);
  padding: 8px 12px 8px;
  border-radius: var(--radius);
  font-size: 0.72rem;
}
.leaflet-control-layers-expanded label { margin-bottom: 3px; color: #c3cfee; }
.leaflet-control-layers-separator { background: rgba(148, 163, 184, 0.2); }

/* Atribución */
.leaflet-control-attribution {
  background: rgba(7, 11, 22, 0.75) !important;
  color: #8b9ac0 !important;
  font-size: 9.5px;
  padding: 2px 7px;
  border-radius: 6px 0 0 0;
}
.leaflet-control-attribution a { color: #9fc9e8 !important; }

/* ══════════════════════ RESPONSIVE ══════════════════════ */
/* Acciones del encabezado: sólo icono salvo en pantallas muy anchas. Con texto
   ocupaban 565 px y dejaban a la barra de herramientas la mitad de su sitio. */
@media (max-width: 1699px) {
  .btn-top .btn-top-label { display: none; }
  .btn-top kbd { display: none; }
}
/* Los rótulos «1 · Estructuras» sólo donde hay sitio de sobra. */
@media (max-width: 1499px) {
  .toolbar-label { display: none; }
}

@media (max-width: 1080px) {
  /* En tabletas la barra de herramientas ya no se envuelve dentro de la franja
     de 62 px (se cortaba por arriba): pasa a una sola fila desplazable. */
  #topbar { height: auto; min-height: var(--topbar-h); flex-wrap: wrap; gap: 8px 12px; padding: 6px 12px; }
  .toolbar {
    order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    gap: 8px; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar-group { flex-direction: row; align-items: center; flex-shrink: 0; gap: 6px; }
  .toolbar-group .tool-grid, .toolbar-group .btn { flex-shrink: 0; }

  /* Botón para abrir/cerrar las propiedades (el panel derecho) */
  .panel-toggle-der {
    display: grid; place-items: center; position: absolute; right: 12px; top: 14px; bottom: auto; z-index: 61;
    width: 44px; height: 44px; border-radius: 12px; cursor: pointer; color: var(--text-main);
    background: var(--bg-surface); border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-md); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  }
  .panel-toggle-der:hover { color: #fff; border-color: rgba(78, 168, 255, 0.6); }
  #workspace:has(#right-panel.open) .panel-toggle-der { color: var(--brand-primary); border-color: rgba(78, 168, 255, 0.65); }

  /* Zonas táctiles cómodas en el dedo */
  .btn-mini { min-height: 32px; min-width: 32px; padding: 5px 10px; }
  .panel-close { width: 32px; height: 32px; }
  .toolbar .btn { min-height: 36px; }
  .ft-btn { width: 30px; height: 30px; }            /* acciones sobre un elemento del mapa */
  #geo-go { min-height: 30px; padding: 5px 12px; }  /* botón Buscar del buscador */
  #stats-materials { min-height: 26px; padding: 3px 10px; }

  /* Los paneles laterales pasan a ser deslizantes DENTRO del área de trabajo:
     al recortar el contenedor, el panel fuera de pantalla ya no ensancha la
     página (antes el documento medía 419 px en un móvil de 390). */
  #workspace { overflow: hidden; }
  #sidebar, #right-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 60;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
    box-shadow: var(--shadow-md);
  }
  /* visibility: oculto => el panel fuera de pantalla no ensancha la página */
  #sidebar { left: 0; transform: translateX(-103%); visibility: hidden; }
  #sidebar.open { transform: none; visibility: visible; }
  #right-panel { right: 0; transform: translateX(103%); visibility: hidden; }
  #right-panel.open { transform: none; visibility: visible; }
  .sidebar-toggle { display: block; top: auto; bottom: 58px; left: 12px; }
  /* En pantalla pequeña el aviso de modo va en su propia fila, justo debajo
     del buscador: centrado se quedaba sin ancho y se partía en 4 líneas. */
  #status-overlay { position: static; flex: 1 1 auto; min-width: 0; margin: 0 6px; }
  .toolbar-label { display: none; }
  .toolbar-sep { display: none; }
  .statusbar-hints { display: none; }
  #box-editor-modal .modal-content { width: 96vw; height: 92vh; }
}

@media (max-width: 760px) {
  #topbar { height: auto; min-height: var(--topbar-h); padding: 8px 10px; flex-wrap: wrap; gap: 8px 10px; }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand-text p { display: none; }
  .topbar-actions { flex-shrink: 0; margin-left: auto; }
  /* Herramientas: fila desplazable bajo la marca — nada se sale de pantalla */
  .toolbar {
    order: 3;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    gap: 8px;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar-group { flex-direction: row; align-items: center; flex-shrink: 0; gap: 6px; }
  .toolbar-group .tool-grid { flex-shrink: 0; }
  .toolbar-group .btn { flex-shrink: 0; }
  .editor-side { display: none; }
  .editor-canvas { grid-template-columns: 1fr; }
  .splitter-center { grid-column: 1; width: 100%; }
  .connections-strip, .canvas-toolbar { grid-column: 1; }
  .modal-overlay { padding: 8px; }
  #search-modal .modal-content { width: 94vw; }
}

/* ══════════════════ EXPORTACIÓN DEL DIAGRAMA (PNG · PDF · SVG) ══════════════════ */
.export-wrap { position: relative; }
.export-pop {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 60;
  min-width: 178px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: modalIn 0.16s ease both;
}
.export-opt {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.export-opt:hover {
  background: rgba(78, 168, 255, 0.14);
  border-color: rgba(78, 168, 255, 0.42);
  color: #fff;
}
.export-opt svg { flex-shrink: 0; opacity: 0.9; }

/* Tiradores para editar los vértices de un cable o zona (morados, estilo Google Earth) */
.vtx-handle span {
  display: block; width: 14px; height: 14px; border-radius: 50%;
  background: #a855f7; border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,0.7); cursor: grab;
}
.vtx-handle span:active { cursor: grabbing; }
.vtx-draw span { width: 16px; height: 16px; background: #a855f7; border-color: #f5d0fe; }
.vtx-draw span:hover { background: #c084fc; }

/* Checkboxes del inventario de equipos (nodo/OLT) */
.eq-check { display: flex !important; align-items: center; gap: 7px; cursor: pointer;
  color: var(--text-main); font-weight: 600; }
.eq-check input[type="checkbox"] { width: 15px !important; height: 15px; flex: 0 0 auto; margin: 0; }

/* Campos de cada equipo del nodo: rejilla de dos columnas y, si el equipo está
   apagado, se ocultan — así el panel no se llena de recuadros vacíos. */
.eq-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 5px; }
.eq-fields[hidden] { display: none; }
.eq-fields .eq-sub { grid-column: 1 / -1; font-size: 0.66rem; color: var(--text-muted); }
.eq-fields select, .eq-fields input { min-width: 0; }


/* ══════════════════ AVISOS NO BLOQUEANTES ══════════════════
   Sustituyen a alert() y confirm(): la app (y el mapa) siguen vivos. */
#fm-avisos {
  position: fixed; right: 16px; bottom: calc(var(--statusbar-h) + 14px); z-index: 4000;
  display: flex; flex-direction: column; gap: 8px; max-width: min(430px, 92vw); pointer-events: none;
}
.fm-aviso {
  display: flex; align-items: flex-start; gap: 9px; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--bg-card-solid);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-md);
  color: var(--text-main); font-size: 0.8rem; line-height: 1.35;
  opacity: 0; transform: translateY(8px); transition: opacity 0.22s, transform 0.22s; pointer-events: auto;
}
.fm-aviso.visible { opacity: 1; transform: none; }
.fm-aviso-ico {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 0.72rem; background: rgba(78, 168, 255, 0.18); color: var(--brand-primary);
}
.fm-aviso-ok .fm-aviso-ico { background: rgba(52, 211, 153, 0.18); color: var(--brand-success); }
.fm-aviso-warn .fm-aviso-ico { background: rgba(251, 191, 36, 0.18); color: var(--brand-warning); }
.fm-aviso-error .fm-aviso-ico { background: rgba(248, 113, 113, 0.18); color: var(--brand-danger); }
.fm-aviso-txt { flex: 1 1 auto; white-space: pre-line; }
.fm-aviso-x { background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: 0.95rem; line-height: 1; padding: 0 2px; }
.fm-aviso-x:hover { color: #fff; }

.fm-confirmar {
  position: fixed; inset: 0; z-index: 4100; padding: 18px;
  background: rgba(3, 7, 18, 0.58); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; animation: fmAparecer 0.16s ease-out;
}
.fm-confirmar-caja {
  width: min(440px, 94vw); padding: 18px; background: var(--bg-card-solid);
  border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.fm-confirmar-caja h3 { font-size: 0.98rem; margin-bottom: 6px; color: var(--text-main); }
.fm-confirmar-caja p { font-size: 0.82rem; color: var(--text-muted); white-space: pre-line; }
.fm-confirmar-acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.fm-confirmar .principal { background: var(--grad-active); border-color: transparent; color: #04121f; font-weight: 700; }
.fm-confirmar .peligro { background: rgba(248, 113, 113, 0.16); border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
@keyframes fmAparecer { from { opacity: 0; } to { opacity: 1; } }

/* Barra de estado desplazable en pantallas pequeñas (los chips no caben) */
@media (max-width: 760px) {
  #statusbar { overflow-x: auto; overflow-y: hidden; justify-content: flex-start; gap: 10px; scrollbar-width: none; }
  #statusbar::-webkit-scrollbar { display: none; }
  .statusbar-group { flex-shrink: 0; }
  #status-overlay { order: -1; flex: 0 1 auto; max-width: min(50vw, 210px); text-align: left; }
}

/* ══════════════════ BUSCADOR DE DIRECCIONES Y LUGARES ══════════════════ */
.geo-search {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 500;
  width: min(360px, calc(100% - 220px)); font-size: 0.78rem;
}
.geo-fila {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border-radius: var(--radius-sm); background: var(--bg-surface);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.geo-lupa { color: var(--text-muted); display: grid; place-items: center; }
#geo-q { flex: 1 1 auto; min-width: 0; background: transparent; border: 0; outline: none; color: var(--text-main); font: inherit; }
#geo-q::placeholder { color: var(--text-muted); }
.geo-go {
  flex: 0 0 auto; padding: 3px 10px; border-radius: 999px; font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid rgba(78, 168, 255, 0.35); background: rgba(78, 168, 255, 0.14); color: #bfe6fb;
}
.geo-go:hover { background: rgba(78, 168, 255, 0.26); color: #fff; }
.geo-res {
  margin-top: 6px; max-height: 46vh; overflow-y: auto; border-radius: var(--radius-sm);
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md); backdrop-filter: blur(10px);
}
.geo-res.hidden { display: none; }
.geo-item {
  display: block; width: 100%; text-align: left; padding: 7px 10px; cursor: pointer; font: inherit;
  background: none; border: 0; border-bottom: 1px solid var(--border-color); color: var(--text-main);
}
.geo-item:last-child { border-bottom: 0; }
.geo-item:hover { background: rgba(78, 168, 255, 0.12); }
.geo-nombre { display: block; font-weight: 600; }
.geo-resto { display: block; font-size: 0.72rem; color: var(--text-muted); }
.geo-vacio { padding: 9px 10px; color: var(--text-muted); }
.geo-attrib { margin-top: 4px; font-size: 0.62rem; color: var(--text-muted); text-align: right; opacity: 0.85; }
.geo-pin-caja {
  width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); background: var(--grad-active); box-shadow: var(--shadow-md);
}
.geo-pin-caja svg { width: 15px; height: 15px; transform: rotate(45deg); color: #04121f; }

/* Escritorio: plegar paneles (el mapa ocupa todo el ancho) */
@media (min-width: 1081px) {
  #workspace.sin-izq #sidebar { display: none; }
  #workspace.sin-der #right-panel { display: none; }
  #workspace.sin-izq .sidebar-toggle, #workspace.sin-der .panel-toggle-der { color: #9fc9e8; }
}

/* Pantalla pequeña: el buscador vuelve a lo ancho bajo el control de zoom (la
   regla base está más arriba y, si no, ganaría por orden de aparición). */
@media (max-width: 1080px) {
  .geo-search {
    top: 88px; left: 10px; transform: none;
    width: min(330px, calc(100% - 20px));
  }
}
