/* ========== КОНСТРУКТОР СХЕМ ========== */
.schema-builder {
    padding: 120px 0 60px;
    min-height: 100vh;
    background: #f8f9fa;
}

.builder-header {
    text-align: center;
    margin-bottom: 40px;
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.builder-header h1 {
    font-family: 'Montserrat', sans-serif;
    font-size: 36px;
    color: #333;
    margin-bottom: 15px;
}

.builder-header .subtitle {
    color: #666;
    font-size: 18px;
    margin-bottom: 30px;
}

.controls-panel {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 500;
    color: #555;
}

.control-group input {
    width: 80px;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    text-align: center;
    font-size: 16px;
}

.builder-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 30px;
    margin-bottom: 50px;
}

/* Панель инструментов */
.tools-panel {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    height: fit-content;
    position: sticky;
    top: 100px;
}

.tool-section {
    margin-bottom: 30px;
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
}

.tool-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.tool-section h3 {
    font-family: 'Montserrat', sans-serif;
    font-size: 18px;
    margin-bottom: 15px;
    color: #444;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-items {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.tool-btn {
    padding: 12px 8px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: #555;
}

.tool-btn:hover {
    border-color: #ff9800;
    transform: translateY(-2px);
}

.tool-btn.active {
    border-color: #ff9800;
    background: #fff3e0;
    color: #e65100;
}

/* Стили для отображения автоматов в панели */
.breaker-single,
.breaker-double,
.breaker-triple,
.breaker-rcd {
    width: 100%;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
    border-radius: 3px;
    margin-bottom: 5px;
}

.breaker-single {
    background: linear-gradient(135deg, #666, #888);
    color: white;
}

.breaker-double {
    background: linear-gradient(135deg, #666 0%, #888 50%, #666 100%);
    color: white;
    position: relative;
}

.breaker-double::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 5px;
    bottom: 5px;
    width: 1px;
    background: white;
}

.breaker-triple {
    background: linear-gradient(135deg, #666 0%, #888 33%, #666 66%, #888 100%);
    color: white;
    position: relative;
}

.breaker-triple::before,
.breaker-triple::after {
    content: '';
    position: absolute;
    top: 5px;
    bottom: 5px;
    width: 1px;
    background: white;
}

.breaker-triple::before {
    left: 33%;
}

.breaker-triple::after {
    left: 66%;
}

.breaker-rcd {
    background: linear-gradient(135deg, #2196F3, #1976D2);
    color: white;
}

/* Цветовая палитра */
.color-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-btn {
    width: 35px;
    height: 35px;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: #333;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #ff9800;
}

/* Текстовое поле */
#breakerText {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Roboto', sans-serif;
    resize: vertical;
    min-height: 100px;
    line-height: 1.4;
}

#breakerText:focus {
    outline: none;
    border-color: #ff9800;
}

/* Выбор фазы */
.phase-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.phase-btn {
    padding: 10px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.3s ease;
    text-align: center;
}

.phase-btn:hover {
    border-color: #ff9800;
    background: #fff3e0;
}

.phase-btn.active {
    border-color: #ff9800;
    background: #fff3e0;
    color: #e65100;
}

/* Кнопки действий */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-primary,
.btn-success,
.btn-danger {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #FF9800, #FF5722);
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, #f44336, #c62828);
    color: white;
}

.btn-primary:hover,
.btn-success:hover,
.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

/* Холст для схемы */
.schema-canvas-container {
    background: white;
    border-radius: 15px;
    padding: 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    min-height: 500px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-header {
    padding: 20px 25px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
}

.canvas-header h3 {
    font-family: 'Montserrat', sans-serif;
    font-size: 20px;
    color: #333;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.canvas-info {
    color: #666;
    font-size: 14px;
}

.canvas-wrapper {
    flex: 1;
    padding: 20px;
    overflow: auto;
    position: relative;
}

/* ТАБЛИЦА - ОСНОВНОЙ ЭЛЕМЕНТ */
.schema-table {
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0 auto;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    min-width: 800px;
}

.schema-table td {
    border: 1px solid #ddd;
    width: 80px;
    height: 80px;
    text-align: center;
    vertical-align: middle;
    padding: 0;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    box-sizing: border-box;
}

.schema-table td:hover {
    background: #f8f9fa;
    border-color: #ff9800;
}

/* Модули в таблице */
.grid-module {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: space-between;
    position: relative;
    padding: 5px;
    box-sizing: border-box;
    border-radius: 4px;
    overflow: hidden;
}

/* Объединенные ячейки (для 2P и 3P) */
.grid-module[data-width="2"] {
    margin-left: 0;
    margin-right: 0;
}

.grid-module[data-width="3"] {
    margin-left: 0;
    margin-right: 0;
}

/* Типы модулей */
.grid-module.single {
    border: 2px solid #333;
}

.grid-module.rcd {
    border: 2px solid #2196F3;
}

/* Содержимое модуля */
.module-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;
    font-size: 12px;
    line-height: 1.3;
    overflow: hidden;
    word-break: break-word;
    text-align: left;
    width: 100%;
}

.module-text {
    width: 100%;
    max-height: 60px;
    overflow-y: auto;
    text-align: left;
    padding: 0 2px;
    margin-bottom: 4px;
}

.module-text::-webkit-scrollbar {
    width: 3px;
}

.module-text::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.module-text::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 2px;
}

/* Бейдж фазы */
.phase-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 10px;
    font-weight: bold;
    color: #333;
    z-index: 2;
    min-width: 20px;
    text-align: center;
}

/* Индекс ячейки */
.cell-index {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 10px;
    color: #888;
    font-weight: bold;
    z-index: 1;
}

/* Цвет фона для ячеек с модулями */
.schema-table td.has-module {
    background: #f8f9fa;
}

/* Пустое состояние */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #999;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 20px;
    color: #ddd;
}

.empty-state p {
    font-size: 18px;
}

/* Инструкция */
.instructions {
    margin-top: 60px;
    padding: 30px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    max-width: 1050px;
    margin-left: auto;
    margin-right: auto;
}

.instructions h2 {
    font-family: 'Montserrat', sans-serif;
    font-size: 28px;
    margin-bottom: 30px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.instructions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
}

.instruction-card {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 10px;
    border-left: 4px solid #ff9800;
}

.instruction-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #FF9800, #FF5722);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.instruction-icon i {
    color: white;
    font-size: 24px;
}

.instruction-card h3 {
    font-family: 'Montserrat', sans-serif;
    font-size: 18px;
    margin-bottom: 10px;
    color: #333;
}

.instruction-card p {
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

/* Адаптивность */
@media (max-width: 1200px) {
    .builder-container {
        grid-template-columns: 300px 1fr;
    }

    .schema-table {
        min-width: 700px;
    }
}

@media (max-width: 992px) {
    .builder-container {
        grid-template-columns: 1fr;
    }

    .tools-panel {
        position: static;
        margin-bottom: 30px;
    }

    .schema-table {
        min-width: auto;
        width: 100%;
    }

    .schema-table td {
        width: 60px;
        height: 70px;
    }
}

@media (max-width: 768px) {
    .controls-panel {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .control-group {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .tool-items {
        grid-template-columns: repeat(3, 1fr);
    }

    .instructions-grid {
        grid-template-columns: 1fr;
    }

    .builder-header h1 {
        font-size: 28px;
    }

    .schema-table td {
        width: 50px;
        height: 60px;
    }

    .module-content {
        font-size: 10px;
        padding: 3px;
    }

    .phase-badge {
        font-size: 8px;
        padding: 0 2px;
        min-width: 16px;
    }

    .cell-index {
        font-size: 8px;
    }
}

@media (max-width: 480px) {
    .tool-items {
        grid-template-columns: repeat(2, 1fr);
    }

    .color-picker {
        grid-template-columns: repeat(4, 1fr);
    }

    .phase-selector {
        grid-template-columns: repeat(2, 1fr);
    }

    .schema-table td {
        width: 45px;
        height: 55px;
    }

    .module-content {
        font-size: 9px;
    }
}

/* Добавь в существующие стили таблицы */
.schema-table {
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0 auto;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    min-width: 800px;
    table-layout: fixed !important;
    /* Важно! */
}

.schema-table td {
    border: 1px solid #ddd;
    width: 80px;
    height: 80px;
    text-align: center;
    vertical-align: middle;
    padding: 0;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    box-sizing: border-box;
    overflow: hidden !important;
    /* Важно! */
}

/* Для ячеек с модулями */
.schema-table td.has-module {
    overflow: visible !important;
    /* Разрешаем видимость для абсолютно позиционированных модулей */
}

/* Обновленные стили модулей */
.grid-module {
    position: absolute !important;
    top: 0;
    left: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: space-between;
    padding: 5px;
    box-sizing: border-box;
    border-radius: 4px;
    height: 100%;
    pointer-events: none;
    /* Чтобы не мешали кликам */
}

/* Остальные стили остаются прежними... */