*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: #f4f7f6;
    color: #333;
    overflow: hidden;
}

/* Full-screen canvas */
#network-canvas {
    position: fixed;
    inset: 0;
    background: white;
    cursor: default;
}

/* Sidebar — overlays the canvas */
#sidebar {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 100;
    width: 290px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

/* Collapsed: only the header row visible */
#sidebar.collapsed .sidebar-content {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
}
#sidebar.collapsed .sidebar-header {
    border-bottom: none;
}

.header-left {
    display: flex;
    align-items: center;
}

.sidebar-title {
    font-weight: bold;
    font-size: 14px;
    margin-left: 8px;
    color: #333;
}

.sidebar-tabs {
    display: flex;
    gap: 4px;
}

#toggle-sidebar-btn {
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #555;
    border-radius: 4px;
    flex-shrink: 0;
}
#toggle-sidebar-btn:hover {
    background: #f0f0f0;
}

button {
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}
button:hover { background-color: #0056b3; }

/* Specific Tab Button Overrides */
.sidebar-tabs button.tab-btn {
    padding: 0;
    width: 32px;
    height: 32px;
    background-color: transparent;
    color: #555;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}
.sidebar-tabs button.tab-btn:hover {
    background-color: #f0f0f0;
}
.sidebar-tabs button.tab-btn.active {
    background-color: #007bff;
    color: white;
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 16px 16px;
}

.tab-pane {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

select, input[type="text"], input[type="number"] {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100%;
}
.control-group {
    background: #f9f9f9;
    padding: 12px;
    border-radius: 5px;
    border: 1px solid #eee;
}

#result {
    font-size: 18px;
    font-weight: bold;
    color: #28a745;
    text-align: center;
    margin-top: 10px;
    line-height: 1.4;
}
.instructions {
    font-size: 13px;
    color: #444;
    margin: 0;
    line-height: 1.6;
}

/* Modal Styles */
#modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.custom-modal {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1000;
    width: 250px;
}
.custom-modal h3 { margin-top: 0; margin-bottom: 15px; }
.custom-modal label {
    font-size: 14px;
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
}
input[type="color"] {
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 100px;
    height: 40px;
    border: none;
    padding: 0;
    cursor: pointer;
    margin-bottom: 15px;
    border-radius: 15px;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}
input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 40px;
}

.modal-buttons { display: flex; gap: 10px; margin-top: 15px; }
.modal-buttons button { flex: 1; }
.btn-cancel { background-color: #6c757d !important; }
.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    cursor: pointer;
    color: #bbb;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-weight: normal;
    transition: color 0.15s, background 0.15s;
}
.modal-close-btn:hover {
    color: #888;
    background: #f0f0f0;
}
:root {
    --bg-color: #f4f7f6;
    --sidebar-bg: #ffffff;
    --text-color: #333333;
    --border-color: #eeeeee;
    --input-bg: #ffffff;
    --control-bg: #f9f9f9;
}

body.dark-mode {
    --bg-color: #1a1a1a;
    --sidebar-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --border-color: #444444;
    --input-bg: #3d3d3d;
    --control-bg: #363636;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-color); /* Updated */
    color: var(--text-color);    /* Updated */
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

#network-canvas {
    position: fixed;
    inset: 0;
    background: var(--bg-color); /* Updated */
}

#sidebar {
    background: var(--sidebar-bg); /* Updated */
    color: var(--text-color);      /* Updated */
    /* ... existing properties ... */
}

.sidebar-header {
    border-bottom: 1px solid var(--border-color); /* Updated */
}

.sidebar-title { color: var(--text-color); }

.control-group {
    background: var(--control-bg);   /* Updated */
    border: 1px solid var(--border-color); /* Updated */
}

select, input[type="text"], input[type="number"] {
    background: var(--input-bg);    /* Updated */
    color: var(--text-color);       /* Updated */
    border: 1px solid var(--border-color);
}

.instructions { color: var(--text-color); opacity: 0.8; }

.custom-modal {
    background: var(--sidebar-bg); /* Updated */
    color: var(--text-color);      /* Updated */
}

/*------------------*/
/* Dark Mode Switch */
/*------------------*/

/* Modern Toggle Switch Container */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.theme-switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 44px;
}

.theme-switch input {
    display: none; /* Hide original checkbox */
}

/* The Slider Track */
.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .15s;
    border-radius: 34px;
}

/* The Sliding Knob */
.slider:before {
    background-color: #fff;
    bottom: 3px;
    content: "";
    height: 18px;
    left: 4px;
    position: absolute;
    transition: .15s;
    width: 18px;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Active State Colors */
input:checked + .slider {
    background-color: #007bff;
}

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

/* Dark Mode Specific Tweaks for the Slider */
body.dark-mode .slider {
    background-color: #555;
}