:root {
  --bg: #0f1520;
  --bg-panel: #161e2c;
  --bg-panel-2: #1c2536;
  --bg-hover: #223049;
  --border: #2a3648;
  --text: #e7ecf5;
  --text-dim: #93a1b8;
  --text-faint: #5f6d84;
  --accent: #3b82f6;
  --accent-dim: #1e3a63;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --sel: #a855f7;        /* roxo da seleção (elemento ou cabo) */
  --sel-bright: #e9d5ff;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Login ---------- */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 800px at 20% 0%, #16233a 0%, var(--bg) 60%);
}
.login-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 340px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { color: var(--text-dim); margin: 0 0 20px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 10px 16px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn.secondary { background: var(--bg-panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 12px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { filter: none; }
.cabo-passando { margin-top: 14px; border: 1px solid var(--info); border-left-width: 3px; border-radius: 8px; padding: 10px 12px; background: rgba(56, 189, 248, .07); }
.cabo-passando strong { display: block; color: var(--info); font-size: 12.5px; margin-bottom: 4px; }
.cabo-passando .hint { margin-bottom: 8px; }
.delete-blocked {
  margin-top: 12px; border: 1px solid var(--danger); border-left-width: 3px; border-radius: 8px;
  padding: 10px 12px; font-size: 12px; color: var(--text-dim); background: rgba(239, 68, 68, .07);
}
.delete-blocked strong { display: block; color: var(--danger); margin-bottom: 6px; font-size: 12.5px; }
.delete-blocked ul { margin: 0 0 8px; padding-left: 18px; }
.delete-blocked li { margin: 2px 0; color: var(--text); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- App shell ---------- */
#app-screen { display: none; flex-direction: column; height: 100vh; }
#app-screen.visible { display: flex; }

header#topbar {
  display: flex; align-items: center; gap: 14px; padding: 6px 16px; min-height: 52px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border); flex: none;
  flex-wrap: wrap; row-gap: 8px; max-width: 100%;
}
.brand { font-weight: 700; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
#topbar-menu { display: flex; align-items: center; gap: 14px; flex: 1 1 auto; min-width: 0; flex-wrap: wrap; row-gap: 8px; }
nav.tabs { display: flex; gap: 4px; }
nav.tabs button {
  background: transparent; border: none; color: var(--text-dim); padding: 8px 12px;
  border-radius: 8px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
nav.tabs button:hover { background: var(--bg-hover); color: var(--text); }
nav.tabs button.active { background: var(--accent-dim); color: var(--accent); }
.topbar-spacer { flex: 1; }
.role-badge {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px;
}
.role-badge.tecnico { color: var(--ok); border-color: #1f4d33; }
.user-chip { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

/* Indicador de papel sempre visível (nunca escondido no menu mobile) */
.role-banner {
  display: flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700;
  padding: 5px 11px; border-radius: 999px; white-space: nowrap; letter-spacing: .3px;
}
.role-banner.tecnico { background: #0d2116; color: var(--ok); border: 1px solid #1f4d33; }
.role-banner.visualizador { background: #2a1608; color: var(--warn); border: 1px solid #5c3a10; }

/* ---------- Menu mobile / off-canvas ---------- */
.icon-btn {
  background: var(--bg-panel-2); border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { border-color: var(--accent); }
.mobile-only { display: none; }
.backdrop-layer { display: none; position: fixed; inset: 0; background: rgba(4,8,14,.55); z-index: 1150; }
.backdrop-layer.visible { display: block; }

main#views { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.view { display: none; height: 100%; }
.view.active { display: flex; }

/* Destaque do que está selecionado (clique ou busca): halo roxo que pisca. */
.leaflet-marker-icon.marker-selected {
  animation: marker-select-glow .85s ease-in-out infinite alternate;
  z-index: 10000 !important;
}
@keyframes marker-select-glow {
  from { filter: drop-shadow(0 0 1px var(--sel-bright)) drop-shadow(0 0 5px var(--sel)); opacity: .7; }
  to   { filter: drop-shadow(0 0 6px var(--sel-bright)) drop-shadow(0 0 16px var(--sel)) drop-shadow(0 0 26px var(--sel)); opacity: 1; }
}

/* Cabo selecionado: um traço roxo largo por baixo do cabo, piscando junto. */
.cabo-selecionado {
  stroke: var(--sel);
  animation: cabo-select-glow .85s ease-in-out infinite alternate;
}
@keyframes cabo-select-glow {
  from { stroke-opacity: .4;  stroke-width: 11; }
  to   { stroke-opacity: .95; stroke-width: 22; }
}

/* ---------- Mapa view ---------- */
#view-mapa { position: relative; }
#map { flex: 1; height: 100%; background: #0b111c; }
.leaflet-container { background: #0b111c; }

#sidebar {
  width: 250px; flex: none; background: var(--bg-panel); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 14px;
}
#sidebar h3 { font-size: 11px; text-transform: uppercase; color: var(--text-faint); letter-spacing: .6px; margin: 18px 0 8px; }
#sidebar h3:first-child { margin-top: 0; }
#sidebar-toggle { position: absolute; bottom: 22px; left: 14px; z-index: 1100; box-shadow: var(--shadow); }
#sidebar-close { position: absolute; top: 10px; right: 10px; }
.tool-btn {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 6px; cursor: pointer; color: var(--text);
}
.tool-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.tool-btn.active { border-color: var(--accent); background: var(--accent-dim); }
.tool-btn img, .tool-btn .ic { width: 20px; height: 20px; flex: none; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); padding: 3px 0; }
.legend-swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.layer-toggle { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text); padding: 3px 0; cursor: pointer; }
.layer-toggle input { accent-color: var(--accent); width: 14px; height: 14px; flex: none; }
.layer-toggle .ic { width: 16px; height: 16px; flex: none; }
.layer-actions { display: flex; gap: 6px; margin: 6px 0 2px; }
.layer-actions button { flex: 1; font-size: 11px; padding: 5px 6px; }
.draw-style { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; padding: 8px; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px; }
.draw-style label { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 5px; }
.draw-style input[type="color"] { width: 26px; height: 24px; border: 1px solid var(--border); border-radius: 5px; background: none; padding: 0; cursor: pointer; }
.draw-style input[type="number"] { width: 44px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 5px; padding: 3px 5px; color: var(--text); }
.color-swatches { display: flex; gap: 5px; flex-wrap: wrap; margin: 4px 0 8px; }
.color-swatch { width: 20px; height: 20px; border-radius: 5px; cursor: pointer; border: 2px solid transparent; }
.color-swatch.selected { border-color: var(--text); }
#search-box {
  width: 100%; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; color: var(--text); margin-bottom: 4px;
}
#search-results { max-height: 200px; overflow-y: auto; }
.search-hit { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.search-hit:hover { background: var(--bg-hover); }
.map-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1100;
  background: var(--accent-dim); border: 1px solid var(--accent); color: var(--text);
  padding: 8px 16px; border-radius: 999px; font-size: 12.5px; display: none; align-items: center; gap: 10px;
}
.map-banner.visible { display: flex; }

/* ---------- Painel de detalhe ---------- */
#detail-panel {
  position: absolute; top: 0; right: -1000px; width: 440px; height: 100%;
  background: var(--bg-panel); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transition: right .18s ease; overflow-y: auto; z-index: 1200;
}
#detail-panel.open { right: 0; }
#detail-panel.wide { width: 760px; }
.panel-head { padding: 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.panel-head h2 { font-size: 15px; margin: 0 0 4px; word-break: break-word; }
.panel-head .type-tag { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.panel-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; line-height: 1; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.panel-tabs button {
  flex: 1; background: none; border: none; color: var(--text-dim); padding: 10px; cursor: pointer;
  font-weight: 600; font-size: 12.5px; border-bottom: 2px solid transparent;
}
.panel-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-body { padding: 16px; }
.status-select { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.status-pill {
  padding: 5px 10px; border-radius: 999px; font-size: 11.5px; cursor: pointer; border: 1px solid var(--border);
  color: var(--text-dim); background: var(--bg-panel-2);
}
.status-pill.selected { color: #fff; border-color: transparent; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
.kv .k { color: var(--text-dim); }
.hint { color: var(--text-faint); font-size: 11.5px; margin-top: 4px; }

/* ---------- Splice / Splitter editors ---------- */
/* ---------- Diagrama de fusão (pente de núcleos) ---------- */
.fiber-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 10px; padding: 8px 10px; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px; }
.fiber-legend-padrao { font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--text-faint); border-right: 1px solid var(--border); padding-right: 10px; display: flex; align-items: center; }
.fiber-legend-item { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-dim); }
.fiber-legend-item i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.3); }
.splice-selects { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.splice-selects select { flex: 1; min-width: 0; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 9px; color: var(--text); }
.splice-diagram-wrap { overflow-x: auto; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.splice-svg { width: 100%; min-width: 620px; display: block; }
.splice-svg .rack-title { fill: var(--text); font-size: 11.5px; font-weight: 700; }
.splice-svg .rack-sub { fill: var(--text-faint); font-size: 9px; }
.splice-svg .col-header-g.clickable { cursor: pointer; }
.splice-svg .col-header-g.clickable:hover .rack-title { fill: var(--accent); text-decoration: underline; }
.splice-svg .col-header-g.clickable:hover .col-role-bg { stroke-width: 2; }
.splice-svg .core-dot.flash { animation: core-flash .4s ease-in-out 3; }
@keyframes core-flash { 0%, 100% { r: 7; } 50% { r: 13; } }
.splice-conn { cursor: pointer; padding: 3px 4px; border-radius: 6px; }
.splice-conn:hover { background: var(--bg-hover); }
.splice-svg .tubo-label { font-size: 9.5px; font-weight: 600; }
.splice-svg .core-stub { stroke: var(--text-faint); stroke-width: 1.5; }
.splice-svg .core-num { fill: var(--text-dim); font-size: 10px; }
.splice-svg .core-dot-g { cursor: pointer; }
.splice-svg .core-dot { stroke: rgba(0,0,0,.35); stroke-width: 1; transition: r .1s; }
.splice-svg .core-dot-g:hover .core-dot { stroke: #fff; stroke-width: 2; }
.splice-svg .core-dot.pending { stroke: #fff; stroke-width: 2.5; filter: drop-shadow(0 0 4px rgba(255,255,255,.6)); }
.splice-svg .core-dot.linked { stroke: #fff; stroke-width: 1.5; }
.splice-svg .core-warn-ring { fill: none; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 3 2; }
.splice-svg .core-batch-ring { fill: none; stroke: var(--ok); stroke-width: 2; }
.splice-svg .core-batch-badge-bg { fill: var(--ok); }
.splice-svg .core-batch-badge { fill: #062b12; font-size: 9px; font-weight: 700; }
.splice-svg .conn-line { stroke-width: 2.5; opacity: .9; }
.splice-svg .splitter-g { cursor: grab; touch-action: none; }
.splice-svg .splitter-g:active { cursor: grabbing; }
.splice-svg .splitter-body { fill: var(--bg-panel-2); stroke: var(--text-faint); stroke-width: 1.5; }
.splice-svg .splitter-body.fed { stroke: var(--info); fill: #0c1f2c; }
.splice-svg .splitter-g:hover .splitter-body { stroke: var(--accent); }
.splice-svg .splitter-fan { stroke: var(--text-faint); stroke-width: 1.5; stroke-linecap: round; }
.splice-svg .splitter-fan.fed { stroke: var(--info); }
.splice-svg .splitter-port-in, .splice-svg .splitter-port-out { fill: var(--bg-panel); stroke: var(--text-faint); stroke-width: 1.5; }
.splice-svg .splitter-port-in.fed, .splice-svg .splitter-port-out.fed { fill: var(--info); stroke: var(--info); }
.port-fusao { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-dim); margin-top: 3px; }
.port-fusao i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.3); }
.splice-svg .splitter-spine { stroke: var(--text-faint); stroke-width: 1.2; stroke-linecap: round; opacity: .7; }
.splice-svg .splitter-spine.fed { stroke: var(--info); }
/* Portas de saída do splitter: cada uma é um terminal de fusão clicável. */
.splice-svg .splitter-out-g { cursor: pointer; }
.splice-svg .splitter-out-dot { fill: var(--bg-panel); stroke: var(--text-faint); stroke-width: 1.5; }
.splice-svg .splitter-out-g.ligada .splitter-out-dot { stroke: #fff; stroke-width: 1.2; }
.splice-svg .splitter-out-g.cliente .splitter-out-dot { stroke: var(--ok); stroke-width: 2; }
.splice-svg .splitter-out-g:hover .splitter-out-dot { stroke: var(--accent); stroke-width: 2.5; }
.splice-svg .splitter-out-num { fill: var(--text-faint); font-size: 8.5px; }
.splice-svg .splitter-out-g.ligada .splitter-out-num { fill: var(--text-dim); font-weight: 700; }
.splice-svg .out-line { stroke-width: 2; opacity: .95; }
.splice-svg .splitter-label { fill: var(--text-dim); font-size: 10.5px; font-weight: 600; }
.splice-svg .splitter-hint { fill: var(--text-faint); font-size: 9px; font-style: italic; }
.splice-svg .splitter-drag-hint { fill: var(--text-faint); font-size: 9px; opacity: 0; transition: opacity .15s; }
.splice-svg .splitter-g:hover .splitter-drag-hint { opacity: 1; }
.splice-svg .col-role-bg { fill: var(--bg-panel); stroke-width: 1; }
.splice-svg .col-role-bg.entrada { stroke: var(--info); }
.splice-svg .col-role-bg.saida { stroke: var(--warn); }
.splice-svg .col-role-txt { font-size: 9px; font-weight: 700; letter-spacing: .4px; }
.splice-svg text.col-role-txt.entrada { fill: var(--info); }
.splice-svg text.col-role-txt.saida { fill: var(--warn); }
.splice-list { margin-top: 14px; }
.splice-conn { display: flex; align-items: center; gap: 6px; font-size: 11.5px; padding: 4px 0; color: var(--text-dim); }
.core-dot-flat { width: 9px; height: 9px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.3); }
.splice-conn button { margin-left: auto; }

.splitter-card { background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.splitter-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ports-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.port-cell {
  border: 1px solid var(--border); border-radius: 6px; padding: 6px; font-size: 11px; cursor: pointer;
  background: var(--bg-panel); text-align: center;
}
.port-cell.livre { color: var(--text-faint); }
.port-cell.ocupado { border-color: var(--ok); color: var(--ok); background: #0d2116; }
.port-cell:hover { border-color: var(--accent); }
.port-cell.port-zero { margin-bottom: 8px; text-align: left; border-style: dashed; }
.port-cell.port-zero.livre { border-color: var(--text-faint); }
.port-cell.port-zero.ocupado { border-color: var(--info); color: var(--info); background: #0c1f2c; }

/* ---------- OLT view ---------- */
#view-olts { overflow-y: auto; padding: 20px; width: 100%; flex-direction: column; gap: 16px; }
.olt-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.olt-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.placa-block { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.placa-block h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--text-dim); }
.porta-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.porta-cell {
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 4px; font-size: 10.5px; text-align: center;
  cursor: pointer; background: var(--bg-panel-2);
}
.porta-cell.ligado { border-color: var(--info); color: var(--info); background: #0c1f2c; }
.porta-cell-dest {
  display: block; font-size: 8.5px; line-height: 1.3; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.porta-cell:hover { border-color: var(--accent); }

.numeracao-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.numeracao-row select { width: auto; flex: 0 1 auto; font-size: 12px; padding: 5px 8px; }

.backup-block { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.backup-block strong { display: block; font-size: 13px; margin-bottom: 4px; }
.backup-block .hint { margin-bottom: 10px; }
.backup-block code { background: var(--bg-panel-2); border-radius: 4px; padding: 1px 5px; font-size: 11.5px; }

.quick-setup { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; }
.quick-setup label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.quick-setup-row { display: flex; gap: 8px; align-items: center; }
.quick-setup-row input { width: 80px; flex: none; }

.dio-portas-list { display: flex; flex-direction: column; gap: 4px; }
.dio-porta-row {
  display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; background: var(--bg-panel-2); flex-wrap: wrap;
}
.dio-porta-row:hover { border-color: var(--accent); }
.dio-porta-row.ligado { border-color: var(--info); }
.dio-porta-num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--bg-hover); color: var(--text); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.dio-porta-olt { color: var(--text-dim); flex: 1; min-width: 160px; }
.dio-porta-cabo { color: var(--text-dim); flex: 1; min-width: 200px; }
.dio-fiber-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 4px 0 6px; border: 1px solid rgba(0,0,0,.3); }

/* ---------- Diagrama ---------- */
#view-diagrama { overflow: auto; padding: 20px; width: 100%; }
.tree { font-size: 13px; }
.tree ul { list-style: none; margin: 0; padding-left: 22px; border-left: 1px dashed var(--border); }
.tree li { margin: 4px 0; position: relative; }
.node-row { display: flex; align-items: center; gap: 8px; padding: 5px 9px; border-radius: 7px; background: var(--bg-panel-2); border: 1px solid var(--border); width: fit-content; }
.node-row .ic { width: 16px; height: 16px; }
.node-row .tag { font-size: 10px; color: var(--text-faint); text-transform: uppercase; }
.node-row .badge { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; background: var(--bg-hover); color: var(--text-dim); }
.node-row .badge.ok { color: var(--ok); }
.node-row .badge.full { color: var(--warn); }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

/* ---------- Usuários ---------- */
#view-usuarios { padding: 24px; overflow-y: auto; width: 100%; }
table.users-table { width: 100%; max-width: 640px; border-collapse: collapse; }
table.users-table th, table.users-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.users-table th { color: var(--text-dim); font-weight: 600; font-size: 11.5px; text-transform: uppercase; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel-2); border: 1px solid var(--border); padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: all .2s ease; pointer-events: none; z-index: 1500; font-size: 13px;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--danger); color: #ffb4b0; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4,8,14,.6); display: none; align-items: center; justify-content: center; z-index: 1600; padding: 16px;
}
.modal-backdrop.visible { display: flex; }
/* Janela encostada no canto direito (usada na edição de cabo): assim ela não tapa
   o trecho do mapa que está sendo editado. */
.modal-backdrop.ancora-direita { justify-content: flex-end; align-items: flex-start; padding: 16px; }
.modal-backdrop.ancora-direita .modal-card { margin: 0; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(380px, 100%); max-height: 88vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 14px; font-size: 15px; }
.modal-card h3.draggable-handle {
  cursor: move; user-select: none; padding: 4px 6px; margin: -4px -6px 14px -6px; border-radius: 6px;
  display: flex; align-items: center; gap: 8px;
}
.modal-card h3.draggable-handle::before { content: '⠿'; color: var(--text-faint); font-size: 14px; }
.modal-card h3.draggable-handle:hover { background: var(--bg-panel-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Autocomplete ---------- */
.ac-wrap { position: relative; }
.ac-input {
  width: 100%; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 32px 9px 11px; color: var(--text); outline: none;
}
.ac-input:focus { border-color: var(--accent); }
.ac-clear {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border-radius: 6px;
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 13px;
}
.ac-clear:hover { background: var(--bg-hover); color: var(--text); }
.ac-results {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; max-height: 240px;
  overflow-y: auto; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); z-index: 50;
}
.ac-results.open { display: block; }
.ac-item { padding: 8px 11px; cursor: pointer; font-size: 12.5px; display: flex; justify-content: space-between; gap: 8px; }
.ac-item:hover { background: var(--bg-hover); }
.ac-sub { color: var(--text-faint); font-size: 11px; flex: none; }
.ac-empty { padding: 10px 11px; color: var(--text-faint); font-size: 12.5px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* =====================================================================
   Responsivo (celular / tablet estreito) — técnicos vão acessar pelo celular
   ===================================================================== */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  body { font-size: 15px; }

  .mobile-only { display: flex; }
  .desktop-only { display: none; }

  header#topbar { gap: 10px; padding: 0 10px; }
  .brand { font-size: 12.5px; }
  .brand-text { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .role-banner span.txt { display: none; }

  #topbar-menu {
    position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
    background: var(--bg-panel); flex-direction: column; align-items: stretch;
    gap: 4px; padding: 14px; overflow-y: auto; z-index: 1200;
    display: none;
  }
  #topbar-menu.open { display: flex; }
  #topbar-menu nav.tabs { flex-direction: column; gap: 4px; }
  #topbar-menu nav.tabs button { text-align: left; padding: 12px 14px; font-size: 15px; }
  #topbar-menu .user-chip { flex-wrap: wrap; padding: 10px 4px; border-top: 1px solid var(--border); margin-top: 6px; }
  #topbar-menu #btn-import-kmz, #topbar-menu #btn-change-pw { width: 100%; text-align: center; padding: 11px; }

  main#views { overflow: hidden; }

  /* Sidebar vira gaveta lateral */
  #sidebar {
    position: fixed; top: 52px; bottom: 0; left: 0; width: 86%; max-width: 320px;
    transform: translateX(-100%); transition: transform .2s ease; z-index: 1200; box-shadow: var(--shadow);
  }
  #sidebar.open { transform: translateX(0); }

  /* Painel de detalhe ocupa quase a tela toda (mesmo no modo "wide" da Fusão) */
  #detail-panel, #detail-panel.wide { width: 94vw; right: -1000px; }
  #detail-panel.open { right: 0; }

  .ports-grid { grid-template-columns: repeat(3, 1fr); }
  .porta-grid { grid-template-columns: repeat(6, 1fr); }
  nav.tabs button, .panel-tabs button { font-size: 13px; }

  #view-olts, #view-diagrama, #view-usuarios { padding: 14px; }
  table.users-table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (max-width: 420px) {
  .porta-grid { grid-template-columns: repeat(4, 1fr); }
}
