* { box-sizing: border-box; }

:root {
    --bg: #0e141a;
    --panel: #18212b;
    --node: #202c38;
    --text: #eef4f8;
    --muted: #94a4b0;
    --ok: #2ecc71;
    --down: #e74c3c;
    --unknown: #7f8c8d;
    --network: #3498db;
    --route: #f39c12;
    --line: #54626d;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

.page {
    max-width: 1700px;
    margin: 0 auto;
    padding: 20px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    margin-bottom: 15px;
}

h1 {
    margin: 0;
    font-size: 30px;
}

.subtitle,
#lastUpdated {
    color: var(--muted);
}

.summary {
    text-align: right;
}

.legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    background: var(--panel);
    padding: 11px 14px;
    border-radius: 10px;
    margin-bottom: 18px;
}

.legend span {
    display: inline-flex;
    gap: 7px;
    align-items: center;
}

.dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
}

.dot.ok { background: var(--ok); }
.dot.down { background: var(--down); }
.dot.route { background: var(--route); }
.dot.interface { background: var(--network); }

.diagram {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.links {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 0;
}

.group {
    position: relative;
    z-index: 1;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,.06);
    background: rgba(255,255,255,.025);
}

.group-title {
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 12px;
}

.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 13px;
}

.server-card,
.node-card {
    min-height: 78px;
    background: var(--node);
    border: 2px solid var(--unknown);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    gap: 11px;
    align-items: center;
    box-shadow: 0 6px 16px rgba(0,0,0,.18);
}

.node-card.ok,
.server-card.ok { border-color: var(--ok); }

.node-card.down,
.server-card.down { border-color: var(--down); }

.badge {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: rgba(255,255,255,.08);
    font-weight: bold;
    font-size: 11px;
    flex: 0 0 auto;
}

.node-content {
    min-width: 0;
    flex: 1;
}

.node-title {
    font-weight: 700;
    margin-bottom: 4px;
}

.node-subtitle,
.node-detail {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.default-ip {
    color: var(--route);
    font-weight: 700;
}

.default-label {
    color: var(--route);
    margin-top: 3px;
    font-size: 11px;
}

.led {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--unknown);
    flex: 0 0 auto;
}

.ok .led { background: var(--ok); }
.down .led { background: var(--down); }

/* Server traffic LED. These override the normal card status LED colour. */
/* Traffic LEDs apply to servers, gateways/load balancer and WAN cards. */
.server-card .led.traffic-green,
.node-card .led.traffic-green { background: var(--ok); }

.server-card .led.traffic-amber,
.node-card .led.traffic-amber { background: var(--route); }

.server-card .led.traffic-red,
.node-card .led.traffic-red { background: var(--down); }

.bus-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bus {
    position: relative;
    min-height: 54px;
    border-radius: 10px;
    background: rgba(52,152,219,.08);
    border: 1px solid rgba(52,152,219,.45);
    display: flex;
    align-items: center;
    padding: 10px 16px;
}

.bus::after {
    content: "";
    position: absolute;
    left: 150px;
    right: 18px;
    top: 50%;
    height: 4px;
    transform: translateY(-50%);
    background: var(--network);
    border-radius: 4px;
    opacity: .8;
}

.bus.vpn::after {
    opacity: .5;
}

.bus-label {
    position: relative;
    z-index: 2;
    min-width: 125px;
    font-weight: 700;
}

.bus-meta {
    position: relative;
    z-index: 2;
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    background: var(--panel);
    padding: 3px 8px;
    border-radius: 12px;
}

.link-line {
    fill: none;
    stroke: var(--line);
    stroke-width: 3;
    opacity: .65;
}

.link-line.wan {
    stroke: var(--ok);
    stroke-width: 4;
}

.link-line.network {
    stroke: var(--network);
    stroke-width: 3;
}

.link-line.interface {
    stroke: var(--network);
    stroke-width: 2;
    opacity: .65;
}

.link-line.default_route {
    stroke: var(--ok);
    stroke-width: 4;
    opacity: .9;
    stroke-dasharray: 7 5;
}

/* A busy route follows the same red threshold as its traffic LED. */
.link-line.default_route.traffic-red,
.link-line.wan.traffic-red {
    stroke: var(--down);
    opacity: 1;
}

.link-line.default_route.traffic-red {
    stroke-dasharray: 7 5;
}


.gateway-users {
    margin-top: 4px;
    color: var(--route);
    font-size: 11px;
    font-weight: 700;
}

.gateway-user-list {
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.35;
}

.event-log {
    margin-top: 18px;
    background: var(--panel);
    padding: 14px;
    border-radius: 10px;
}

.event-log-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 9px;
}

button {
    cursor: pointer;
    padding: 8px 12px;
    border: 0;
    border-radius: 7px;
}

.event-item {
    padding: 5px 0;
    border-top: 1px solid rgba(255,255,255,.06);
    font-size: 13px;
}

@media (max-width: 750px) {
    .page { padding: 10px; }
    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }
    .summary { text-align: left; }
    .group-grid { grid-template-columns: 1fr; }
}


/* Hover path tracing */
.link-line,
.node-card,
.server-card,
.bus {
    transition: opacity .12s ease, stroke .12s ease, stroke-width .12s ease,
                border-color .12s ease, box-shadow .12s ease;
}

.link-line.trace-dim {
    opacity: .08 !important;
}

.link-line.trace-line {
    stroke: #ffffff !important;
    stroke-width: 5 !important;
    opacity: 1 !important;
    filter: drop-shadow(0 0 3px rgba(255,255,255,.65));
}

.node-card.trace-dim,
.server-card.trace-dim,
.bus.trace-dim {
    opacity: .28;
}

.node-card.trace-node,
.server-card.trace-node,
.bus.trace-node {
    opacity: 1;
    border-color: #ffffff !important;
    box-shadow: 0 0 0 1px rgba(255,255,255,.35), 0 0 12px rgba(255,255,255,.18);
}


.vpn-cards .node-card {
    min-height: 78px;
}

.vpn-cards .node-card .badge {
    width: 46px;
    height: 46px;
}


/* Active WireGuard tunnel: recent authenticated peer handshake. */
.link-line.interface.vpn-active {
    stroke: var(--ok);
    stroke-width: 4;
    stroke-dasharray: 9 6;
    opacity: 1;
}


/* Per-server RX/TX traffic row. */
.server-traffic-row {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    margin-top: 7px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,.07);
}

.server-traffic-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
    min-width: 0;
}

.traffic-mini-led {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
    background: var(--unknown);
}

.server-traffic-item.traffic-green,
.server-traffic-item.traffic-green .traffic-value,
.server-traffic-item.traffic-green .traffic-arrow {
    color: var(--ok);
    font-size:12pt;
}
.server-traffic-item.traffic-green .traffic-mini-led { background: var(--ok); }

.server-traffic-item.traffic-amber,
.server-traffic-item.traffic-amber .traffic-value,
.server-traffic-item.traffic-amber .traffic-arrow {
    color: var(--route);
    font-size:12pt;
}
.server-traffic-item.traffic-amber .traffic-mini-led { background: var(--route); }

.server-traffic-item.traffic-red,
.server-traffic-item.traffic-red .traffic-value,
.server-traffic-item.traffic-red .traffic-arrow {
    color: var(--down);
    font-size:12pt;
}
.server-traffic-item.traffic-red .traffic-mini-led { background: var(--down); }

/* Uniform server-card layout: align name, IP block and traffic row. */
.server-card {
    height: 178px;
    min-height: 178px;
    align-items: stretch;
}

.server-card .node-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.server-card .node-title {
    min-height: 18px;
    margin-bottom: 6px;
}

.server-card .node-detail,
.server-card .default-label {
    line-height: 1.35;
}

.server-card .external-ip {
    color: var(--route);
    font-weight: 700;
}

.server-card .server-traffic-row {
    margin-top: auto;
    width: 100%;
}


/* WAN traffic uses the same RX/TX display as server cards. */
.node-card .node-traffic-row {
    margin-top: 5px;
    padding-top: 4px;
}

.vpn-cards .node-card.unknown { border-color: var(--unknown); }
.vpn-cards .node-card.ok { border-color: var(--ok); }
.vpn-cards .node-card.down { border-color: var(--down); }
.vpn-peer-count { margin-top: 4px; font-weight: 700; }
.link-line.interface:not(.vpn-active) { stroke: var(--unknown); }

/* WireGuard state: running/idle green, connected orange, down red. */
.vpn-cards .node-card.connected { border-color: var(--route); }
.vpn-cards .node-card.connected .led { background: var(--route); }
.link-line.interface.vpn-running { stroke: var(--ok); stroke-width: 3; opacity: .9; }
.link-line.interface.vpn-connected { stroke: var(--route); stroke-width: 4; stroke-dasharray: 9 6; opacity: 1; }
.link-line.interface.vpn-down { stroke: var(--down); stroke-width: 3; opacity: .9; }

/* VPN LED must represent tunnel state, never throughput utilisation. */
.vpn-cards .node-card.ok .led { background: var(--ok); }
.vpn-cards .node-card.connected .led { background: var(--route); }
.vpn-cards .node-card.down .led { background: var(--down); }
.vpn-cards .node-card.unknown .led { background: var(--unknown); }
