* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; height: 100vh; overflow: hidden; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ===================== ШАПКА С БРЕНДИНГОМ ===================== */
#auth-bar {
    background: linear-gradient(90deg, #0f1926 0%, #1a2538 60%, #1a2740 100%);
    color: #fff;
    padding: 6px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-shrink: 0;
    border-bottom: 1px solid #22304a;
    box-shadow: 0 1px 6px rgba(0, 212, 255, 0.08);
}

#brand {
    display: flex;
    align-items: center;
    gap: 12px;
    user-select: none;
    flex-shrink: 0;
}

#brand-logo {
    filter: drop-shadow(0 0 6px rgba(0, 212, 255, 0.55));
    flex-shrink: 0;
    transition: filter .2s;
}
#brand-logo:hover {
    filter: drop-shadow(0 0 10px rgba(0, 212, 255, 0.85));
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
}

.brand-name {
    font-family: 'Arial Black', 'Arial Bold', Arial, sans-serif;
    font-weight: 900;
    font-size: 21px;
    letter-spacing: 0.6px;
    background: linear-gradient(135deg, #eef4fa 0%, #b8c5d6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-name-accent {
    background: linear-gradient(135deg, #00d4ff 0%, #4285f4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
}

.brand-slogan {
    font-size: 10px;
    letter-spacing: 1.6px;
    color: #7a91a8;
    text-transform: uppercase;
    margin-top: 2px;
    font-weight: 500;
    white-space: nowrap;
}

#auth-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
#auth-controls #user-display {
    color: #b8c5d6;
    font-size: 13px;
}
#auth-controls button {
    background: #ecf0f1;
    border: none;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
#auth-controls button:hover { background: #bdc3c7; }

/* ===================== ОСНОВНАЯ ОБЛАСТЬ ===================== */
#main-area { display: flex; flex: 1; overflow: hidden; min-height: 0; }

#toolbar {
    width: 220px; background: #f0f0f0; padding: 10px;
    overflow-y: auto; border-right: 1px solid #ccc; flex-shrink: 0;
}
#toolbar h3 { margin-bottom: 8px; }
#block-list { margin-bottom: 10px; }

#run-simulation {
    width: 100%; padding: 8px; background: #4285f4; color: #fff;
    border: none; border-radius: 4px; cursor: pointer; margin-top: 10px;
}
#run-simulation:hover { background: #3367d6; }

#canvas-container {
    flex: 1; position: relative; background: #fafafa;
    overflow: hidden; min-width: 0; z-index: auto;
}
#canvas { position: relative; width: 100%; height: 100%; overflow: hidden; z-index: auto; }

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

#properties-panel {
    width: 300px; background: #f0f0f0; padding: 10px;
    border-left: 1px solid #ccc; overflow-y: auto; flex-shrink: 0;
}
#properties-panel h3 { margin-bottom: 8px; }
#properties-content { font-size: 13px; }
#properties-content h4 { margin-bottom: 6px; word-break: break-word; }
#properties-content .param-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
#properties-content .param-input { padding: 3px 5px; border: 1px solid #ccc; border-radius: 3px; }
#properties-content .sr-info {
    margin-top: 8px; padding: 6px 8px; background: #e8f4fd;
    border-left: 3px solid #4285f4; font-size: 11px; color: #2c3e50; border-radius: 2px;
}

.block-tool {
    padding: 6px 8px; margin: 4px 0; background: #fff;
    border: 1px solid #ccc; border-radius: 4px; cursor: pointer;
    font-size: 13px; transition: background .15s, border-color .15s;
}
.block-tool:hover { background: #e3f2fd; border-color: #4285f4; }

.block-on-canvas {
    position: absolute; background: #fff; border: 2px solid #333;
    border-radius: 6px; padding: 10px; min-width: 130px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    touch-action: none;
    -webkit-user-drag: none;
    cursor: move; z-index: 10; user-select: none;
}
.block-on-canvas.selected {
    border-color: #4285f4;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.35), 0 2px 6px rgba(0,0,0,0.15);
}
.block-label {
    font-weight: bold; font-size: 13px; text-align: center;
    margin-bottom: 6px; cursor: move; color: #2c3e50; word-break: break-word;
    touch-action: none;
}
.block-ports {
    display: flex; justify-content: space-between;
    align-items: flex-start; gap: 10px;
}

.port {
    display: inline-block; width: 12px; height: 12px;
    border-radius: 50%; border: 2px solid #2c3e50;
    cursor: crosshair; flex-shrink: 0;
    transition: transform .1s; position: relative; z-index: 11;
}
.port:hover { transform: scale(1.25); }
.port.input  { background: #2ecc71; }
.port.output { background: #e74c3c; }
.port-label { font-size: 11px; color: #555; white-space: nowrap; }

.connection-path {
    stroke-width: 2; fill: none;
    pointer-events: stroke; cursor: pointer;
}
.connection-path:hover { stroke-width: 3; }

button.locked {
    background: #bdc3c7 !important; color: #7f8c8d !important;
    cursor: not-allowed !important; opacity: 0.9; box-shadow: none !important;
}

/* ===================== МОДАЛКИ ===================== */
.auth-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
}
.auth-modal-content {
    background: white; padding: 30px; border-radius: 8px;
    width: 340px; position: relative;
}
.auth-modal-content h2 { margin-bottom: 15px; }
.auth-modal-content input {
    width: 100%; padding: 8px; margin: 8px 0;
    border: 1px solid #ccc; border-radius: 4px;
}
.auth-modal-content button {
    width: 100%; padding: 8px; background: #4285f4; color: white;
    border: none; border-radius: 4px; cursor: pointer;
}
.auth-modal-content button:hover { background: #3367d6; }
.close-modal {
    position: absolute; top: 10px; right: 15px;
    font-size: 24px; cursor: pointer;
}

#register-access-key.invalid { border-color: #e74c3c; background: #fdecea; }
#register-access-key.valid { border-color: #2ecc71; background: #eafaf1; }

/* ===================== МОДАЛКА РЕЗУЛЬТАТОВ ===================== */
.modal-overlay {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.modal-overlay.show { display: flex; }
.modal-inner {
    background: #fff; width: 90%; height: 80%;
    padding: 20px; border-radius: 8px; overflow-y: auto;
}
.modal-close-btn {
    display: block; margin: 10px auto; padding: 8px 20px;
    border: 1px solid #ccc; border-radius: 4px; cursor: pointer; background: #fff;
}
.modal-close-btn:hover { background: #f0f0f0; }

/* ===================== МОДАЛКА АНАЛИТИКИ ===================== */
.analytical-inner {
    background: #fff; width: 90%; max-width: 1000px;
    max-height: 88vh; overflow-y: auto;
    padding: 24px; border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.analytical-inner h2 { color: #2c3e50; }
.analytical-meta { font-size: 12px; color: #7f8c8d; margin-bottom: 12px; }
.analytical-section { margin-top: 14px; }
.analytical-label {
    font-weight: bold; font-size: 13px; color: #34495e;
    margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;
}
.analytical-pre {
    background: #f7f9fa; border: 1px solid #dfe6e9; border-radius: 4px;
    padding: 10px 12px; font-family: 'Courier New', monospace; font-size: 12px;
    overflow-x: auto; white-space: pre-wrap; word-break: break-word;
    color: #2d3436;
}
.analytical-rendered {
    background: #fafbfc; border: 1px solid #dfe6e9; border-radius: 4px;
    padding: 14px 12px; min-height: 40px; overflow-x: auto;
}
.analytical-copy-btn {
    padding: 3px 10px; font-size: 11px; cursor: pointer;
    background: #4285f4; color: #fff; border: none; border-radius: 3px;
}
.analytical-copy-btn:hover { background: #3367d6; }

/* ===================== СЕЛЕКТОРЫ АНАЛИТИКИ ===================== */
.analytical-selectors {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #f7f9fa;
    border: 1px solid #dfe6e9;
    border-radius: 4px;
}
.analytical-selector-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 260px;
    min-width: 0;
}
.analytical-selector-row label {
    font-weight: bold;
    font-size: 12px;
    color: #34495e;
    white-space: nowrap;
}
.analytical-select {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
    cursor: pointer;
}
.analytical-select:focus {
    outline: none;
    border-color: #4285f4;
    box-shadow: 0 0 0 2px rgba(66,133,244,0.2);
}
.analytical-reset-btn {
    padding: 5px 12px;
    font-size: 12px;
    background: #ecf0f1;
    color: #2c3e50;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}
.analytical-reset-btn:hover { background: #bdc3c7; }

/* ===================== ЛЕГЕНДА ===================== */
.analytical-legend {
    background: #fafbfc;
    border: 1px solid #dfe6e9;
    border-radius: 4px;
    padding: 10px 12px;
    max-height: 260px;
    overflow-y: auto;
}
.legend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.legend-table tr { border-bottom: 1px solid #eef2f4; }
.legend-table tr:last-child { border-bottom: none; }
.legend-table td {
    padding: 5px 6px;
    vertical-align: top;
}
.legend-symbol {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #2c3e50;
    white-space: nowrap;
    width: 170px;
    border-right: 1px solid #eef2f4;
}
.legend-desc {
    color: #576574;
    word-break: break-word;
}