body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #f4f4ff;
    transition: background-color 0.3s, color 0.3s;
}

/* Dark mode support */
body.dark-mode {
    background: #E5E5E5;
    color: #e0e0e0;
}

header {
    background: linear-gradient(135deg, #7A4FFF, #4F8BFF);
    color: white;
    padding: 30px;
    text-align: center;
}

.subtitle {
    margin-top: 5px;
    opacity: 0.9;
}

#toolbar {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: #ffffff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    align-items: center;
    flex-wrap: wrap;
}

body.dark-mode #toolbar {
    background: #3A3A3A;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.device-btn, #connectModeBtn, #clearBtn, #saveBtn, #loadBtn, #exportBtn, #importBtn, #darkModeBtn, #helpBtn {
    padding: 8px 12px;
    border: none;
    background: #7A4FFF;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.device-btn:hover, #connectModeBtn:hover, #clearBtn:hover, #saveBtn:hover, #loadBtn:hover, #exportBtn:hover, #importBtn:hover, #darkModeBtn:hover, #helpBtn:hover {
    background: #5f3bd9;
}

#connectModeBtn.active {
    background: #2b6cff;
}

#canvas {
    width: 100%;
    height: calc(100vh - 160px);
    background: #e9e9ff;
    position: relative;
    overflow: hidden;
    transition: background-color 0.3s;
}

body.dark-mode #canvas {
    background: #E5E5E5;
}

.device {
    width: 80px;
    height: 80px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    font-size: 30px;
    user-select: none;
    touch-action: none;
    z-index: 10;
    transition: outline 0.2s, box-shadow 0.2s, background-color 0.2s;
}

body.dark-mode .device {
    background: #3A3A3A;
    color: #e0e0e0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.device.selected {
    outline: 4px solid rgba(43,108,255,0.25);
    box-shadow: 0 6px 14px rgba(43,108,255,0.15);
}

/* Highlight active element for learning mode */
.highlight-active {
    animation: highlight-pulse 1.5s infinite;
}

@keyframes highlight-pulse {
    0%, 100% {
        outline: 4px solid rgba(255, 193, 7, 0.5);
        box-shadow: 0 0 15px rgba(255, 193, 7, 0.4);
    }
    50% {
        outline: 4px solid rgba(255, 193, 7, 0.8);
        box-shadow: 0 0 25px rgba(255, 193, 7, 0.6);
    }
}

/* SVG overlay for cables */
#canvas svg {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

svg line {
    stroke-linecap: round;
    transition: stroke 0.3s;
}

svg text {
    font-family: Arial, sans-serif;
    font-size: 12px;
    fill: #10305a;
    user-select: none;
    pointer-events: none;
    transition: fill 0.3s;
}

body.dark-mode svg text {
    fill: #b0c4ff;
}

.cable {
    position: absolute;
    background: #4F8BFF;
    height: 4px;
    transform-origin: 0 0;
}

/* Device internal name label */
.device .dev-name {
    position: absolute;
    bottom: 6px;
    left: 8px;
    font-size: 12px;
    color: #10305a;
    font-weight: 600;
    pointer-events: none;
}

body.dark-mode .device .dev-name {
    color: #b0c4ff;
}

/* Status color outlines */
.device.status-green {
    box-shadow: 0 6px 14px rgba(40,167,69,0.12);
    border: 3px solid #28a745;
}

.device.status-yellow {
    box-shadow: 0 6px 14px rgba(240,173,78,0.12);
    border: 3px solid #f0ad4e;
}

.device.status-red {
    box-shadow: 0 6px 14px rgba(220,53,69,0.12);
    border: 3px solid #dc3545;
}

/* Port status indicators (inline in config panel) */
.port-status {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    transition: background-color 0.2s;
}

.port-status.up {
    background: #28a745;
    box-shadow: 0 0 6px rgba(40, 167, 69, 0.5);
}

.port-status.down {
    background: #dc3545;
    box-shadow: 0 0 6px rgba(220, 53, 69, 0.5);
}

.port-status.disabled {
    background: #999;
    box-shadow: 0 0 6px rgba(153, 153, 153, 0.3);
}

/* Port and connection labels (SVG text) */
.port-label {
    font-size: 12px;
    fill: #222;
    pointer-events: none;
    font-weight: 600;
}

body.dark-mode .port-label {
    fill: #e0e0e0;
}

.conn-label {
    font-size: 12px;
    fill: #2b6cff;
    pointer-events: none;
}

body.dark-mode .conn-label {
    fill: #6fa8ff;
}

/* Device configuration panel */
#configPanel {
    position: absolute;
    right: 16px;
    top: 100px;
    width: 360px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 12px;
    z-index: 50;
    font-family: Arial, sans-serif;
    font-size: 13px;
    max-height: calc(100vh - 130px);
    overflow-y: auto;
    display: none;
}

body.dark-mode #configPanel {
    background: #3A3A3A;
    color: #e0e0e0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

#configPanel > div:first-child {
    font-weight: 700;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

body.dark-mode #configPanel > div:first-child {
    border-bottom-color: #444;
}

#configPanel label {
    display: block;
    margin: 10px 0 4px 0;
    font-weight: 600;
    color: #333;
}

body.dark-mode #configPanel label {
    color: #b0c4ff;
}

#configPanel input[type="text"],
#configPanel input[type="number"],
#configPanel input[type="password"],
#configPanel select {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 8px;
    background: white;
    color: #333;
}

body.dark-mode #configPanel input,
body.dark-mode #configPanel select {
    background: #E5E5E5;
    color: #e0e0e0;
    border-color: #444;
}

#configPanel button {
    padding: 6px 12px;
    margin: 4px 4px 4px 0;
    border: none;
    background: #7A4FFF;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

#configPanel button:hover {
    background: #5f3bd9;
}

/* CLI Terminal area */
#cliOutput {
    background: #3A3A3A;
    color: #b9f;
    padding: 8px;
    height: 160px;
    overflow-y: auto;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

body.dark-mode #cliOutput {
    background: #3A3A3A;
    color: #9f9;
}

#cliInput {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    margin-top: 6px;
    background: white;
    color: #333;
}

body.dark-mode #cliInput {
    background: #E5E5E5;
    color: #e0e0e0;
    border-color: #444;
}

/* Port configuration table */
#configPanel .port-row,
#configPanel .iface-row,
#configPanel .route-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px;
    background: #f9f9f9;
    border-radius: 4px;
}

body.dark-mode #configPanel .port-row,
body.dark-mode #configPanel .iface-row,
body.dark-mode #configPanel .route-row {
    background: #E5E5E5;
}

#configPanel .port-row input,
#configPanel .port-row select,
#configPanel .iface-row input,
#configPanel .iface-row select,
#configPanel .route-row input,
#configPanel .route-row select {
    flex: 1;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
}

body.dark-mode #configPanel .port-row input,
body.dark-mode #configPanel .port-row select,
body.dark-mode #configPanel .iface-row input,
body.dark-mode #configPanel .iface-row select,
body.dark-mode #configPanel .route-row input,
body.dark-mode #configPanel .route-row select {
    background: #3A3A3A;
    color: #e0e0e0;
    border-color: #444;
}

/* Cheat bubble / Learning assistant */
#cheatBubble {
    position: fixed;
    left: 16px;
    bottom: 16px;
    width: 320px;
    background: #fff8e1;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 60;
    font-family: Arial, sans-serif;
    font-size: 13px;
    max-height: 70vh;
    overflow-y: auto;
}

body.dark-mode #cheatBubble {
    background: #3A3A3A;
    color: #e0e0e0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

#cheatBubble div:first-child {
    font-weight: 700;
    color: #333;
    margin-bottom: 8px;
}

body.dark-mode #cheatBubble div:first-child {
    color: #ffc107;
}

#cheatBubble > div:nth-child(2) {
    margin: 8px 0;
    font-weight: 600;
    color: #1a5490;
}

body.dark-mode #cheatBubble > div:nth-child(2) {
    color: #6fa8ff;
}

#cheatBubble pre {
    background: #fff;
    color: #0b1220;
    padding: 8px;
    border-radius: 6px;
    font-size: 11px;
    max-height: 180px;
    overflow: auto;
    margin: 8px 0;
    font-family: 'Courier New', monospace;
    line-height: 1.3;
}

body.dark-mode #cheatBubble pre {
    background: #3A3A3A;
    color: #9f9;
}

#cheatBubble div.hint {
    font-size: 13px;
    color: #334;
    margin-bottom: 8px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.6);
    border-left: 3px solid #ffc107;
    border-radius: 3px;
}

body.dark-mode #cheatBubble div.hint {
    background: rgba(255, 193, 7, 0.1);
    color: #ffc107;
    border-left-color: #ffc107;
}

#cheatBubble button {
    padding: 6px 10px;
    margin: 4px 4px 4px 0;
    border: 1px solid #ccc;
    background: white;
    color: #333;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

body.dark-mode #cheatBubble button {
    background: #3A3A3A;
    color: #e0e0e0;
    border-color: #444;
}

#cheatBubble button:hover {
    background: #f0f0f0;
}

body.dark-mode #cheatBubble button:hover {
    background: #E5E5E5;
}

/* Scenario progress indicator */
.scenario-progress {
    width: 100%;
    height: 8px;
    background: #ddd;
    border-radius: 4px;
    margin: 8px 0;
    overflow: hidden;
}

body.dark-mode .scenario-progress {
    background: #444;
}

.scenario-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.3s;
}

/* Ping trace animation */
.ping-trace-active {
    animation: ping-trace-pulse 0.8s ease-out;
}

@keyframes ping-trace-pulse {
    0% {
        outline: 4px solid rgba(76, 175, 80, 0.8);
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
    }
    100% {
        outline: 4px solid rgba(76, 175, 80, 0.2);
        box-shadow: 0 0 0px rgba(76, 175, 80, 0);
    }
}

/* Autocomplete popup for CLI */
.autocomplete-popup {
    position: absolute;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 1000;
    max-height: 150px;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 0;
}

body.dark-mode .autocomplete-popup {
    background: #3A3A3A;
    border-color: #444;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.autocomplete-popup li {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.autocomplete-popup li:hover,
.autocomplete-popup li.active {
    background: #e0e0ff;
}

body.dark-mode .autocomplete-popup li:hover,
body.dark-mode .autocomplete-popup li.active {
    background: #E5E5E5;
}

/* Modal dialogs */
.modal-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

body.dark-mode .modal-box {
    background: #3A3A3A;
    color: #e0e0e0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.modal-box h2 {
    margin-top: 0;
    color: #333;
}

body.dark-mode .modal-box h2 {
    color: #6fa8ff;
}

.modal-box .form-group {
    margin-bottom: 12px;
}

.modal-box label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    color: #333;
}

body.dark-mode .modal-box label {
    color: #b0c4ff;
}

.modal-box input,
.modal-box select {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

body.dark-mode .modal-box input,
body.dark-mode .modal-box select {
    background: #E5E5E5;
    color: #e0e0e0;
    border-color: #444;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.modal-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

.modal-actions button.primary {
    background: #7A4FFF;
    color: white;
}

.modal-actions button.primary:hover {
    background: #5f3bd9;
}

.modal-actions button.secondary {
    background: #ddd;
    color: #333;
}

body.dark-mode .modal-actions button.secondary {
    background: #444;
    color: #e0e0e0;
}

.modal-actions button.secondary:hover {
    background: #ccc;
}

body.dark-mode .modal-actions button.secondary:hover {
    background: #555;
}

/* Responsive design for mobile */
@media (max-width: 768px) {
    #toolbar {
        gap: 8px;
    }

    #canvas {
        height: calc(100vh - 140px);
    }

    #configPanel {
        right: 8px;
        left: 8px;
        width: auto;
        max-height: calc(100vh - 150px);
    }

    #cheatBubble {
        left: 8px;
        right: 8px;
        width: auto;
        max-height: 50vh;
    }

    .device-btn, #connectModeBtn, #clearBtn, #saveBtn, #loadBtn, #exportBtn, #importBtn {
        padding: 6px 10px;
        font-size: 12px;
        gap: 4px;
    }

    .device {
        width: 70px;
        height: 70px;
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    #toolbar {
        flex-direction: column;
        gap: 6px;
    }

    .device-btn, #connectModeBtn, #clearBtn, #saveBtn, #loadBtn, #exportBtn, #importBtn {
        width: 100%;
        justify-content: center;
    }

    #canvas {
        height: calc(100vh - 240px);
    }

    #configPanel {
        font-size: 12px;
    }

    #cheatBubble {
        font-size: 12px;
    }

    svg text {
        font-size: 10px;
    }
}
