* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    background: #eef1f5;
    color: #1e293b;
}

#container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

#sidebar {
    width: 290px;
    flex-shrink: 0;
    background: #ffffff;
    border-right: 1px solid #dfe3e8;
    padding: 18px .6rem;
    z-index: 10;
    box-shadow: 1px 0 4px rgba(15, 23, 42, 0.04);
    overflow-y: auto;
}

#sidebar h3 {
    margin: 0 0 2px;
    font-size: 1.15em;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #1e293b;
}

#sidebar .subtitle {
    font-size: 0.75em;
    color: #94a3b8;
    margin: 0 0 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eef1f5;
}

#sidebar .section-label {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    color: #94a3b8;
    margin: 18px 0 8px;
}

#canvas-area {
    flex-grow: 1;
    position: relative;
    background-color: #f4f6f9;
    background-image: radial-gradient(
        rgba(100, 116, 139, 0.16) 1px,
        transparent 1px
    );
    background-size: 24px 24px;
    overflow: hidden;
    /* Schakelt de browser's eigen scroll/pinch-zoom uit zodat onze eigen
       Pointer Events-gebaseerde pan/zoom/sleep-gebaren (ook op touch) niet
       verstoord worden. */
    touch-action: none;
}

#canvas-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    transform-origin: 0 0;
}

#canvas-content.panning {
    cursor: grabbing;
}

#svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

path.connection-request {
    stroke: #2563eb;
    stroke-width: 2px;
    fill: none;
    stroke-linecap: round;
    opacity: 0.5;
}

path.connection-sync {
    stroke: #6d28d9;
    stroke-width: 1.75px;
    fill: none;
    stroke-linecap: round;
    stroke-dasharray: 6 5;
    opacity: 0.45;
}

path.connection-dead {
    stroke: #b6bcc6 !important;
    stroke-dasharray: 3 6 !important;
    opacity: 0.6 !important;
}

path.draft-connection {
    stroke: #94a3b8;
    stroke-width: 1.5px;
    stroke-dasharray: 4;
    fill: none;
}

.connection-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 16px;
    pointer-events: stroke;
    cursor: context-menu;
}

.packet {
    pointer-events: none;
}

.mode-switch {
    display: flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
    margin-bottom: 1rem;
}

.mode-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 7px 4px;
    font-size: 0.76em;
    font-weight: 600;
    color: #64748b;
    border-radius: 6px;
    cursor: pointer;
    transition:
        background 0.15s,
        color 0.15s;
}

.mode-btn:hover:not(.active) {
    color: #334155;
}

.mode-btn.active {
    background: #ffffff;
    color: #1d4ed8;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.node.locked {
    cursor: default;
}

.node.locked .port {
    cursor: default;
}

.drag-source {
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-left: 3px solid var(--accent, #3b6ea5);
    border-radius: 6px;
    cursor: grab;
    user-select: none;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition:
        box-shadow 0.15s,
        border-color 0.15s;
    touch-action: none;
}

.drag-source:hover {
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1);
}

/* Ghost-kaart die met de vinger/cursor meebeweegt tijdens het slepen van een
   nieuw component vanuit de sidebar naar het canvas. */
.drag-ghost {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 300;
    opacity: 0.85;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
    transform: rotate(-2deg);
}

.drag-source .ds-title {
    font-weight: 600;
    font-size: 0.9em;
    color: #1e293b;
}

.drag-source .ds-desc {
    font-size: 0.72em;
    color: #94a3b8;
    margin-top: 2px;
}

.drag-client {
    --accent: #38bdf8;
}
.drag-lb {
    --accent: #0284c7;
}
.drag-web {
    --accent: #1d4ed8;
}
.drag-db {
    --accent: #1e3a8a;
}

.legend {
    display: flex;
    flex-direction: column;
    gap: 7px;
    font-size: 0.74em;
    color: #64748b;
}

.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.node {
    position: absolute;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 12px 12px;
    width: 190px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
    user-select: none;
    cursor: move;
    z-index: 2;
    font-size: 13px;
    transition: box-shadow 0.2s;
    touch-action: none;
}

.node.selected {
    border-color: #2563eb;
    box-shadow:
        0 0 0 2px rgba(37, 99, 235, 0.35),
        0 2px 6px rgba(15, 23, 42, 0.08);
}

.node.outage-zone,
.node.outage-region {
    border-color: #dc2626;
    border-style: dashed;
    opacity: 0.75;
}

.node.outage-zone::after,
.node.outage-region::after {
    content: "⚡ ZONE DOWN";
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    background: #dc2626;
    color: #ffffff;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    z-index: 3;
}

.node.outage-region::after {
    content: "🌍 REGIO DOWN";
    background: #7f1d1d;
}

.node-header {
    font-weight: 600;
    text-align: center;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eef1f5;
    color: #1e293b;
}

.node-icon {
    margin-right: 4px;
}

.node-sub {
    font-size: 0.72em;
    text-align: center;
    color: #94a3b8;
    margin-bottom: 6px;
}

.node-client {
    --accent: #38bdf8;
}
.node-loadbalancer {
    --accent: #0284c7;
}
.node-webserver {
    --accent: #1d4ed8;
}
.node-database {
    --accent: #1e3a8a;
}

.node-client .port,
.node-loadbalancer .port,
.node-webserver .port,
.node-database .port {
    background: var(--accent);
}

.status-led {
    position: absolute;
    top: 9px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    z-index: 6;
}

.status-led.online {
    background: #16a34a;
    animation: ledPulse 2.4s infinite;
}

.status-led.offline {
    background: #dc2626;
}

@keyframes ledPulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

.request-fail-flash {
    box-shadow:
        0 0 0 2px rgba(220, 38, 38, 0.55),
        0 2px 6px rgba(15, 23, 42, 0.08) !important;
}

.probe-ok {
    box-shadow:
        0 0 0 2px rgba(22, 163, 74, 0.45),
        0 2px 6px rgba(15, 23, 42, 0.08) !important;
}

.probe-fail {
    box-shadow:
        0 0 0 2px rgba(220, 38, 38, 0.5),
        0 2px 6px rgba(15, 23, 42, 0.08) !important;
}

.monitor-display {
    background: #f0fdf4;
    color: #15803d;
    font-family: "Consolas", monospace;
    padding: 7px;
    text-align: center;
    border-radius: 5px;
    border: 1px solid #bbf7d0;
    margin: 8px 0 2px;
    font-weight: 600;
    font-size: 1em;
    transition: all 0.2s;
}

.monitor-display.status-503 {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.monitor-display.status-pending {
    color: #92400e;
    background: #fffbeb;
    border-color: #fde68a;
}

.hint-line {
    font-size: 0.68em;
    color: #94a3b8;
    text-align: center;
    min-height: 1.4em;
    margin-bottom: 4px;
}

.ports-container {
    display: flex;
    justify-content: space-around;
    position: absolute;
    width: 100%;
    left: 0;
}

.ports-top {
    top: -7px;
}

.ports-bottom {
    bottom: -7px;
}

.port {
    position: relative;
    width: 14px;
    height: 14px;
    border: 2px solid #f4f6f9;
    border-radius: 50%;
    cursor: crosshair;
    z-index: 5;
    transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
    touch-action: none;
}

.port::after {
    content: '';
    position: absolute;
    inset: -7px;
}

.port:hover {
    transform: scale(1.25);
}

.port.connectable {
    animation: connectablePulse 0.9s ease-in-out infinite;
    box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.28);
}

.port.connectable:hover {
    transform: scale(1.6);
    box-shadow: 0 0 0 7px rgba(37, 99, 235, 0.4);
    animation: none;
}

@keyframes connectablePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }
}

body.connecting .port:not(.connectable) {
    opacity: 0.3;
    cursor: not-allowed;
}

.port-sync {
    width: 13px;
    height: 13px;
    background: #6d28d9 !important;
    position: absolute;
    top: 50%;
}

.port-sync-left {
    left: -6px;
    transform: translateY(-50%);
}

.port-sync-right {
    right: -6px;
    transform: translateY(-50%);
}

.node-btn {
    width: 100%;
    padding: 5px;
    font-size: 0.78em;
    margin-top: 5px;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #dbe1e8;
    background: #f8fafc;
    color: #334155;
    transition: background 0.15s;
}

.node-btn:hover {
    background: #eef2f6;
}

.node-btn.btn-offline {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.node-btn.primary-btn {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
    font-weight: 600;
}

.node-btn.primary-btn:hover {
    background: #dbeafe;
}

.node-btn.ghost-btn {
    background: transparent;
    border-style: dashed;
    color: #64748b;
}

.node-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.node-btn:disabled:hover {
    background: transparent;
}

.switch {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 16px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    transition: 0.2s;
    border-radius: 18px;
}

.slider::before {
    content: "";
    position: absolute;
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
    background: white;
    transition: 0.2s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background: #16a34a;
}

input:checked + .slider::before {
    transform: translateX(14px);
}

.panel-placeholder {
    font-size: 0.75em;
    color: #94a3b8;
    line-height: 1.5;
    margin: 4px 0 0;
}

.panel-node-title {
    font-weight: 600;
    font-size: 0.9em;
    color: #1e293b;
    margin-bottom: 10px;
}

.panel-hint {
    font-size: 0.72em;
    color: #94a3b8;
    line-height: 1.5;
    margin: 8px 0 0;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.setting-label {
    display: flex;
    align-items: center;
    font-size: 0.78em;
    color: #334155;
    font-weight: 500;
}

.setting-select {
    font-size: 0.76em;
    padding: 4px 6px;
    border-radius: 5px;
    border: 1px solid #dbe1e8;
    background: #f8fafc;
    color: #334155;
    max-width: 132px;
}

.setting-block {
    margin-bottom: 14px;
}

.setting-block-label {
    display: flex;
    align-items: center;
    font-size: 0.78em;
    color: #334155;
    font-weight: 500;
    margin-bottom: 6px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.radio-group.inline {
    flex-direction: row;
    gap: 4px;
}

.radio-group.inline .radio-option {
    flex: 1;
    text-align: center;
    padding: 6px 2px;
}

.radio-group input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.radio-option {
    display: block;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #dbe1e8;
    background: #f8fafc;
    color: #334155;
    font-size: 0.76em;
    cursor: pointer;
    transition:
        background 0.15s,
        border-color 0.15s,
        color 0.15s;
}

.radio-option:hover {
    background: #eef2f6;
}

.radio-group input[type="radio"]:checked + .radio-option {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
    font-weight: 600;
}

.radio-group input[type="radio"]:focus-visible + .radio-option {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #64748b;
    font-size: 10px;
    font-style: normal;
    margin-left: 5px;
    cursor: help;
    position: relative;
    flex-shrink: 0;
}

.info-icon .tooltip-text {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.15s;
    position: absolute;
    bottom: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #f1f5f9;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.45;
    width: 190px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25);
    z-index: 50;
    text-align: left;
}

.info-icon .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1e293b;
}

@supports (position-area: right) {
    .info-icon .tooltip-text {
        position: fixed;
        position-area: right;
        position-try-fallbacks:
            flip-inline,
            flip-block,
            flip-block flip-inline;
        inset: auto;
        margin: 6px;
        transform: none;
    }

    .info-icon .tooltip-text::after {
        display: none;
    }
}

.info-icon:hover .tooltip-text,
.info-icon:focus .tooltip-text {
    visibility: visible;
    opacity: 1;
}

.role-badge {
    display: block;
    width: fit-content;
    margin: 0 auto 6px;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 0.65em;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.role-primary {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.role-replica {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-left: 3px solid #2563eb;
    color: #334155;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.8em;
    max-width: 300px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
    transition:
        opacity 0.3s,
        transform 0.3s;
}

.toast-warn {
    border-left-color: #b45309;
}
.toast-error {
    border-left-color: #b91c1c;
}

.context-menu {
    position: fixed;
    display: none;
    z-index: 200;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    padding: 4px;
    min-width: 150px;
}

.context-menu-btn {
    display: block;
    width: 100%;
    white-space: nowrap;
    padding: 7px 14px;
    background: transparent;
    border: none;
    border-radius: 5px;
    color: #b91c1c;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.context-menu-btn:hover {
    background: #fef2f2;
}
