/* ============================================================
   Network Diagram – Node Styles & Electricity Flow Animation
   Used by NetworkDiagramView.razor (Z.Blazor.Diagrams 3.x)
   ============================================================ */

/* --- Container ------------------------------------------- */
.network-diagram-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 500px;
    display: flex;
    flex-direction: column;
}

.network-diagram-toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
}

.network-diagram-canvas {
    flex: 1;
    width: 100%;
    min-height: 450px;
    overflow: hidden;
    position: relative;
}

/* Force the library canvas to fill its flex-item parent.
   height:100% alone doesn't resolve when the parent's height
   comes from flex layout rather than an explicit property. */
.network-diagram-canvas>.diagram-canvas {
    position: absolute;
    inset: 0;
}

/* --- Network node base ----------------------------------- */
.network-node {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 2px solid;
    padding: 8px 10px;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.15s ease, transform 0.1s ease;
    text-align: center;
    overflow: visible;
    white-space: nowrap;
    min-width: 160px;
    min-height: 60px;
}

/* --- Node action bar (top-right, visible on hover) ------ */
.network-node__actions {
    position: absolute;
    top: -10px;
    right: -6px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transform: scale(0.7);
    transform-origin: top right;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 10;
}

.network-node:hover .network-node__actions,
.network-node__actions:focus-within {
    opacity: 1;
    transform: scale(1);
}

/* --- Meter indicator (Feature 020): always-visible ElectricMeter icon -------- */
/* Rendered on the owning grid-connection/asset node; color reflects meter health */
/* via MudBlazor Color, matching the BESS telemetry palette (FR-002/FR-003).     */
.network-node__meter-indicator {
    position: absolute;
    top: -10px;
    left: -8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    z-index: 9;
}

.network-node__meter-indicator .mud-icon-root {
    font-size: 1rem;
}

.network-node__action-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    background: #fff;
    color: #616161;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    line-height: 0;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.network-node__action-btn .mud-icon-root {
    font-size: 14px !important;
    width: 14px;
    height: 14px;
}

.network-node__action-btn:hover {
    background: #1976d2;
    color: #fff;
    border-color: #1976d2;
}

.network-node__action-btn--danger {
    color: #d32f2f;
}

.network-node__action-btn--danger:hover {
    background: #d32f2f;
    color: #fff;
    border-color: #d32f2f;
}

.network-node:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.network-node.selected {
    outline: 3px solid #3B82F6;
    outline-offset: 1px;
}

/* --- Node type colour schemes ---------------------------- */

/* Grid / utility root — amber */
.network-node--grid {
    background-color: #FDE68A;
    border-color: #D97706;
    color: #78350F;
}

/* Grid connection — neutral gray */
.network-node--connection {
    background-color: #E5E7EB;
    border-color: #6B7280;
    color: #1F2937;
}

/* --- Dual-EAN connection node (horizontal split: top/bottom) */
.network-node--connection-dual {
    min-width: 160px;
    flex-direction: column;
    padding: 4px 8px 6px;
}

.network-node__dual-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-bottom: 3px;
}

.network-node__ean-panes {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}

.network-node__ean-pane {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 4px;
    position: relative;
    min-width: 0;
}

.network-node__ean-divider {
    height: 1px;
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    margin: 2px 0;
}

.network-node__flow-label {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 0.68rem;
    font-weight: 600;
    margin-bottom: 1px;
    white-space: nowrap;
}

/* Make sublabel wider inside dual-EAN panes */
.network-node--connection-dual .network-node__sublabel {
    max-width: none;
    font-size: 0.62rem;
}

/* Meter totals in dual panes */
.network-node--connection-dual .network-node__meter-totals {
    gap: 4px;
    align-items: center;
}

/* --- Hidden port anchors (functional, not visual) -------- */
.port-anchor {
    width: 1px !important;
    height: 1px !important;
    background: transparent !important;
    border: none !important;
    opacity: 0 !important;
    pointer-events: none;
}

/* Grid connection — edit popover removed; uses overlay dialog */

.network-node__edit-header {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 2px;
    margin-bottom: 2px;
}

/* Production asset — green */
.network-node--production {
    background-color: #D1FAE5;
    border-color: #059669;
    color: #064E3B;
}

/* --- Production node flow panes (aux consumption ↓ / production ↑) */
.network-node__flow-panes {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}

.network-node__flow-pane {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 4px;
}

.network-node--production .network-node__meter-totals {
    gap: 4px;
    align-items: center;
}

/* Consumption asset — blue */
.network-node--consumer {
    background-color: #DBEAFE;
    border-color: #2563EB;
    color: #1E3A8A;
}

/* Battery storage asset — amber */
.network-node--bess {
    background-color: #FEF3C7;
    border-color: #D97706;
    color: #78350F;
}

/* --- Node content elements ------------------------------- */
.network-node__icon {
    font-size: 1.4rem;
    line-height: 1.2;
    margin-bottom: 4px;
}

.network-node__label {
    font-weight: 600;
    font-size: 0.78rem;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.network-node__sublabel {
    font-size: 0.68rem;
    opacity: 0.75;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.network-node__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background-color: rgba(0, 0, 0, 0.12);
    padding: 1px 6px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-top: 4px;
    white-space: nowrap;
}

.network-node__stats {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: 3px;
}

.network-node__stat {
    font-size: 0.62rem;
    font-weight: 600;
    white-space: nowrap;
    color: #2e7d32;
}

.network-node__meter-totals {
    display: flex;
    gap: 6px;
    margin-top: 3px;
    font-size: 0.62rem;
    font-weight: 600;
    white-space: nowrap;
}

.network-node__consumption {
    color: #e65100;
}

.network-node__injection {
    color: #2e7d32;
}

/* --- Live meter phase voltages (asset/connection overlay) -- */
.meter-voltage-phases {
    display: flex;
    gap: 6px;
    margin-top: 2px;
    font-size: 0.62rem;
    font-weight: 600;
    white-space: nowrap;
}

.meter-voltage-phases__phase {
    color: var(--mud-palette-text-secondary, #555);
}

/* --- Electricity flow animation on links ----------------- */
@keyframes flow-forward {
    from {
        stroke-dashoffset: 80;
    }

    to {
        stroke-dashoffset: 0;
    }
}

@keyframes flow-backward {
    from {
        stroke-dashoffset: 0;
    }

    to {
        stroke-dashoffset: 80;
    }
}

.diagram-link path {
    stroke-dasharray: 12 8;
    stroke-dashoffset: 80;
    animation: flow-forward 1.8s linear infinite;
    transition: stroke-width 0.2s ease, stroke 0.2s ease;
}

.diagram-link.flow-reverse path {
    animation: flow-backward 1.8s linear infinite;
}

/* Link thickness classes */
.diagram-link.flow-high path {
    stroke-width: 4px;
}

.diagram-link.flow-medium path {
    stroke-width: 2.5px;
}

.diagram-link.flow-low path {
    stroke-width: 1.5px;
}

/* Link colours per type */
.diagram-link.link--consumption path {
    stroke: #2563EB;
}

.diagram-link.link--production path {
    stroke: #059669;
}

/* --- Steering Group Container ----------------------------- */
.steering-group-container {
    width: 100%;
    height: 100%;
    border: 2px dashed #90A4AE;
    border-radius: 12px;
    background: rgba(144, 164, 174, 0.05);
    padding: 8px;
    box-sizing: border-box;
    overflow: hidden;
}

.steering-group-container__header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #546E7A;
    white-space: nowrap;
}

.steering-group-container__title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.steering-group-container__status {
    font-size: 10px;
    font-weight: 500;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.08);
}

/* Status variants */
.steering-group-container--active {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.06);
}

.steering-group-container--active .steering-group-container__header {
    color: #2E7D32;
}

.steering-group-container--active .steering-group-container__status {
    background: rgba(76, 175, 80, 0.15);
    color: #2E7D32;
}

.steering-group-container--pending {
    border-color: #FF9800;
    background: rgba(255, 152, 0, 0.06);
}

.steering-group-container--pending .steering-group-container__header {
    color: #E65100;
}

.steering-group-container--pending .steering-group-container__status {
    background: rgba(255, 152, 0, 0.15);
    color: #E65100;
}

.steering-group-container--failed {
    border-color: #F44336;
    background: rgba(244, 67, 54, 0.06);
}

.steering-group-container--failed .steering-group-container__header {
    color: #C62828;
}

.steering-group-container--failed .steering-group-container__status {
    background: rgba(244, 67, 54, 0.15);
    color: #C62828;
}

/* Override default group styling from Z.Blazor.Diagrams */
.diagram-group .steering-group-container {
    pointer-events: auto;
}

.diagram-link.link--connection path {
    stroke: #6B7280;
}

/* Data link (BESS → Edge device) — dotted teal, no flow animation */
.diagram-link.link--data path {
    stroke: #26a69a;
    stroke-dasharray: 4 6;
    stroke-width: 1.5px;
    animation: none;
}

/* --- Diagram legend ─────────────────────────────────────── */
.network-diagram-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 6px 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(0, 0, 0, 0.02);
    align-items: center;
}

.network-diagram-legend__item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.6);
    white-space: nowrap;
}

.network-diagram-legend__swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 2px solid;
    flex-shrink: 0;
}

.network-diagram-legend__line {
    width: 24px;
    height: 0;
    border-bottom: 2px solid;
    flex-shrink: 0;
}

.network-diagram-legend__line--dashed {
    border-bottom-style: dashed;
}