﻿*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Segoe UI',Tahoma,Geneva,Verdana,sans-serif;background:#0a1929;color:#e0e0e0;overflow:hidden}
#app{display:flex;flex-direction:column;height:100vh}
#topbar{background:#0e1e30;border-bottom:1px solid #1a3a5c;padding:12px 16px;display:flex;justify-content:space-between;align-items:center}
.brand{font-size:18px;font-weight:600;color:#00e5ff}
.topbar-actions{display:flex;gap:8px;align-items:center}
.topbar-actions button{background:#132f4c;border:1px solid #1a3a5c;color:#00e5ff;padding:8px 16px;border-radius:6px;cursor:pointer;font-size:13px;transition:all 0.2s}
.topbar-actions button:hover{background:#1a3a5c;border-color:#00e5ff}
.separator{width:1px;height:20px;background:#1a3a5c;margin:0 4px}
#main-container{display:flex;flex:1;overflow:hidden}

/* LEFT: Channel Detail Panel */
#channel-detail-panel{width:280px;background:#0e1e30;border-right:1px solid #1a3a5c;padding:16px;overflow-y:auto}
#channel-detail-panel.empty #channel-detail-empty{display:block}
#channel-detail-empty .hint{color:#546e7a;font-size:13px;text-align:center;margin-top:40px;font-style:italic}
.detail-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.detail-header h3{color:#00e5ff;font-size:16px}
.btn-close{background:none;border:none;color:#90a4ae;font-size:22px;cursor:pointer;line-height:1}
.btn-close:hover{color:#ff5252}
.detail-type{font-size:12px;color:#90a4ae;text-transform:uppercase;letter-spacing:1px;margin-bottom:12px}
#channel-detail-content h4{font-size:12px;color:#546e7a;text-transform:uppercase;letter-spacing:1px;margin-top:16px;margin-bottom:8px;border-top:1px solid #1a3a5c;padding-top:12px}
#detailDeviceList{display:flex;flex-direction:column;gap:6px;margin-bottom:16px}
.detail-device-item{background:#132f4c;border:1px solid #1a3a5c;border-radius:4px;padding:8px 10px;font-size:12px;display:flex;justify-content:space-between;align-items:center}
.detail-device-item .dev-name{color:#e0e0e0;font-weight:500}
.detail-device-item .dev-type{color:#546e7a;font-size:11px}
.detail-device-item .dev-remove{background:none;border:none;color:#ff5252;cursor:pointer;font-size:14px}
.btn-danger{background:#ff5252;border:none;color:#fff;padding:8px 16px;border-radius:6px;cursor:pointer;width:100%;font-size:13px;margin-top:12px}
.btn-danger:hover{background:#ff1744}

/* MIDDLE: Map Canvas */
#map-canvas{flex:1;background:#0a1929;position:relative;overflow:hidden;touch-action:none}
#map-surface{position:absolute;top:0;left:0;width:5000px;height:5000px;background-image:radial-gradient(circle,#132f4c 1px,transparent 1px);background-size:30px 30px;transform-origin:0 0;will-change:transform}
.map-hint{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);color:#546e7a;text-align:center;font-size:14px;pointer-events:none;z-index:2}
.map-hint p{margin-bottom:8px}
#zoom-controls{position:absolute;bottom:16px;right:16px;display:flex;flex-direction:column;gap:4px;z-index:10}
#zoom-controls button{background:#132f4c;border:1px solid #1a3a5c;color:#00e5ff;width:36px;height:36px;border-radius:6px;cursor:pointer;font-size:16px;font-weight:bold}
#zoom-controls button:hover{background:#1a3a5c;border-color:#00e5ff}
#zoom-level{background:#0e1e30;border:1px solid #1a3a5c;color:#90a4ae;font-size:11px;text-align:center;padding:4px;border-radius:4px;min-width:36px}

/* Channel Card on Map */
.channel-card{position:absolute;background:#132f4c;border:2px solid #1a3a5c;border-radius:8px;padding:12px;min-width:180px;cursor:move;user-select:none;transition:border-color 0.2s,box-shadow 0.2s;box-shadow:0 2px 8px rgba(0,0,0,0.3)}
.channel-card.selected{box-shadow:0 0 0 3px #00e5ff,0 4px 12px rgba(0,229,255,0.3)}
.channel-card.drag-over{border-color:#00e5ff;background:#1a3a5c}
.channel-card.drag-invalid{border-color:#ff5252}
.channel-card[data-type="partyline"]{border-top:4px solid #00e5ff}
.channel-card[data-type="pointtopoint"]{border-top:4px solid #e040fb}
.channel-card[data-type="4wire"]{border-top:4px solid #ffc107}
.channel-card[data-type="2wire"]{border-top:4px solid #ff9800}
.channel-card[data-type="radio"]{border-top:4px solid #ff5252}
.channel-card[data-type="dante"]{border-top:4px solid #76ff03}
.channel-card[data-type="madi"]{border-top:4px solid #29b6f6}
.channel-card .ch-name{font-weight:600;font-size:14px;color:#e0e0e0;margin-bottom:4px}
.channel-card .ch-type{font-size:11px;color:#90a4ae;text-transform:uppercase;margin-bottom:8px}
.channel-card .ch-count{font-size:11px;color:#00e5ff;background:#0e1e30;padding:4px 8px;border-radius:4px;display:inline-block;margin-top:4px}
.channel-card .ch-warning{font-size:10px;color:#ff9800;margin-top:6px}

/* RIGHT: Devices Panel */
#devices-panel{width:280px;background:#0e1e30;border-left:1px solid #1a3a5c;padding:16px;overflow-y:auto}
#devices-panel h3{color:#00e5ff;font-size:14px;margin-bottom:12px;text-transform:uppercase;letter-spacing:1px}
#devices-list{display:flex;flex-direction:column;gap:10px}
.device-card{background:#132f4c;border:2px solid #1a3a5c;border-radius:8px;padding:10px;cursor:grab;transition:all 0.2s}
.device-card:hover{border-color:#00e5ff}
.device-card:active{cursor:grabbing}
.device-card.dragging{opacity:0.5}
.device-card[data-type="panel"]{border-left:4px solid #00e5ff}
.device-card[data-type="beltpack"]{border-left:4px solid #76ff03}
.device-card[data-type="masterstation"]{border-left:4px solid #ff6e40}
.device-card[data-type="interface"]{border-left:4px solid #ffc107}
.device-card[data-type="radio"]{border-left:4px solid #ff5252}
.device-card[data-type="other"]{border-left:4px solid #90a4ae}
.device-card .dev-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px}
.device-card .dev-name{font-weight:600;font-size:13px;color:#e0e0e0}
.device-card .dev-type-badge{font-size:10px;color:#90a4ae;background:#0e1e30;padding:2px 6px;border-radius:3px;text-transform:capitalize}
.device-card .dev-slots{font-size:11px;color:#90a4ae}
.device-card .dev-slot-bar{height:3px;background:#0e1e30;border-radius:2px;overflow:hidden;margin-top:4px}
.device-card .dev-slot-fill{height:100%;background:#00e5ff;transition:width 0.3s}
.device-card .dev-slot-fill.full{background:#ff5252}
.device-card .dev-channels{display:flex;flex-wrap:wrap;gap:4px;margin-top:6px}
.device-card .dev-chip{font-size:10px;padding:2px 6px;border-radius:3px;background:#0e1e30;color:#00e5ff}
.device-card .dev-actions{display:flex;gap:4px;margin-top:6px}
.device-card .dev-add-slot,.device-card .dev-delete{font-size:10px;background:none;border:1px dashed #1a3a5c;color:#00e5ff;padding:3px 6px;border-radius:3px;cursor:pointer;flex:1}
.device-card .dev-add-slot:hover{border-color:#00e5ff;background:#0e1e30}
.device-card .dev-delete{color:#ff5252;border-color:#1a3a5c}
.device-card .dev-delete:hover{border-color:#ff5252;background:#0e1e30}

/* Modal */
.modal-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.7);display:flex;justify-content:center;align-items:center;z-index:1000}
.modal{background:#0e1e30;border:1px solid #1a3a5c;border-radius:8px;padding:24px;min-width:400px;max-width:500px}
.modal h3{color:#00e5ff;margin-bottom:16px;font-size:16px}
.modal label{display:block;margin-bottom:12px;font-size:13px;color:#cfd8dc}
.modal input,.modal select{width:100%;background:#132f4c;border:1px solid #1a3a5c;color:#e0e0e0;padding:8px 12px;border-radius:4px;font-size:13px;margin-top:4px}
.modal input:focus,.modal select:focus{outline:none;border-color:#00e5ff}
.modal-actions{display:flex;gap:8px;margin-top:20px;justify-content:flex-end}
.btn-cancel{background:#1a3a5c;border:1px solid #1a3a5c;color:#90a4ae;padding:8px 16px;border-radius:6px;cursor:pointer}
.btn-cancel:hover{background:#132f4c}
.btn-apply{background:#00e5ff;border:none;color:#0a1929;padding:8px 16px;border-radius:6px;cursor:pointer;font-weight:600}
.btn-apply:hover{background:#00d4e6}

::-webkit-scrollbar{width:8px;height:8px}
::-webkit-scrollbar-track{background:#0a1929}
::-webkit-scrollbar-thumb{background:#1a3a5c;border-radius:4px}
::-webkit-scrollbar-thumb:hover{background:#2a4a6c}

.toast{position:fixed;bottom:20px;right:20px;background:#ff5252;color:#fff;padding:12px 20px;border-radius:6px;font-size:13px;z-index:2000;animation:slideIn 0.3s ease-out}
.toast.success{background:#76ff03;color:#0a1929}
@keyframes slideIn{from{transform:translateX(400px);opacity:0}to{transform:translateX(0);opacity:1}}

/* MAP VIEW & BRAND */
.powered-by{font-size:11px;color:#546e7a;font-weight:400;margin-left:6px;letter-spacing:0.3px}
.btn-view-toggle{background:#00e5ff !important;color:#0a1929 !important;border-color:#00e5ff !important;font-weight:600}
.btn-view-toggle:hover{background:#00d4e6 !important}
.btn-view-toggle.active{background:#e040fb !important;border-color:#e040fb !important;color:#fff !important}
body.mapview-active .setup-only-actions{display:none}
[hidden]{display:none !important}
#map-view{flex:1;position:relative;overflow:hidden;display:flex}
#map-view-canvas{flex:1;position:relative;background:#0a1929;overflow:hidden;touch-action:none;cursor:grab}
#map-view-canvas:active{cursor:grabbing}
#map-view-surface{position:absolute;top:0;left:0;width:5000px;height:5000px;transform-origin:0 0;will-change:transform}
#map-nodes{position:absolute;top:0;left:0;width:5000px;height:5000px}
#map-channels-bar{display:none}
#map-lines{position:absolute;top:0;left:0;width:5000px;height:5000px;pointer-events:none;z-index:2;overflow:visible}
#map-devices-area{display:none}
.map-view-hint{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);color:#546e7a;font-size:14px;font-style:italic;pointer-events:none;z-index:10}
#map-view-zoom-controls{position:absolute;bottom:16px;right:16px;display:flex;flex-direction:column;gap:4px;z-index:20}
#map-view-zoom-controls button{background:#132f4c;border:1px solid #1a3a5c;color:#00e5ff;width:36px;height:36px;border-radius:6px;cursor:pointer;font-size:16px;font-weight:bold}
#map-view-zoom-controls button:hover{background:#1a3a5c;border-color:#00e5ff}
#mv-zoom-level{background:#0e1e30;border:1px solid #1a3a5c;color:#90a4ae;font-size:11px;text-align:center;padding:4px;border-radius:4px;min-width:36px}
.map-channel-node{position:absolute;background:#0e1e30;border:2px solid #00e5ff;border-radius:50px;padding:10px 18px;cursor:move;user-select:none;transition:box-shadow 0.2s,transform 0.1s;font-size:12px;z-index:3;box-shadow:0 4px 12px rgba(0,0,0,0.5);text-align:center;min-width:120px}
.map-channel-node:hover{box-shadow:0 0 0 2px #00e5ff,0 4px 16px rgba(0,229,255,0.3)}
.map-channel-node.selected{box-shadow:0 0 0 3px #00e5ff,0 4px 16px rgba(0,229,255,0.5);background:#1a3a5c}
.map-channel-node.dragging{opacity:0.8;z-index:6}
.map-channel-node::before{content:"\01F517";display:block;font-size:14px;margin-bottom:2px;opacity:0.7}
.map-channel-node[data-type="partyline"]{border-color:#00e5ff}
.map-channel-node[data-type="pointtopoint"]{border-color:#e040fb}
.map-channel-node[data-type="4wire"]{border-color:#ffc107}
.map-channel-node[data-type="2wire"]{border-color:#ff9800}
.map-channel-node[data-type="radio"]{border-color:#ff5252}
.map-channel-node[data-type="dante"]{border-color:#76ff03}
.map-channel-node[data-type="madi"]{border-color:#29b6f6}
.map-channel-node .mc-name{font-weight:700;color:#e0e0e0;margin-bottom:2px;letter-spacing:0.5px}
.map-channel-node .mc-meta{font-size:9px;color:#90a4ae;text-transform:uppercase;letter-spacing:1px}
.map-device-node{position:absolute;background:#132f4c;border:2px solid #1a3a5c;border-radius:8px;padding:8px 10px;min-width:110px;cursor:move;user-select:none;font-size:11px;z-index:3;transition:border-color 0.2s}
.map-device-node:hover{border-color:#00e5ff}
.map-device-node.dragging{opacity:0.7;z-index:4}
.map-device-node[data-type="panel"]{border-left:4px solid #00e5ff}
.map-device-node[data-type="beltpack"]{border-left:4px solid #76ff03}
.map-device-node[data-type="masterstation"]{border-left:4px solid #ff6e40}
.map-device-node[data-type="interface"]{border-left:4px solid #ffc107}
.map-device-node[data-type="radio"]{border-left:4px solid #ff5252}
.map-device-node[data-type="other"]{border-left:4px solid #90a4ae}
.map-device-node .md-name{font-weight:600;color:#e0e0e0}
.map-device-node .md-type{font-size:9px;color:#90a4ae;text-transform:uppercase;margin-top:2px}
.map-line{stroke:#00e5ff;stroke-width:2;fill:none;opacity:0.8}
.map-line.oneway{stroke-dasharray:6 4;stroke:#e040fb}

.detail-notes{background:#0a1929;border-left:3px solid #00e5ff;padding:8px 10px;margin-bottom:12px;font-size:12px;color:#cfd8dc;font-style:italic;border-radius:0 4px 4px 0;white-space:pre-wrap}
.dev-notes{font-size:11px;color:#90a4ae;font-style:italic;margin:4px 0 6px 0;padding:4px 6px;background:#0a1929;border-left:2px solid #00e5ff;border-radius:0 3px 3px 0}
.dev-note-line{font-size:10px;color:#90a4ae;font-style:italic;margin-top:3px}

.qty-control{display:flex;align-items:center;gap:6px;margin-top:4px}
.qty-btn{background:#132f4c;border:1px solid #1a3a5c;color:#00e5ff;width:32px;height:32px;border-radius:4px;cursor:pointer;font-size:16px;font-weight:bold}
.qty-btn:hover{background:#1a3a5c;border-color:#00e5ff}
.qty-control input{flex:1;text-align:center}
.dev-name-edit{background:#0a1929;border:1px solid #00e5ff;color:#e0e0e0;padding:2px 6px;border-radius:3px;font-size:13px;font-weight:600;width:100%;outline:none}
.dev-name{cursor:text}

/* Channel legend in topbar */
.channel-legend{display:flex;gap:14px;flex-wrap:wrap;justify-content:center;align-items:center;flex:1;padding:0 20px}
.legend-item{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:#90a4ae;text-transform:uppercase;letter-spacing:0.5px;white-space:nowrap}
.legend-swatch{display:inline-block;width:22px;height:3px;border-radius:2px}
.legend-item[data-type="partyline"] .legend-swatch{background:#00e5ff}
.legend-item[data-type="pointtopoint"] .legend-swatch{background:#e040fb;background-image:linear-gradient(to right,#e040fb 50%,transparent 50%);background-size:6px 3px;background-repeat:repeat-x}
.legend-item[data-type="4wire"] .legend-swatch{background:#ffc107}
.legend-item[data-type="2wire"] .legend-swatch{background:#ff9800}
.legend-item[data-type="radio"] .legend-swatch{background:#ff5252}
.legend-item[data-type="dante"] .legend-swatch{background:#76ff03}
.legend-item[data-type="madi"] .legend-swatch{background:#29b6f6}
body:not(.mapview-active) .channel-legend{display:none}

/* Per-channel-type line colors in Map View */
.map-line{stroke:#00e5ff}
.map-line.ch-partyline{stroke:#00e5ff}
.map-line.ch-pointtopoint{stroke:#e040fb}
.map-line.ch-4wire{stroke:#ffc107}
.map-line.ch-2wire{stroke:#ff9800}
.map-line.ch-radio{stroke:#ff5252}
.map-line.ch-dante{stroke:#76ff03}
.map-line.ch-madi{stroke:#29b6f6}

.detail-header h3{cursor:text}
.detail-name-edit{background:#0a1929;border:1px solid #00e5ff;color:#00e5ff;padding:2px 6px;border-radius:3px;font-size:16px;font-weight:600;outline:none;width:calc(100% - 30px)}

/* Interfaces panel (right side, after devices) */
#interfaces-panel{width:260px;background:#0e1e30;border-left:1px solid #1a3a5c;padding:16px;overflow-y:auto}
#interfaces-panel h3{color:#ffc107;font-size:14px;margin-bottom:12px;text-transform:uppercase;letter-spacing:1px}
#interfaces-list{display:flex;flex-direction:column;gap:10px}
.interface-card{background:#132f4c;border:2px solid #1a3a5c;border-radius:8px;padding:10px;cursor:grab;transition:all 0.2s}
.interface-card:hover{border-color:#ffc107}
.interface-card:active{cursor:grabbing}
.interface-card.dragging{opacity:0.5}
.interface-card[data-type="4wire"]{border-left:4px solid #ffc107}
.interface-card[data-type="2wire"]{border-left:4px solid #ff9800}
.interface-card[data-type="dante"]{border-left:4px solid #76ff03}
.interface-card[data-type="madi"]{border-left:4px solid #29b6f6}
.interface-card .if-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px}
.interface-card .if-name{font-weight:600;font-size:13px;color:#e0e0e0;cursor:text}
.interface-card .if-type-badge{font-size:10px;color:#90a4ae;background:#0e1e30;padding:2px 6px;border-radius:3px;text-transform:uppercase}
.interface-card .if-notes{font-size:11px;color:#90a4ae;font-style:italic;margin:4px 0 6px 0;padding:4px 6px;background:#0a1929;border-left:2px solid #ffc107;border-radius:0 3px 3px 0}
.interface-card .if-channels{display:flex;flex-wrap:wrap;gap:4px;margin-top:6px}
.interface-card .if-chip{font-size:10px;padding:2px 6px;border-radius:3px;background:#0e1e30;color:#ffc107}
.interface-card .if-actions{display:flex;gap:4px;margin-top:6px}
.interface-card .if-delete{font-size:10px;background:none;border:1px dashed #1a3a5c;color:#ff5252;padding:3px 6px;border-radius:3px;cursor:pointer;flex:1}
.interface-card .if-delete:hover{border-color:#ff5252;background:#0e1e30}
.if-name-edit{background:#0a1929;border:1px solid #ffc107;color:#e0e0e0;padding:2px 6px;border-radius:3px;font-size:13px;font-weight:600;width:100%;outline:none}

/* Interface node on map view */
.map-interface-node{position:absolute;background:#132f4c;border:2px solid #1a3a5c;border-radius:4px;padding:8px 10px;min-width:110px;cursor:move;user-select:none;font-size:11px;z-index:3;transition:border-color 0.2s;clip-path:polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%)}
.map-interface-node:hover{border-color:#ffc107}
.map-interface-node.dragging{opacity:0.7;z-index:4}
.map-interface-node[data-type="4wire"]{border-left:4px solid #ffc107}
.map-interface-node[data-type="2wire"]{border-left:4px solid #ff9800}
.map-interface-node[data-type="dante"]{border-left:4px solid #76ff03}
.map-interface-node[data-type="madi"]{border-left:4px solid #29b6f6}
.map-interface-node .mi-name{font-weight:600;color:#e0e0e0}
.map-interface-node .mi-type{font-size:9px;color:#90a4ae;text-transform:uppercase;margin-top:2px}

/* Legend click state */
.legend-item{cursor:pointer;padding:4px 8px;border-radius:4px;transition:background 0.15s,color 0.15s}
.legend-item:hover{background:#132f4c;color:#e0e0e0}
.legend-item.active{background:#132f4c;color:#e0e0e0;box-shadow:0 0 0 1px currentColor inset}

.map-line.if-4wire{stroke:#ffc107}
.map-line.if-2wire{stroke:#ff9800}
.map-line.if-dante{stroke:#76ff03}
.map-line.if-madi{stroke:#29b6f6}

.brand{display:flex;align-items:center;gap:8px}
.brand-logo{width:26px;height:26px;object-fit:contain;display:block}

.panel-header{display:flex;align-items:center;gap:8px;margin-bottom:12px}
.panel-header h3{flex:0 0 auto;margin:0}
.panel-search{flex:1;background:#0a1929;border:1px solid #1a3a5c;color:#e0e0e0;padding:4px 8px;border-radius:4px;font-size:11px;outline:none;min-width:0}
.panel-search:focus{border-color:#00e5ff}
.panel-search::placeholder{color:#546e7a}
