/* =========================================================================
   Tower network map (topology) - per agent
   ========================================================================= */
.topo-hide { display: none !important; }

/* ---- toolbar ---- */
.topo-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: 0 0 1rem;
}
.topo-header-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 1rem;
    background: rgba(92, 181, 198, 0.12);
    border: 1px solid rgba(120, 202, 219, 0.35);
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 800;
    color: #f8fafc;
    box-shadow: 0 4px 14px rgba(92, 181, 198, 0.15);
}
.topo-header-badge i {
    font-size: 1rem;
    color: #78cadb;
}
.topo-seg {
    display: none !important;
}
.topo-seg-btn {
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.5rem 1rem;
    border: 0; border-radius: 9px;
    background: transparent; color: #a0a1ab;
    font-family: inherit; font-size: 0.85rem; font-weight: 800;
    cursor: pointer; transition: all .2s;
}
.topo-seg-btn.active { background: linear-gradient(135deg, #b3e000, #97be00); color: #021922; box-shadow: 0 4px 14px rgba(92, 181, 198, .35); }
.topo-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.topo-zoom { display: inline-flex; gap: 4px; }
.topo-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: #e7e7ec;
    font-family: inherit; font-size: 0.82rem; font-weight: 800;
    cursor: pointer; transition: all .2s;
}
.topo-btn:hover { background: rgba(255, 255, 255, 0.1); }
.topo-btn.primary { background: rgba(92, 181, 198, .18); border-color: rgba(92, 181, 198, .5); color: #9de0ee; }
.topo-btn.magic { background: rgba(188, 181, 241, .18); border-color: rgba(188, 181, 241, .5); color: #c5bdfa; }
.topo-btn.icon { padding: 0.5rem 0.65rem; }
.topo-btn.danger { color: #f87171; border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .1); }
.topo-btn.active { background: rgba(92, 181, 198, 0.25); border-color: rgba(120, 202, 219, 0.6); color: #78cadb; }
.topo-btn.topo-lock-btn {
    transition: all .2s ease;
    min-width: 85px;
}
.topo-btn.topo-lock-btn.locked {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.14);
    color: #d3d3da;
}
.topo-btn.topo-lock-btn.locked i {
    color: #78cadb;
}
.topo-btn.topo-lock-btn.unlocked {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.65);
    color: #fef08a;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.28);
}
.topo-btn.topo-lock-btn.unlocked i {
    color: #fbbf24;
}

/* Cursor and drag behavior per lock state */
.topo-viewport.is-locked .topo-node {
    cursor: pointer !important;
}
.topo-viewport:not(.is-locked) .topo-node {
    cursor: grab !important;
}
.topo-viewport:not(.is-locked) .topo-node.dragging {
    cursor: grabbing !important;
}

.topo-zoom-label {
    min-width: 44px;
    font-size: 0.74rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.2px;
    padding: 0 6px;
    cursor: pointer;
}

/* ---- Fullscreen Mode ---- */
.dude-topology-section {
    position: relative;
    width: 100%;
}
.dude-topology-section:fullscreen,
.dude-topology-section:-webkit-full-screen,
.dude-topology-section.topo-fullscreen-mode {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    z-index: 9999 !important;
    background: #00151f !important;
    padding: 1rem 1.25rem !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}
body.topo-fullscreen-active {
    overflow: hidden !important;
}
.dude-topology-section:fullscreen #dudeViewToolbar,
.dude-topology-section:-webkit-full-screen #dudeViewToolbar,
.dude-topology-section.topo-fullscreen-mode #dudeViewToolbar {
    flex: 0 0 auto !important;
    margin-bottom: 0.75rem !important;
}
.dude-topology-section:fullscreen #dudeTopologyWrap,
.dude-topology-section:-webkit-full-screen #dudeTopologyWrap,
.dude-topology-section.topo-fullscreen-mode #dudeTopologyWrap {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}
.dude-topology-section:fullscreen .topo-viewport,
.dude-topology-section:-webkit-full-screen .topo-viewport,
.dude-topology-section.topo-fullscreen-mode .topo-viewport {
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    border-radius: 14px !important;
}

/* ---- banner (hints / empty state - disabled) ---- */
.topo-banner {
    display: none !important;
}

.topo-empty {
    text-align: center;
    padding: 2.2rem 1.2rem;
    border: 1px dashed rgba(255, 255, 255, .15);
    border-radius: 16px;
    background: rgba(0, 33, 46, .5);
}
.topo-empty h3 { margin: 0 0 .4rem; color: #f8fafc; font-size: 1.15rem; font-weight: 800; }
.topo-empty p { margin: 0 0 1.2rem; color: #a0a1ab; font-size: .88rem; }
.topo-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; text-align: start; }
.topo-step {
    display: flex; flex-direction: column; gap: .5rem;
    padding: .9rem; border-radius: 14px;
    background: rgba(0, 14, 22, .45); border: 1px solid rgba(255, 255, 255, .08);
}
.topo-step b { color: #f1f5f9; font-size: .92rem; }
.topo-step span { color: #a0a1ab; font-size: .78rem; line-height: 1.5; }
.topo-step .num {
    width: 28px; height: 28px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(92, 181, 198, .2); color: #78cadb; font-weight: 800; font-size: .85rem;
}
.topo-step .topo-btn { align-self: flex-start; }

/* ---- layout & canvas ---- */
.topo-wrap {
    position: relative;
    width: 100%;
}
.topo-main-layout {
    display: flex;
    flex-direction: row;
    gap: 12px;
    width: 100%;
    /* Fill the screen instead of a fixed 600px box */
    height: clamp(560px, calc(100vh - 200px), 1100px);
    position: relative;
    overflow: hidden;
}
.dude-topology-section:fullscreen .topo-main-layout,
.dude-topology-section:-webkit-full-screen .topo-main-layout,
.dude-topology-section.topo-fullscreen-mode .topo-main-layout {
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
}

/* ---- Towers Sidebar (قائمة الأبراج الجانبية) ---- */
.topo-sidebar {
    width: 290px;
    flex: 0 0 290px;
    height: 100%;
    background: rgba(0, 28, 40, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, flex 0.25s ease;
    direction: rtl;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    z-index: 20;
}

.topo-sidebar.collapsed {
    width: 0 !important;
    flex: 0 0 0 !important;
    min-width: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

.topo-sidebar-head {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 33, 46, 0.65);
    flex: 0 0 auto;
}

.topo-sidebar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 0.94rem;
    color: #f1f5f9;
}

.topo-sidebar-pill {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(60, 168, 188, 0.2);
    color: #90d2e0;
    border: 1px solid rgba(60, 168, 188, 0.35);
}

.topo-sidebar-close-btn {
    background: transparent;
    border: none;
    color: #a0a1ab;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 6px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.topo-sidebar-close-btn:hover {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.08);
}

.topo-sidebar-add-bar {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 33, 46, 0.3);
    flex: 0 0 auto;
}

.topo-sidebar-add-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(92, 181, 198, 0.4);
    background: linear-gradient(135deg, rgba(92, 181, 198, 0.2), rgba(84, 166, 182, 0.3));
    color: #78cadb;
    font-size: 0.84rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
}

.topo-sidebar-add-btn:hover {
    background: linear-gradient(135deg, rgba(92, 181, 198, 0.35), rgba(84, 166, 182, 0.5));
    border-color: #78cadb;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(92, 181, 198, 0.35);
}

.topo-sidebar-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.topo-sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.topo-sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.topo-sidebar-item {
    background: rgba(13, 52, 67, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 10px 11px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.topo-sidebar-item:hover {
    background: rgba(13, 52, 67, 0.9);
    border-color: rgba(60, 168, 188, 0.4);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    transform: translateY(-1px);
}

.topo-sidebar-item.active {
    background: rgba(0, 67, 90, 0.45);
    border-color: #52b4c7;
    box-shadow: 0 0 14px rgba(60, 168, 188, 0.35);
}

.topo-sidebar-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 7px;
}

.topo-sidebar-item-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    font-size: 0.86rem;
    color: #f8fafc;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
}

.topo-sidebar-item-title i {
    color: #52b4c7;
    font-size: 0.92rem;
    flex-shrink: 0;
}

.topo-sidebar-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topo-sidebar-status-tag {
    font-size: 0.66rem;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 6px;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

.topo-sidebar-status-tag.up {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.topo-sidebar-status-tag.down {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.topo-sidebar-status-tag.empty {
    background: rgba(160, 161, 171, 0.12);
    color: #a0a1ab;
    border: 1px solid rgba(160, 161, 171, 0.25);
}

.topo-sidebar-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-size: 0.72rem;
    color: #a0a1ab;
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.topo-sidebar-dev-count {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 700;
    color: #d3d3da;
}

.topo-sidebar-focus-hint {
    font-size: 0.68rem;
    color: #72727c;
    display: flex;
    align-items: center;
    gap: 4px;
}

.topo-sidebar-item:hover .topo-sidebar-focus-hint {
    color: #90d2e0;
}

.topo-sidebar-item-tools {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.topo-sidebar-tool-btn {
    width: 25px;
    height: 25px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: #d3d3da;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.72rem;
    transition: all 0.15s ease;
}

.topo-sidebar-tool-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.3);
}

.topo-sidebar-tool-btn.danger:hover {
    background: rgba(239, 68, 68, 0.22);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.45);
}

.topo-sidebar-empty {
    padding: 24px 12px;
    text-align: center;
    color: #a0a1ab;
    font-size: 0.8rem;
    line-height: 1.6;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

/* Highlight pulse on nodes when a tower is focused */
@keyframes topoNodePulse {
    0% {
        box-shadow: 0 0 0 0 rgba(60, 168, 188, 0.8);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 22px 6px rgba(60, 168, 188, 0.95);
        transform: scale(1.06);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(60, 168, 188, 0);
        transform: scale(1);
    }
}
.topo-node.topo-node-highlighted {
    animation: topoNodePulse 1.2s ease-in-out 2 !important;
    border-color: #52b4c7 !important;
    z-index: 50 !important;
}

/* Drawer mode (tablet / narrow desktop / phone): the towers list slides over the map instead of eating its width */
.topo-main-layout.drawer-mode .topo-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 86%);
    height: auto;
    max-height: 100%;
    flex: none;
    z-index: 40;
    transform: translateX(0);
    transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1), opacity .2s ease;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.6);
}
.topo-main-layout.drawer-mode .topo-sidebar.collapsed {
    width: min(300px, 86%) !important;
    transform: translateX(110%);
}
.topo-main-layout.drawer-mode.drawer-open::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 35;
    background: rgba(0, 14, 22, 0.45);
    border-radius: 16px;
    pointer-events: none;
}
[dir="ltr"] .topo-main-layout.drawer-mode .topo-sidebar { right: auto; left: 0; }
[dir="ltr"] .topo-main-layout.drawer-mode .topo-sidebar.collapsed { transform: translateX(-110%); }

/* ---- canvas viewport ---- */
.topo-viewport {
    position: relative;
    overflow: hidden;
    direction: ltr;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, .08);
    background:
        radial-gradient(circle at 1px 1px, rgba(160, 161, 171, .16) 1px, transparent 0) 0 0 / 24px 24px,
        linear-gradient(180deg, #001c28, #00151f);
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.topo-viewport.panning {
    cursor: grabbing !important;
}
.topo-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}
.topo-links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }

.topo-nav-hint {
    position: absolute;
    bottom: 12px;
    left: 14px;
    z-index: 10;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(0, 33, 46, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 5px 14px;
    font-size: 0.74rem;
    font-weight: 700;
    color: #a0a1ab;
    direction: rtl;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.topo-nav-hint i {
    color: #78cadb;
    font-size: 0.85rem;
}

/* ---- node ---- */
.topo-node {
    position: absolute;
    z-index: 2;
    box-sizing: border-box;
    display: flex; flex-direction: row; align-items: center; gap: 10px;
    padding: 10px 12px;
    direction: rtl;
    border-radius: 14px;
    background: linear-gradient(160deg, #032b3a 0%, #00202d 100%);
    border: 1px solid rgba(160, 161, 171, .18);
    box-shadow: 0 8px 22px -10px rgba(0, 0, 0, .85), inset 0 1px 0 rgba(255, 255, 255, .04);
    cursor: grab;
    user-select: none;
    touch-action: none;
    transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
}
.topo-node::before {
    /* kind accent bar on the leading edge */
    content: '';
    position: absolute;
    top: 12px; bottom: 12px;
    inset-inline-start: -1px;
    width: 3px;
    border-radius: 3px;
    background: var(--k, #c7f900);
    box-shadow: 0 0 10px var(--k, #78cadb);
}
.topo-node:hover {
    box-shadow: 0 12px 28px -8px rgba(0, 0, 0, .9), 0 0 0 1px rgba(120, 202, 219, .45), 0 0 18px rgba(120, 202, 219, .25);
    border-color: rgba(120, 202, 219, .55);
}
.topo-node.dragging {
    z-index: 100 !important;
    opacity: 0.95;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.85), 0 0 25px rgba(120, 202, 219, 0.7) !important;
    transform: scale(1.07);
    cursor: grabbing !important;
    transition: none !important;
}
.topo-node.selected { border-color: #78cadb; box-shadow: 0 0 0 2px rgba(120, 202, 219, .45); }

/* ---- Connect Handle (علامة الربط السفلية) ---- */
.topo-connect-handle {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #00151f;
    border: 2px solid #78cadb;
    box-shadow: 0 0 10px rgba(120, 202, 219, 0.7), 0 3px 6px rgba(0, 0, 0, 0.7);
    display: none; /* Controlled by lock state */
    align-items: center;
    justify-content: center;
    color: #78cadb;
    font-size: 9px;
    cursor: crosshair;
    z-index: 25;
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    touch-action: none;
}
.topo-connect-handle:hover {
    transform: translateX(-50%) scale(1.3);
    background: #98be00;
    border-color: #021922;
    color: #021922;
    box-shadow: 0 0 18px rgba(120, 202, 219, 1), 0 0 26px rgba(92, 181, 198, 0.7);
}
.topo-connect-handle:active {
    transform: translateX(-50%) scale(1.15);
}

/* Visibility based on lock state */
.topo-viewport.is-locked .topo-connect-handle {
    display: none !important;
}
.topo-viewport:not(.is-locked) .topo-connect-handle {
    display: flex !important;
}

/* Target node highlight when wire is dragged over it */
.topo-node.connect-target {
    border-color: #34d399 !important;
    box-shadow: 0 0 24px rgba(52, 211, 153, 0.9), 0 0 0 3px rgba(52, 211, 153, 0.45) !important;
    transform: scale(1.05);
    z-index: 50;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

/* Wire preview SVG styling */
.topo-wire-preview {
    fill: none;
    stroke: #78cadb;
    stroke-width: 3.5;
    stroke-dasharray: 8 5;
    stroke-linecap: round;
    filter: drop-shadow(0 0 8px #78cadb);
    pointer-events: none;
    animation: topoWirePulse 0.8s linear infinite;
}
@keyframes topoWirePulse {
    from { stroke-dashoffset: 26; }
    to { stroke-dashoffset: 0; }
}

.topo-viewport.wiring-active {
    cursor: crosshair !important;
}
.topo-viewport.wiring-active .topo-node {
    cursor: crosshair !important;
}
.topo-node.k-router { --k: #c7f900; }
.topo-node.k-ptp    { --k: #34d399; }
.topo-node.k-sector { --k: #d3ff59; }
.topo-node.k-cpe    { --k: #fbbf24; }
.topo-node.k-olt    { --k: #ec4899; }
.topo-node.k-other  { --k: #a0a1ab; }
.topo-node.st-down {
    border-color: rgba(239, 68, 68, .65);
    background: linear-gradient(160deg, #3a1219 0%, #1f0f18 100%);
    box-shadow: 0 8px 22px -10px rgba(0, 0, 0, .85), 0 0 18px rgba(239, 68, 68, .25);
}
.topo-node.st-down::before { background: #ef4444; box-shadow: 0 0 10px #ef4444; }
.topo-node.unlinked { border-style: dashed; }
.topo-node-tile {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--k, #c7f900) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--k, #78cadb) 40%, transparent);
}
.topo-node-ico { color: var(--k); font-size: 1.15rem; }
.topo-node.st-down .topo-node-tile { background: rgba(239, 68, 68, .16); border-color: rgba(239, 68, 68, .45); }
.topo-node.st-down .topo-node-ico { color: #f87171; }
.topo-node-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex; flex-direction: column; gap: 5px;
}
.topo-node-name {
    min-width: 0;
    font-size: .9rem;
    font-weight: 800;
    line-height: 1.2;
    color: #f8fafc;
    /* full name on up to two lines instead of cutting it with "..." */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    white-space: normal;
    overflow-wrap: anywhere;
    unicode-bidi: plaintext;
    text-align: start;
}
.topo-node-name.long { font-size: .78rem; }
.topo-node-meta {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    min-width: 0;
}
.topo-node-ip {
    font-family: 'JetBrains Mono', monospace;
    font-size: .7rem;
    font-weight: 600;
    color: #a0a1ab;
    direction: ltr;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.topo-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: #72727c; }
.st-up .topo-dot { background: #22c55e; box-shadow: 0 0 8px #22c55e; animation: topoDotPulse 2s ease-in-out infinite; }
.st-down .topo-dot { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.st-pending .topo-dot { background: #c7f900; }
@keyframes topoDotPulse { 50% { box-shadow: 0 0 2px #22c55e; } }
.topo-node-sub {
    font-family: 'JetBrains Mono', monospace;
    font-size: .66rem;
    font-weight: 800;
    letter-spacing: 0.6px;
    direction: ltr;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(160, 161, 171, .12);
}
.topo-node-sub.st-up { background: rgba(34, 197, 94, .14); }
.topo-node-sub.st-down { background: rgba(239, 68, 68, .18); }
.topo-node-sub.st-pending { background: rgba(120, 202, 219, .14); }

/* ---- tower group frames ---- */
.topo-frame {
    position: absolute;
    z-index: 0;
    box-sizing: border-box;
    direction: rtl;
    border-radius: 20px;
    border: 1px solid rgba(82, 180, 199, .22);
    background:
        linear-gradient(180deg, rgba(60, 168, 188, .10) 0, rgba(60, 168, 188, .03) 50px, rgba(0, 33, 46, .25) 51px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
    pointer-events: none;
}
.topo-frame.has-down { border-color: rgba(239, 68, 68, .35); }
.topo-frame.empty { border-style: dashed; border-color: rgba(160, 161, 171, .28); }
.topo-frame-head {
    display: flex; align-items: center; gap: 8px;
    height: 50px;
    padding: 0 14px;
    min-width: 0;
}
.topo-frame-ico {
    width: 28px; height: 28px; flex: 0 0 auto;
    border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(82, 180, 199, .18);
    color: #90d2e0;
    font-size: .85rem;
}
.topo-frame-name {
    flex: 1 1 auto; min-width: 0;
    font-size: .95rem; font-weight: 800; color: #f1f5f9;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    unicode-bidi: plaintext; text-align: start;
}
.topo-frame-count {
    flex: 0 0 auto;
    font-size: .72rem; font-weight: 800; color: #d3d3da;
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px;
    background: rgba(255, 255, 255, .06);
}
.topo-frame-count i { font-size: .65rem; color: #a0a1ab; }
.topo-frame-status {
    flex: 0 0 auto;
    font-size: .7rem; font-weight: 800;
    padding: 3px 9px; border-radius: 999px;
    white-space: nowrap;
}
.topo-frame-status.up { color: #4ade80; background: rgba(34, 197, 94, .14); }
.topo-frame-status.down { color: #fca5a5; background: rgba(239, 68, 68, .2); }
.topo-frame-status.empty { color: #a0a1ab; background: rgba(160, 161, 171, .12); }
.topo-frame-add {
    pointer-events: auto;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin: 16px 18px 0;
    width: calc(100% - 36px);
    height: 48px;
    border-radius: 12px;
    border: 1px dashed rgba(120, 202, 219, .45);
    background: rgba(120, 202, 219, .08);
    color: #9de0ee;
    font-family: inherit; font-size: .85rem; font-weight: 800;
    cursor: pointer;
}
.topo-frame-add:hover { background: rgba(120, 202, 219, .16); }
.topo-node-sub.st-up,
.st-up .topo-node-sub {
    color: #4ade80 !important;
}
.topo-node-sub.st-down,
.st-down .topo-node-sub {
    color: #f87171 !important;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
.topo-node-sub.st-pending,
.st-pending .topo-node-sub {
    color: #78cadb !important;
}

.topo-tower-status {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.68rem;
    font-weight: 900;
    padding: 1px 7px;
    border-radius: 6px;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    margin-inline-start: 6px;
}
.topo-tower-status.up {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.45);
}
.topo-tower-status.down {
    background: rgba(239, 68, 68, 0.25);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.5);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.topo-node-hint { position: absolute; top: -9px; inset-inline-end: 8px; font-size: .58rem; font-weight: 800; padding: 0 6px; border-radius: 6px; background: #bcb5f1; color: #fff; }

/* ---- links ---- */
.topo-links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }

.topo-link-item {
    pointer-events: auto;
}
.topo-link-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 22;
    stroke-linecap: round;
    pointer-events: stroke !important;
}
.topo-link {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    transition: stroke .2s ease, stroke-width .2s ease, filter .2s ease;
    pointer-events: none;
}
.topo-link.up { stroke: #22c55e; }
.topo-link.down { stroke: #ef4444; stroke-dasharray: 6 5; }
.topo-link.warn { stroke: #f59e0b; }
.topo-link.pending { stroke: #72727c; stroke-dasharray: 3 5; }

/* Interactive Delete Hover when Unlocked */
.topo-viewport:not(.is-locked) .topo-link-hit {
    cursor: pointer !important;
}
.topo-viewport:not(.is-locked) .topo-link-item:hover .topo-link {
    stroke: #ef4444 !important;
    stroke-width: 4px !important;
    stroke-dasharray: 6 4 !important;
    filter: drop-shadow(0 0 10px rgba(239, 68, 68, 1)) !important;
    animation: topoWirePulse 0.6s linear infinite !important;
}
.topo-viewport.is-locked .topo-link-hit {
    cursor: default;
}

/* ---- Device Inspection Modal ---- */
.topo-sheet-back {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 10001 !important;
    background: rgba(0, 14, 22, .7) !important;
    backdrop-filter: blur(5px) !important;
    -webkit-backdrop-filter: blur(5px) !important;
    display: none;
    opacity: 0;
    transition: opacity .2s ease;
}
.topo-sheet-back.open {
    display: block !important;
    opacity: 1 !important;
}
.topo-sheet {
    position: fixed !important;
    z-index: 10002 !important;
    left: 50% !important;
    top: 50% !important;
    bottom: auto !important;
    right: auto !important;
    margin: 0 !important;
    transform: translate(-50%, -50%) scale(0.92) !important;
    width: min(500px, calc(100vw - 2rem)) !important;
    max-height: min(85vh, 640px) !important;
    overflow-y: auto !important;
    background: linear-gradient(180deg, #00212e, #001a26) !important;
    border: 1px solid rgba(120, 202, 219, .35) !important;
    border-radius: 20px !important;
    padding: 1.25rem 1.35rem 1.4rem !important;
    direction: rtl !important;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, .85), 0 0 25px rgba(92, 181, 198, .18) !important;
    display: none;
    opacity: 0;
    transition: transform .22s cubic-bezier(.16, 1, .3, 1), opacity .22s ease !important;
}
.topo-sheet.open {
    display: block !important;
    transform: translate(-50%, -50%) scale(1) !important;
    opacity: 1 !important;
}
.topo-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    margin-bottom: .9rem;
    padding-bottom: .6rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.topo-sheet-title {
    font-size: 1.12rem;
    font-weight: 800;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: .55rem;
    min-width: 0;
    overflow-wrap: anywhere;
}
.topo-sheet-title i {
    font-size: 1.25rem;
}
.topo-sheet-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    margin-bottom: 1rem;
}
.topo-chip {
    font-size: .75rem;
    font-weight: 800;
    padding: 4px 11px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(255, 255, 255, .05);
    color: #d3d3da;
}
.topo-chip.up { color: #34d399; border-color: rgba(16, 185, 129, .4); background: rgba(16, 185, 129, .14); }
.topo-chip.down { color: #f87171; border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .14); }
.topo-chip.ip { font-family: 'JetBrains Mono', monospace; direction: ltr; color: #9de0ee; }
.topo-sheet-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
    margin-bottom: 1.1rem;
}
.topo-sheet-actions .topo-btn {
    height: 42px;
    font-size: 0.88rem;
}
.topo-sheet-actions .topo-sheet-delete { grid-column: 1 / -1; }
.topo-sheet-actions .topo-sheet-delete:hover { background: rgba(239, 68, 68, .2); }
.topo-field {
    background: rgba(0, 33, 46, .6);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 14px;
    padding: .9rem 1rem;
}
.topo-field label {
    display: flex;
    align-items: center;
    gap: .45rem;
    font-size: .85rem;
    font-weight: 800;
    color: #e7e7ec;
    margin-bottom: .5rem;
}
.topo-field small {
    display: block;
    margin-top: .45rem;
    color: #a0a1ab;
    font-size: .75rem;
    line-height: 1.45;
}
.topo-select {
    width: 100%;
    height: 44px;
    box-sizing: border-box;
    padding: 0 .8rem;
    background: rgba(0, 14, 22, .9);
    color: #9de0ee;
    font-family: inherit;
    font-weight: 700;
    font-size: .9rem;
    border: 1px solid rgba(120, 202, 219, .45);
    border-radius: 10px;
    outline: none;
    transition: border-color .2s;
}
.topo-select:focus {
    border-color: #78cadb;
    box-shadow: 0 0 0 3px rgba(120, 202, 219, .2);
}



/* ---- small dialog ---- */
.topo-dialog-back { position: fixed; inset: 0; z-index: 10005; background: rgba(0, 14, 22, .65); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.topo-dialog { width: min(400px, 100%); background: #00212e; border: 1px solid rgba(120, 202, 219, .35); border-radius: 16px; padding: 1.1rem; direction: rtl; }
.topo-dialog h4 { margin: 0 0 .8rem; color: #f8fafc; font-size: 1rem; font-weight: 800; }
.topo-dialog input { width: 100%; box-sizing: border-box; height: 44px; margin-bottom: .9rem; font-size: .95rem; }
.topo-dialog-btns { display: flex; gap: .5rem; }
.topo-dialog-btns .topo-btn { flex: 1; height: 42px; }

/* ---- links sit between the tower frames and the devices ---- */
.topo-links { z-index: 1; }
.topo-link { stroke-width: 2.5; }
.topo-link.up { filter: drop-shadow(0 0 3px rgba(34, 197, 94, .55)); }
.topo-link.down { filter: drop-shadow(0 0 3px rgba(239, 68, 68, .55)); }

/* ---- floating zoom controls (bottom corner of the map) ---- */
.topo-zoom-float {
    position: absolute;
    left: 14px;
    bottom: 14px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 5px;
    border-radius: 14px;
    background: rgba(0, 33, 46, .88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, .1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
}
.topo-zoom-float .topo-btn { width: 40px; height: 36px; padding: 0; border-radius: 9px; }
.topo-zoom-float .topo-zoom-label { min-width: 0; font-size: .66rem; }
.dude-topology-section:has(.topo-empty) .topo-zoom-float { display: none; }
.dude-topology-section.topo-fullscreen-mode .topo-zoom-float,
.dude-topology-section:fullscreen .topo-zoom-float { left: calc(1.25rem + 14px); bottom: calc(1rem + 14px); }

/* hint sits on the opposite corner from the zoom controls */
.topo-nav-hint { left: auto; right: 14px; }

/* touch screens: bigger link handle so it can be grabbed with a finger */
@media (pointer: coarse) {
    .topo-connect-handle { width: 32px; height: 32px; bottom: -16px; font-size: 12px; }
}

/* ---- phone ---- */
@media (max-width: 759px) {
    .topo-toolbar {
        flex-wrap: nowrap;
        gap: .5rem;
        margin-bottom: .7rem;
    }
    .topo-header-badge { padding: .45rem .7rem; font-size: .8rem; white-space: nowrap; }
    .topo-header-badge span { display: none; }
    .topo-actions { flex-wrap: nowrap; gap: .4rem; overflow-x: auto; scrollbar-width: none; }
    .topo-actions::-webkit-scrollbar { display: none; }
    .topo-btn { height: 40px; padding: 0 .8rem; white-space: nowrap; }
    .topo-btn-label { display: none; }
    .topo-lock-btn { min-width: 0; }

    .topo-banner { font-size: .78rem; padding: .6rem .75rem; }

    /* same map as the PC (pan / pinch / drag); leave some page above & below it to scroll the page */
    .topo-main-layout { height: 68vh; height: 68svh; min-height: 400px; }
    .topo-main-layout.drawer-mode .topo-sidebar { max-height: none; }

    .topo-nav-hint { display: none; }
    .topo-zoom-float { left: 10px; bottom: 10px; padding: 4px; }
    .topo-zoom-float .topo-btn { width: 38px; height: 34px; }
    .dude-topology-section.topo-fullscreen-mode .topo-main-layout,
    .dude-topology-section:fullscreen .topo-main-layout { height: 100% !important; }

    /* device sheet becomes a bottom sheet */
    .topo-sheet {
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        max-height: 82vh !important;
        border-radius: 22px 22px 0 0 !important;
        transform: translateY(100%) !important;
        padding-bottom: calc(1.4rem + env(safe-area-inset-bottom)) !important;
    }
    .topo-sheet.open { transform: translateY(0) !important; }
    .topo-sheet-actions .topo-btn { height: 48px; }
}
