﻿/* DESIGN SYSTEM & GLOBAL VARIABLES */
:root {
    --bg-main: #0c0f17;
    --bg-card: rgba(20, 26, 42, 0.6);
    --bg-card-hover: rgba(30, 38, 60, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent: #6366f1; /* Indigo */
    --accent-hover: #4f46e5;
    
    /* Potential Potentials Colors */
    --color-dead: #2d3139;
    --color-l1: #ff3b30;
    --color-l2: #ff9500;
    --color-l3: #af52de;
    --color-neutral: #00d4ff;
    
    /* State colors */
    --color-success: #34c759;
    --color-danger: #ff3b30;
    --color-warning: #ffcc00;
    --color-info: #00d4ff;
    
    --font-hebrew: 'Assistant', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-latin: 'Outfit', sans-serif;
}

/* BASE STYLES */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-hebrew);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

button, input, select {
    font-family: inherit;
    font-size: inherit;
}

/* APP CONTAINER LAYOUT */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* HEADER STYLE */
.app-header {
    background: rgba(12, 15, 23, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
}

.logo-text {
    font-family: var(--font-latin);
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a78bfa, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.logo-ver {
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 4px;
    color: #a78bfa;
    -webkit-text-fill-color: initial;
}

/* Circuit Name Header Container */
.circuit-name-container {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.4rem 0.8rem;
    gap: 0.4rem;
    height: 42px;
    margin-right: 1.5rem;
    margin-left: auto;
}

#circuit-name-input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    outline: none;
    width: 160px;
    text-align: right;
    transition: all 0.2s ease;
}

#circuit-name-input:focus {
    color: #a78bfa;
}

.file-ext-badge {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
    direction: ltr;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 0.4rem;
    border-radius: 12px;
}

.control-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.control-btn:hover:not(.disabled) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.control-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.run-btn {
    color: var(--color-success);
}
.run-btn:hover:not(.disabled) {
    background: rgba(52, 199, 89, 0.15) !important;
    color: #4cd964;
}

.scan-btn {
    color: #818cf8;
}
.scan-btn:hover:not(.disabled) {
    background: rgba(99, 102, 241, 0.15) !important;
    color: #a5b4fc;
}

.pause-btn {
    color: var(--color-warning);
}
.pause-btn:hover:not(.disabled) {
    background: rgba(255, 204, 0, 0.15) !important;
    color: #ffcc00;
}

.reset-btn:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.08) !important;
}

.clear-btn:hover:not(.disabled) {
    background: rgba(255, 59, 48, 0.15) !important;
    color: #ff453a;
}

.save-btn:hover:not(.disabled) {
    background: rgba(99, 102, 241, 0.15) !important;
    color: #a78bfa;
}

.load-btn:hover:not(.disabled) {
    background: rgba(0, 212, 255, 0.15) !important;
    color: #00d4ff;
}

.print-btn {
    color: #f3a952;
}

.print-btn:hover:not(.disabled) {
    background: rgba(243, 169, 82, 0.15) !important;
    color: #ffc477;
}

.help-tour-btn {
    color: #5eead4;
}

.help-tour-btn:hover:not(.disabled) {
    background: rgba(45, 212, 191, 0.15) !important;
    color: #99f6e4;
}


.divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.speed-control input[type="range"] {
    width: 80px;
    accent-color: var(--accent);
    cursor: pointer;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-indicator.normal {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.status-indicator.active {
    background: rgba(52, 199, 89, 0.1);
    border: 1px solid rgba(52, 199, 89, 0.3);
    color: #34c759;
}

.status-indicator.tripped {
    background: rgba(255, 59, 48, 0.1);
    border: 1px solid rgba(255, 59, 48, 0.3);
    color: #ff3b30;
    animation: pulse-danger 1s infinite alternate;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
}

.status-indicator.active .status-dot {
    background-color: #34c759;
    box-shadow: 0 0 8px #34c759;
}

.status-indicator.tripped .status-dot {
    background-color: #ff3b30;
    box-shadow: 0 0 8px #ff3b30;
}

.about-btn {
    background: var(--accent);
    border: none;
    color: white;
    padding: 0.4rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.about-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

/* MAIN LAYOUT STRUCTURE */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* SIDEBAR LEFT - TOOLBOX */
.sidebar-left {
    width: 280px;
    border-left: 1px solid var(--border-color);
    background: rgba(12, 15, 23, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    letter-spacing: -0.2px;
}

.toolbox-search-container {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.toolbox-search-container input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0.8rem;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.toolbox-search-container input:focus {
    border-color: var(--accent);
}

.toolbox-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.tool-group {
    margin-bottom: 1.5rem;
}

.tool-group-header {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding-bottom: 0.25rem;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.tool-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 72px;
    color: var(--text-secondary);
}

.tool-item:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.tool-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--accent);
    color: #a78bfa;
    box-shadow: inset 0 0 8px rgba(99, 102, 241, 0.2);
}

.tool-icon {
    width: 32px;
    height: 32px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-latin);
    font-weight: 700;
    font-size: 0.9rem;
    border-radius: 4px;
}

.tool-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.eraser-tool {
    grid-column: span 2;
    background: rgba(255, 59, 48, 0.05);
    border-color: rgba(255, 59, 48, 0.15);
    color: rgba(255, 59, 48, 0.7);
}

.eraser-tool:hover {
    background: rgba(255, 59, 48, 0.15);
    border-color: rgba(255, 59, 48, 0.3);
    color: #ff453a;
}

/* ICONS DRAWINGS */
.wire-h-icon::after { content: ''; width: 24px; height: 2px; background: currentColor; }
.wire-v-icon::after { content: ''; width: 2px; height: 24px; background: currentColor; }
.wire-c-br-icon::after {
    content: ''; width: 14px; height: 14px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    position: absolute; top: 6px; left: 6px;
}
.wire-c-bl-icon::after {
    content: ''; width: 14px; height: 14px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor;
    position: absolute; top: 6px; right: 6px;
}
.wire-c-tr-icon::after {
    content: ''; width: 14px; height: 14px; border-right: 2px solid currentColor; border-top: 2px solid currentColor;
    position: absolute; bottom: 6px; left: 6px;
}
.wire-c-tl-icon::after {
    content: ''; width: 14px; height: 14px; border-left: 2px solid currentColor; border-top: 2px solid currentColor;
    position: absolute; bottom: 6px; right: 6px;
}
.wire-t-d-icon::after {
    content: ''; width: 24px; height: 2px; background: currentColor; position: absolute;
}
.wire-t-d-icon::before {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; top: 16px;
}
.wire-t-u-icon::after {
    content: ''; width: 24px; height: 2px; background: currentColor; position: absolute;
}
.wire-t-u-icon::before {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; bottom: 16px;
}
.wire-t-r-icon::before {
    content: ''; width: 2px; height: 24px; background: currentColor; position: absolute;
}
.wire-t-r-icon::after {
    content: ''; width: 12px; height: 2px; background: currentColor; position: absolute; left: 4px;
}
.wire-t-l-icon::before {
    content: ''; width: 2px; height: 24px; background: currentColor; position: absolute;
}
.wire-t-l-icon::after {
    content: ''; width: 12px; height: 2px; background: currentColor; position: absolute; right: 4px;
}
.wire-cross-icon::after {
    content: ''; width: 24px; height: 2px; background: currentColor; position: absolute;
}
.wire-cross-icon::before {
    content: ''; width: 2px; height: 24px; background: currentColor; position: absolute;
}
.wire-bridge-icon {
    background: linear-gradient(currentColor, currentColor) no-repeat center/2px 24px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wire-bridge-icon::after {
    content: ''; width: 24px; height: 2px; background: currentColor; position: absolute;
}
.wire-bridge-icon::before {
    content: '';
    width: 10px;
    height: 8px;
    border: 2px solid currentColor;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: #131720; /* Card/toolbox dark background */
    position: absolute;
    top: 3px;
    box-sizing: border-box;
}

.source-l1-icon { background: var(--color-l1); color: white; border-radius: 50%; font-size: 0.75rem; }
.source-l2-icon { background: var(--color-l2); color: black; border-radius: 50%; font-size: 0.75rem; }
.source-l3-icon { background: var(--color-l3); color: white; border-radius: 50%; font-size: 0.75rem; }
.source-n-icon { background: var(--color-neutral); color: black; border-radius: 50%; font-size: 0.75rem; }

/* Buttons & switches */
.btn-no-icon::after {
    content: ''; width: 16px; height: 2px; background: currentColor; position: absolute; top: 12px;
}
.btn-no-icon::before {
    content: ''; width: 16px; height: 2px; background: currentColor; position: absolute; top: 8px; transform: rotate(-15deg);
}
.btn-nc-icon::after {
    content: ''; width: 16px; height: 2px; background: currentColor; position: absolute; top: 16px;
}
.btn-nc-icon::before {
    content: ''; width: 18px; height: 2px; background: currentColor; position: absolute; top: 16px; transform: rotate(15deg);
}
.sw-no-icon::after {
    content: ''; width: 16px; height: 2px; background: currentColor; position: absolute; top: 14px;
}
.sw-no-icon::before {
    content: ''; width: 16px; height: 2px; background: currentColor; position: absolute; top: 10px; transform: rotate(-25deg);
}
.sw-nc-icon::after {
    content: ''; width: 16px; height: 2px; background: currentColor; position: absolute; top: 16px;
}
.sw-nc-icon::before {
    content: ''; width: 18px; height: 2px; background: currentColor; position: absolute; top: 16px; transform: rotate(25deg);
}

/* Relays & contacts */
.coil-icon { border: 2px solid currentColor; width: 22px; height: 14px; }
.timer-coil-icon { border: 2px solid currentColor; width: 22px; height: 14px; color: #a78bfa; }
.step-coil-icon { border: 2px solid currentColor; width: 22px; height: 14px; color: #34c759; }

.timer-no-icon {
    color: #a78bfa;
    font-size: 8px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}
.timer-no-icon::after {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; left: 12px;
}
.timer-no-icon::before {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; right: 12px;
}

.step-no-icon {
    color: #34c759;
    font-size: 8px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}
.step-no-icon::after {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; left: 12px;
}
.step-no-icon::before {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; right: 12px;
}

.contact-no-icon::after {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; left: 12px;
}
.contact-no-icon::before {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; right: 12px;
}
.contact-nc-icon::after {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; left: 10px;
}
.contact-nc-icon::before {
    content: ''; width: 2px; height: 12px; background: currentColor; position: absolute; right: 10px;
}
.contact-nc-icon::shadow {
    /* draw a line crossing them */
}

/* Lamps & Motors */
.lamp-icon { border: 2px solid currentColor; width: 20px; height: 20px; border-radius: 50%; }
.lamp-icon::after {
    content: 'X'; font-size: 10px; font-weight: bold; position: absolute;
}
.motor1-icon, .motor3-icon, .motor6-icon {
    border: 2px solid currentColor; width: 24px; height: 24px; border-radius: 50%;
    font-size: 8px; font-weight: bold;
}

/* Overload Relay Icons */
.ol-power-icon { border: 2px solid currentColor; width: 20px; height: 12px; border-radius: 2px; }
.ol-power-icon::after { content: 'OL'; font-size: 7px; font-weight: bold; position: absolute; color: var(--text-secondary); }
.ol-nc-icon { border: 1px solid var(--border-color); width: 20px; height: 20px; border-radius: 4px; }
.ol-nc-icon::before { content: 'OL'; font-size: 8px; font-weight: bold; position: absolute; top: -1px; left: -1px; }
.ol-nc-icon::after { content: 'NC'; font-size: 8px; font-weight: bold; position: absolute; bottom: -1px; right: -1px; }
.ol-no-icon { border: 1px solid var(--border-color); width: 20px; height: 20px; border-radius: 4px; }
.ol-no-icon::before { content: 'OL'; font-size: 8px; font-weight: bold; position: absolute; top: -1px; left: -1px; }
.ol-no-icon::after { content: 'NO'; font-size: 8px; font-weight: bold; position: absolute; bottom: -1px; right: -1px; }

/* WORKSPACE GRID AREA */
.workspace-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #090b11;
    overflow: hidden;
}

.workspace-header {
    height: 48px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(12, 15, 23, 0.3);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.workspace-title {
    font-weight: 700;
    color: var(--text-primary);
}

.workspace-grid-controls {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.grid-size-btn {
    border: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.12);
    color: var(--text-primary);
    border-radius: 7px;
    padding: 0.3rem 0.65rem;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.grid-size-btn:hover {
    background: rgba(99, 102, 241, 0.28);
    border-color: var(--accent);
}

.grid-size-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.grid-size-display {
    min-width: 52px;
    direction: ltr;
    text-align: center;
    color: var(--text-secondary);
    font-family: var(--font-latin);
}

.canvas-viewport {
    flex: 1;
    overflow: auto;
    padding: 2rem;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
}

.print-circuit-header {
    display: none;
}

/* THE GRID CANVAS */
.schematic-grid {
    display: grid;
    background-color: #0b0d16;
    background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 17px 17px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(0, 0, 0, 0.4);
    position: relative;
    padding: 5px;
    margin: 0 auto;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

@page {
    size: A4 landscape;
    margin: 8mm;
}

@media print {
    :root {
        --bg-main: #ffffff;
        --text-primary: #111827;
        --text-secondary: #374151;
        --border-color: rgba(17, 24, 39, 0.18);
        --color-dead: #1f2937;
    }

    *, *::before, *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        animation: none !important;
        transition: none !important;
    }

    html,
    body,
    .app-container {
        width: auto !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        background: #ffffff !important;
        color: #111827 !important;
    }

    .app-header,
    .sidebar-left,
    .sidebar-right,
    .workspace-header,
    .modal-overlay,
    .short-circuit-screen,
    .context-menu,
    .selection-info,
    .selection-box {
        display: none !important;
    }

    .app-main,
    .workspace-area {
        display: block !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        background: #ffffff !important;
    }

    .print-circuit-header {
        display: flex !important;
        align-items: flex-end;
        justify-content: space-between;
        direction: rtl;
        border-bottom: 2px solid #111827;
        margin-bottom: 4mm;
        padding: 0 0 2mm;
    }

    .print-circuit-header h1 {
        color: #111827;
        font-size: 20pt;
        line-height: 1.1;
    }

    #print-circuit-meta {
        direction: ltr;
        color: #4b5563;
        font-family: var(--font-latin);
        font-size: 9pt;
    }

    .canvas-viewport {
        display: block !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        padding: 0 !important;
    }

    .schematic-grid {
        grid-template-columns: repeat(var(--print-cols, 14), var(--print-cell-size, 60px)) !important;
        grid-template-rows: repeat(var(--print-rows, 10), var(--print-cell-size, 60px)) !important;
        width: var(--print-grid-width) !important;
        height: var(--print-grid-height) !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: 0 auto !important;
        padding: 4px !important;
        border: 1px solid #9ca3af !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background-color: #ffffff !important;
        background-image: radial-gradient(rgba(17, 24, 39, 0.12) 1px, transparent 1px) !important;
        background-size: calc(var(--print-cell-size, 60px) / 5) calc(var(--print-cell-size, 60px) / 5) !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .grid-cell {
        border-color: rgba(17, 24, 39, 0.04) !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    .grid-cell.selected,
    .grid-cell.multi-selected {
        border-color: rgba(17, 24, 39, 0.04) !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    .cell-address,
    .cell-description,
    .cell-motor-label {
        background: rgba(255, 255, 255, 0.88) !important;
    }
}

/* CELL STYLING */
.grid-cell {
    width: 100%;
    height: 100%;
    border: 1px dashed rgba(255, 255, 255, 0.02);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    transition: background 0.15s ease, border-color 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.grid-cell:hover {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(99, 102, 241, 0.2);
}

/* When in Eraser mode */
.workspace-area.eraser-active .grid-cell {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ff3b30' stroke-width='2'><path d='M20 20H7L3 16C2 15 2 13 3 12L13 2L22 11L20 20Z'/></svg>") 4 16, pointer;
}

.workspace-area.eraser-active .grid-cell:hover {
    background: rgba(255, 59, 48, 0.05);
    border-color: rgba(255, 59, 48, 0.3);
}

/* CELL GRAPHICS */
.cell-component {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.component-svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Address Label in grid */
.cell-address {
    position: absolute;
    top: 4px;
    font-family: var(--font-latin);
    font-size: 0.65rem;
    font-weight: 700;
    color: #a78bfa;
    background: rgba(12, 15, 23, 0.7);
    padding: 0 0.2rem;
    border-radius: 2px;
    pointer-events: none;
    direction: ltr;
}

.cell-description {
    position: absolute;
    bottom: 2px;
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(12, 15, 23, 0.7);
    padding: 0 0.3rem;
    border-radius: 2px;
    pointer-events: none;
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Shift description up for motor cells to leave space for motor type label */
.load-motor1-cell .cell-description,
.load-motor3-cell .cell-description {
    bottom: 14px;
}

/* Motor label at the very bottom */
.cell-motor-label {
    position: absolute;
    bottom: 2px;
    font-family: var(--font-latin);
    font-size: 0.6rem;
    font-weight: 700;
    background: rgba(12, 15, 23, 0.75);
    padding: 0 0.25rem;
    border-radius: 2px;
    pointer-events: none;
    direction: ltr;
}

.load-motor1-cell .cell-motor-label {
    color: #00d4ff; /* Cyan */
}

.load-motor3-cell .cell-motor-label {
    color: #ff9500; /* Orange */
}

/* Highlight cell on hover/select */
.grid-cell.selected {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid var(--accent) !important;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.grid-cell.button-pressed {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(129, 140, 248, 0.75);
    box-shadow: inset 0 0 18px rgba(99, 102, 241, 0.18), 0 0 10px rgba(99, 102, 241, 0.3);
}

.grid-cell.overload-tripped {
    background: rgba(255, 59, 48, 0.12);
    border-color: rgba(255, 59, 48, 0.6) !important;
    box-shadow: inset 0 0 18px rgba(255, 59, 48, 0.12), 0 0 10px rgba(255, 59, 48, 0.3);
    animation: pulse-danger 1s infinite alternate;
}

/* SIDEBAR RIGHT - LIVE MONITOR & LOGS */
.sidebar-right {
    width: 320px;
    border-right: 1px solid var(--border-color);
    background: rgba(12, 15, 23, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
}

.monitor-section {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.monitor-section.flex-grow {
    flex: 1;
    overflow: hidden;
}

.section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Examples buttons list */
.examples-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.example-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-align: right;
    transition: all 0.2s ease;
}

.example-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

/* Variable Table styles */
.variables-panel {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.15);
}

.variables-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    text-align: right;
}

.variables-table th {
    background: rgba(255, 255, 255, 0.02);
    padding: 0.5rem;
    font-weight: 700;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.variables-table td {
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    vertical-align: middle;
}

.variables-table tr:hover {
    background: rgba(255, 255, 255, 0.01);
}

.variables-table tr.no-vars {
    text-align: center;
    color: var(--text-secondary);
}

.var-tag {
    font-family: var(--font-latin);
    font-weight: 700;
    background: rgba(99, 102, 241, 0.15);
    color: #a78bfa;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    border: 1px solid rgba(99, 102, 241, 0.2);
    display: inline-block;
    direction: ltr;
}

.var-state {
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.7rem;
    display: inline-block;
    text-align: center;
}

.var-state.on {
    background: rgba(52, 199, 89, 0.15);
    color: #30d158;
    border: 1px solid rgba(52, 199, 89, 0.25);
    box-shadow: 0 0 6px rgba(52, 199, 89, 0.1);
}

.var-state.off {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.var-state.trip-active {
    background: rgba(255, 59, 48, 0.15);
    color: #ff453a;
    border: 1px solid rgba(255, 59, 48, 0.25);
    box-shadow: 0 0 6px rgba(255, 59, 48, 0.1);
}

.var-state.trip-normal {
    background: rgba(52, 199, 89, 0.15);
    color: #30d158;
    border: 1px solid rgba(52, 199, 89, 0.25);
}

/* Event log style */
.event-log {
    height: 120px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    font-family: var(--font-hebrew);
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.log-entry {
    line-height: 1.3;
    padding: 0.1rem 0.2rem;
    border-radius: 4px;
}

.log-entry.system-log { color: var(--text-secondary); border-right: 2px solid var(--text-secondary); padding-right: 4px; }
.log-entry.event-on { color: #30d158; border-right: 2px solid #30d158; padding-right: 4px; }
.log-entry.event-off { color: #8e8e93; border-right: 2px solid #8e8e93; padding-right: 4px; }
.log-entry.event-warn { color: var(--color-warning); border-right: 2px solid var(--color-warning); padding-right: 4px; }
.log-entry.event-danger { color: var(--color-danger); border-right: 2px solid var(--color-danger); padding-right: 4px; font-weight: bold; }

/* MODALS - GENERAL & ABOUT & PROPERTIES */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(6, 8, 14, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: #0f131f;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    width: 450px;
    max-width: 90vw;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-card {
    transform: translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.close-modal {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.close-modal:hover { color: var(--text-primary); }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.01);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* BUTTONS */
.btn {
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    border: none;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.btn-danger {
    background: rgba(255, 59, 48, 0.15);
    color: #ff453a;
    border: 1px solid rgba(255, 59, 48, 0.2);
}
.btn-danger:hover {
    background: rgba(255, 59, 48, 0.3);
    color: white;
}
.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.btn-warning {
    background: var(--color-warning);
    color: black;
}
.btn-warning:hover {
    background: #e6b800;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.3);
}

/* ABOUT MODAL SPECIFICS */
.text-center { text-align: center; }
.about-logo {
    font-family: var(--font-latin);
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a78bfa, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.about-desc {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.developer-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dev-avatar {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent), #4f46e5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-latin);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    margin-bottom: 0.75rem;
}

.developer-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.dev-email {
    font-family: var(--font-latin);
    color: var(--accent);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.dev-copyright {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.about-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: right;
    line-height: 1.5;
    background: rgba(0, 0, 0, 0.1);
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.about-meta p {
    margin-bottom: 0.3rem;
}

/* FORM FIELDS STYLING */
.form-group {
    margin-bottom: 1.25rem;
    text-align: right;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group input, .form-group select {
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease;
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--accent);
}

.form-row {
    display: flex;
    gap: 0.75rem;
}

.col-6 {
    flex: 1;
}

.form-tip {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
    display: block;
}

/* SHORT CIRCUIT TRIP OVERLAY Screen */
.short-circuit-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(12, 5, 5, 0.9);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.short-circuit-screen.active {
    display: flex;
    animation: flash-red 0.5s ease-out;
}

.trip-alert-box {
    background: #1c0a0a;
    border: 2px solid #ff3b30;
    border-radius: 20px;
    padding: 2.5rem;
    width: 480px;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 0 50px rgba(255, 59, 48, 0.3);
    animation: shake-trip 0.4s ease-in-out;
}

.trip-icon {
    font-size: 3.5rem;
    color: #ffcc00;
    text-shadow: 0 0 20px rgba(255, 204, 0, 0.5);
    margin-bottom: 1rem;
    animation: flicker-trip 1.5s infinite;
}

.trip-alert-box h2 {
    font-size: 1.8rem;
    color: #ff3b30;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.trip-alert-box p {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.trip-details {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* ANIMATIONS & KEYFRAMES */
@keyframes pulse-danger {
    0% { background: rgba(255, 59, 48, 0.1); border-color: rgba(255, 59, 48, 0.3); }
    100% { background: rgba(255, 59, 48, 0.25); border-color: rgba(255, 59, 48, 0.6); }
}

@keyframes flash-red {
    0% { background: rgba(255, 0, 0, 1); }
    100% { background: rgba(12, 5, 5, 0.9); }
}

@keyframes shake-trip {
    0%, 100% { transform: translateY(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes flicker-trip {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* SVG Line Power potential colors (controlled in js) */
.potential-none { stroke: var(--color-dead); transition: stroke 0.15s ease; }
.potential-l1 { stroke: var(--color-l1); filter: drop-shadow(0px 0px 3px rgba(255, 59, 48, 0.8)); transition: stroke 0.15s ease; }
.potential-l2 { stroke: var(--color-l2); filter: drop-shadow(0px 0px 3px rgba(255, 149, 0, 0.8)); transition: stroke 0.15s ease; }
.potential-l3 { stroke: var(--color-l3); filter: drop-shadow(0px 0px 3px rgba(175, 82, 222, 0.8)); transition: stroke 0.15s ease; }
.potential-neutral { stroke: var(--color-neutral); filter: drop-shadow(0px 0px 3px rgba(0, 212, 255, 0.8)); transition: stroke 0.15s ease; }

/* SVG text labels inside grid */
.svg-label {
    font-family: var(--font-latin);
    font-size: 8px;
    font-weight: bold;
    fill: var(--text-secondary);
}

/* MOTOR ANIMATION (Rotor rotates when active) */
@keyframes spin-rotor {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes spin-rotor-reverse {
    from { transform: rotate(360deg); }
    to { transform: rotate(0deg); }
}

@keyframes spin-rotor-ccw {
    from { transform: scaleX(-1) rotate(0deg); }
    to { transform: scaleX(-1) rotate(-360deg); }
}

.motor-rotor {
    transform-origin: 42.5px 47.5px; /* Shifted center of motor cell */
    transform-box: view-box;
}
.motor6-v-cell .motor-rotor {
    transform-origin: 42.5px 42.5px; /* Centered in capsule */
}

.motor-active .motor-rotor {
    animation: spin-rotor 1.5s linear infinite;
}

.motor-active.motor-slow .motor-rotor {
    animation: spin-rotor 4s linear infinite;
}

.motor-active.motor-ccw .motor-rotor {
    animation: spin-rotor-reverse 1.5s linear infinite;
}

.motor-active.motor-slow.motor-ccw .motor-rotor {
    animation: spin-rotor-reverse 4s linear infinite;
}

/* LAMP GLOW CLASSES */
.lamp-glow-red { fill: #ff3b30; filter: drop-shadow(0 0 6px #ff3b30); }
.lamp-glow-green { fill: #34c759; filter: drop-shadow(0 0 6px #34c759); }
.lamp-glow-yellow { fill: #ffcc00; filter: drop-shadow(0 0 6px #ffcc00); }
.lamp-glow-blue { fill: #00d4ff; filter: drop-shadow(0 0 6px #00d4ff); }

/* SCROLLBARS */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Drag and Drop styling */
.grid-cell[draggable="true"] {
    cursor: grab;
}

.grid-cell.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.grid-cell.drag-over {
    background: rgba(99, 102, 241, 0.15);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

/* Canvas Panning Styles */
.canvas-viewport.pan-mode {
    cursor: grab !important;
}
.canvas-viewport.panning-active {
    cursor: grabbing !important;
    user-select: none !important;
}
.canvas-viewport.panning-active * {
    pointer-events: none !important;
}

/* Direction Picker Popover */
.direction-picker-popover {
    position: absolute;
    z-index: 1000;
    background: #171d2b;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.6rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: auto;
    width: 120px;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.picker-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
    user-select: none;
}

.picker-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
}

.picker-btn {
    width: 46px;
    height: 46px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.picker-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: scale(1.05);
}

/* Guided Help Tour */
.help-tour-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: min(420px, calc(100vw - 2.5rem));
    background: linear-gradient(180deg, rgba(20, 28, 43, 0.98), rgba(11, 15, 24, 0.98));
    border: 1px solid rgba(94, 234, 212, 0.35);
    border-radius: 12px;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    padding: 1rem;
    z-index: 1900;
}

.help-tour-panel.hidden {
    display: none;
}

.help-tour-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.help-tour-step {
    color: #5eead4;
    font-size: 0.78rem;
    font-weight: 700;
}

.help-tour-header h2 {
    font-size: 1.1rem;
    line-height: 1.25;
    margin-top: 0.1rem;
}

.help-tour-icon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
}

.help-tour-icon-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.help-tour-text {
    color: var(--text-primary);
    line-height: 1.55;
    font-size: 0.95rem;
    min-height: 4.4rem;
}

.help-tour-progress {
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
    margin: 0.9rem 0;
}

#help-tour-progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #5eead4, #818cf8);
    transition: width 0.25s ease;
}

.help-tour-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.tour-highlight {
    position: relative;
    z-index: 30 !important;
    outline: 3px solid #5eead4 !important;
    box-shadow: 0 0 0 5px rgba(45, 212, 191, 0.18), 0 0 22px rgba(45, 212, 191, 0.45) !important;
}

.tour-cell-highlight {
    position: relative;
    z-index: 25 !important;
    border-color: #5eead4 !important;
    box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.22), inset 0 0 18px rgba(45, 212, 191, 0.18) !important;
}

.tour-cell-highlight::after {
    content: '';
    position: absolute;
    inset: 5px;
    border: 2px dashed rgba(94, 234, 212, 0.9);
    border-radius: 8px;
    pointer-events: none;
}

body.help-tour-active .app-main,
body.help-tour-active .app-header {
    transition: filter 0.2s ease;
}

@media (max-width: 720px) {
    .help-tour-panel {
        right: 0.75rem;
        bottom: 0.75rem;
        width: calc(100vw - 1.5rem);
    }

    .help-tour-text {
        min-height: 0;
    }
}
/* === V1.13 NEW LIBRARY PANEL === */
.library-modal-content {
  background: linear-gradient(180deg, #131826 0%, #0c0f17 100%);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 90%;
  max-width: 520px;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

.library-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.02);
}

.library-modal-header .modal-title {
  font-family: var(--font-latin);
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0;
  text-align: right;
  color: var(--text-primary);
}

.library-modal-header .close-modal {
  position: static;
  float: none;
  font-size: 1.5rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  transition: background 0.2s;
}

.library-modal-header .close-modal:hover {
  background: rgba(255, 255, 255, 0.05);
}

.library-search-box {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.library-search-box input {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.library-search-box input:focus {
  border-color: var(--accent);
}

.library-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.library-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.library-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.library-list li:hover {
  background: rgba(99, 102, 241, 0.08);
}

.library-list li:active {
  background: rgba(99, 102, 241, 0.15);
}

.library-list li .lib-icon {
  font-size: 1.4rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(99, 102, 241, 0.15);
}

.library-list li .lib-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.library-list li .lib-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  direction: ltr;
  text-align: left;
}

.library-list li .lib-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.library-list li .lib-load-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}

.library-list li:hover .lib-load-btn {
  opacity: 1;
}

.library-list li .lib-load-btn:hover {
  background: var(--accent-hover);
}

.library-list li.no-results {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  cursor: default;
  justify-content: center;
}

.library-list li.no-results:hover {
  background: none;
}

.library-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.02);
}

.library-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

@keyframes fadeIn {
  from {opacity:0;transform:scale(0.95);}
  to {opacity:1;transform:scale(1);}
}

/* === V1.14 NEW MULTI-SELECT FEATURES === */

/* Selected Grid Cells */
.grid-cell.selected {
    border: 2px solid var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3), inset 0 0 15px rgba(99, 102, 241, 0.15) !important;
    z-index: 5;
}
.grid-cell.selected .cell-content {
    filter: brightness(1.2);
}

/* Selection Box (Drag Rectangle) */
.selection-box {
    position: fixed;
    border: 2px dashed var(--accent);
    background: rgba(99, 102, 241, 0.1);
    pointer-events: none;
    z-index: 100;
    border-radius: 4px;
    display: none;
}
.selection-box.active {
    display: block;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: linear-gradient(180deg, #131826 0%, #0c0f17 100%);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.4rem 0;
    min-width: 180px;
    z-index: 3000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: none;
    animation: fadeIn 0.15s ease-out;
}
.context-menu.open {
    display: block;
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: background 0.15s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.context-menu-item:last-child {
    border-bottom: none;
}
.context-menu-item:hover {
    background: rgba(99, 102, 241, 0.12);
}
.context-menu-item .cm-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}
.context-menu-item .cm-label {
    flex: 1;
}
.context-menu-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.05);
    margin: 0.3rem 0.5rem;
}
.context-menu-item.danger {
    color: #ff453a;
}
.context-menu-item.danger:hover {
    background: rgba(255, 59, 48, 0.12);
}
.context-menu-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.context-menu-item.disabled:hover {
    background: none;
}

/* Move Mode Cursor */
.grid-cell.move-target {
    cursor: move !important;
}

/* Selection Info Bar */
.selection-info {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    z-index: 50;
    display: none;
    backdrop-filter: blur(8px);
}
.selection-info.visible {
    display: block;
}
.selection-info .sel-count {
    color: var(--accent);
    font-weight: 700;
}

/* Toast Notification for Multi-Select */
.select-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.6rem 1.2rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    z-index: 3000;
    display: none;
    animation: fadeIn 0.2s ease-out;
    backdrop-filter: blur(8px);
    white-space: nowrap;
}
.select-toast.visible {
    display: block;
}

/* === V1.16 DIAGNOSTICS & SCAN MODAL STYLES === */
.scan-card {
    max-width: 580px;
}
.scan-status-summary {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1.2rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 1.5rem;
}
.scan-status-icon {
    font-size: 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent);
    flex-shrink: 0;
}
.scan-status-icon.success {
    background: rgba(52, 199, 89, 0.15);
    color: #30d158;
}
.scan-status-icon.warning {
    background: rgba(255, 214, 10, 0.15);
    color: #ffd60a;
}
.scan-status-icon.danger {
    background: rgba(255, 69, 58, 0.15);
    color: #ff453a;
}
.scan-status-details h3 {
    margin: 0 0 0.35rem 0;
    font-size: 1.15rem;
    font-weight: 700;
}
.scan-status-details p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.scan-results-container {
    max-height: 280px;
    overflow-y: auto;
    padding-right: 0.25rem;
}
.scan-results-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}
.scan-results-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.scan-result-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem;
    border-radius: 10px;
    font-size: 0.88rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.15s ease;
}
.scan-result-item:hover {
    transform: translateY(-1px);
}
.scan-result-item.info {
    background: rgba(10, 132, 255, 0.06);
    border-color: rgba(10, 132, 255, 0.15);
    color: #409cff;
}
.scan-result-item.info:hover {
    background: rgba(10, 132, 255, 0.12);
}
.scan-result-item.warning {
    background: rgba(255, 214, 10, 0.06);
    border-color: rgba(255, 214, 10, 0.15);
    color: #ffd60a;
}
.scan-result-item.warning:hover {
    background: rgba(255, 214, 10, 0.12);
}
.scan-result-item.danger {
    background: rgba(255, 69, 58, 0.06);
    border-color: rgba(255, 69, 58, 0.15);
    color: #ff453a;
}
.scan-result-item.danger:hover {
    background: rgba(255, 69, 58, 0.12);
}
.scan-result-item-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}
.scan-result-item-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.scan-result-item-title {
    font-weight: 700;
}
.scan-result-item-desc {
    opacity: 0.85;
    line-height: 1.4;
}
.scan-result-item-action {
    font-size: 0.72rem;
    font-weight: 600;
    opacity: 0.6;
    margin-top: 0.25rem;
    align-self: flex-start;
}
.scan-result-item:hover .scan-result-item-action {
    opacity: 1;
    text-decoration: underline;
}

/* Diagnostic Flash Highlighting */
@keyframes temp-blink {
    0% { outline: 3px solid #ff453a; box-shadow: 0 0 15px rgba(255,69,58,0.6); }
    50% { outline: 3px solid transparent; box-shadow: 0 0 0 transparent; }
    100% { outline: 3px solid #ff453a; box-shadow: 0 0 15px rgba(255,69,58,0.6); }
}
.grid-cell.temp-highlight {
    animation: temp-blink 0.4s ease-in-out 4;
    z-index: 100;
}

/* === V1.19 MERGE MODAL & OPTIONS === */
.load-choice-container {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    flex-direction: row;
}

.load-choice-card {
    flex: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.load-choice-card:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.2);
}

.load-choice-icon {
    font-size: 2.2rem;
    margin-bottom: 0.25rem;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
    transition: transform 0.3s ease;
}

.load-choice-card:hover .load-choice-icon {
    transform: scale(1.15) rotate(5deg);
}

.load-choice-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.load-choice-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 0.25rem;
}

/* Keep editor-only state highlights out of the printed schematic. */
@media print {
    .schematic-grid .grid-cell,
    .schematic-grid .grid-cell:hover,
    .schematic-grid .grid-cell.selected,
    .schematic-grid .grid-cell.multi-selected,
    .schematic-grid .grid-cell.button-pressed,
    .schematic-grid .grid-cell.overload-tripped,
    .schematic-grid .grid-cell.dragging,
    .schematic-grid .grid-cell.drag-over,
    .schematic-grid .grid-cell.move-target,
    .schematic-grid .grid-cell.temp-highlight {
        border-color: rgba(17, 24, 39, 0.04) !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
    }

    /* The address also exists inside the component SVG; hide the duplicate overlay. */
    .schematic-grid .cell-address.duplicate-address {
        display: none !important;
    }

    .schematic-grid .cell-address:not(.duplicate-address) {
        top: 1px !important;
        right: 2px;
        padding: 0 2px;
        font-size: clamp(4px, calc(var(--print-cell-size, 60px) / 10), 8px);
        line-height: 1;
    }

    .schematic-grid .component-address-label {
        transform: translateY(-4px);
    }

    .schematic-grid .cell-description {
        bottom: -1px !important;
        max-width: 82%;
        padding: 0 2px;
        font-size: clamp(4px, calc(var(--print-cell-size, 60px) / 11), 8px);
        line-height: 1.05;
    }
}



