/* === ГЛОБАЛЬНЫЕ СТИЛИ === */
body { margin: 0; padding: 0; font-family: sans-serif; background: #111827; color: #e5e7eb; overflow: hidden; height: 100vh; }

/* === ГЛОБАЛЬНОЕ МЕНЮ === */
#top-nav {
    height: 40px;
    background: #1f2937;
    border-bottom: 1px solid #374151;
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}
.nav-brand { font-weight: bold; color: #60a5fa; margin-right: 30px; font-size: 14px; letter-spacing: 1px; }
.nav-links { display: flex; gap: 10px; }
.nav-btn {
    color: #d1d5db;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 12px;
    background: #374151;
    transition: 0.2s;
    border: 1px solid transparent;
}
.nav-btn:hover { background: #4b5563; color: #fff; }
.nav-btn.active { background: #2563eb; color: #fff; border-color: #3b82f6; }

#main-container {
    margin-top: 40px; /* Высота меню */
    height: calc(100vh - 40px);
    position: relative;
    overflow-y: auto; /* Добавляем прокрутку для страниц контента */
}

/* === СТИЛИ ЛАБОРАТОРИИ === */

/* Левая панель */
#sidebar { width: 280px; background:#1f2937; padding:0; display:flex; flex-direction: column; z-index: 10; border-right: 1px solid #374151; flex-shrink: 0; height: 100%; box-sizing: border-box; }
.sidebar-header { padding: 10px; border-bottom: 1px solid #374151; flex-shrink: 0; }
h3 { margin:0 0 10px 0; font-size:14px; color:#9ca3af; }
#search-box { width: 100%; box-sizing: border-box; padding: 6px; background: #111827; border: 1px solid #374151; border-radius: 4px; color: white; font-size: 12px; }
.atom-list-container { flex: 1; overflow-y: auto; padding: 0 5px 5px 5px; }
.atom-group { margin-top: 10px; }
.group-header { font-size: 10px; text-transform: uppercase; color: #9ca3af; padding: 4px 5px; border-bottom: 1px solid #374151; margin-bottom: 4px; }
.atom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.atom-item-compact { display: flex; align-items: center; background:#374151; cursor:grab; padding: 6px 6px; border-radius: 3px; transition: 0.2s; overflow: hidden; border-left: 3px solid transparent; }
.atom-item-compact:hover { background:#4b5563; }
.atom-sym { font-weight:bold; font-size: 11px; pointer-events: none; margin-right: 4px; }
.atom-name { flex: 1; font-size: 9px; color: #d1d5db; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.is-candidate { border-left-color: #f59e0b !important; }

/* Правая панель */
#inspector { width: 260px; background:#1f2937; padding:15px; border-left:1px solid #374151; display:flex; flex-direction: column; z-index: 10; overflow-y: hidden; height: 100%; flex-shrink: 0; box-sizing: border-box; }
.toolbar { padding: 10px 0; display: flex; gap: 10px; flex-wrap: wrap; flex-shrink: 0; }
.btn-action { padding: 5px 10px; background: #2563eb; border-radius: 4px; font-size: 12px; cursor: pointer; border: none; color: white; }
.btn-action:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-action.danger { background: #dc2626; }
.btn-action.success { background: #16a34a; }
.btn-action.purple { background: #7c3aed; }
#inspector-content { flex-shrink: 0; padding-bottom: 10px; }
#analyzer-section { margin-top:10px; border-top:1px solid #374151; padding-top:10px; flex-shrink: 0; }
#text-input { width:100%; height:60px; background:#111827; border:1px solid #374151; color:white; border-radius:4px; padding:5px; resize:none; font-size: 12px; box-sizing: border-box; }
#analysis-result { margin-top:10px; font-size:11px; max-height: 150px; overflow-y: auto; }
#monitor-section { flex: 1; display: flex; flex-direction: column; margin-top: 10px; border-top: 1px solid #374151; padding-top: 10px; overflow: hidden; }
#monitor-log { flex: 1; overflow-y: auto; margin-top: 5px; background: rgba(0,0,0,0.2); border-radius: 4px; padding: 5px; }
.log-entry { font-size: 11px; padding: 4px; border-bottom: 1px solid #374151; }
.log-entry .time { color: #6b7280; margin-right: 5px; }
.log-entry .text { color: #d1d5db; }

/* Основная область */
#main-area { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    position: relative; 
    overflow: hidden; 
    background: #111827;
    height: 100%; 
}

/* Канвас */
#canvas { 
    flex: 1; 
    position:relative; 
    overflow:hidden; 
    background-color: #111827; 
    background-image: radial-gradient(circle, #374151 1px, transparent 1px); 
    background-size: 25px 25px; 
    cursor: grab; 
    min-height: 100px; 
    z-index: 1;
}
#canvas.panning { cursor: grabbing; }
#canvas.selecting { cursor: crosshair; }

#connections-svg { position: absolute; top:0; left:0; width:100%; height:100%; pointer-events: none; z-index: 5; overflow: visible; }
.conn-line { stroke: #94a3b8; stroke-width: 2px; fill: none; opacity: 0.8; stroke-linecap: round; }
.conn-line.temp { stroke: #ef4444; stroke-dasharray: 5,5; opacity: 0.9; }

#transform-layer { width: 100%; height: 100%; position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; z-index: 2; }
#nodes-layer { position: relative; width: 100%; height: 100%; }

#selection-box { position: absolute; background: rgba(59, 130, 246, 0.2); border: 1px solid #3b82f6; pointer-events: none; z-index: 1000; display: none; }

/* Узел */
.node {
    position: absolute; width: 200px; background: #1f2937; border-radius: 6px;
    border: 2px solid #4b5563; box-shadow: 0 4px 6px rgba(0,0,0,0.3); 
    user-select: none; display: flex; flex-direction: column;
    transition: box-shadow 0.2s;
}
.node.selected { box-shadow: 0 0 15px rgba(59, 130, 246, 0.6); border-color: #3b82f6; }
.node.is-group, .node.is-molecule { border-style: dashed; border-width: 2px; background: rgba(31, 41, 55, 0.8); }
.node.is-group.opened, .node.is-molecule.opened { background: rgba(16, 185, 129, 0.05); border-color: #10b981; }

.node-header { background: #374151; padding: 5px 8px; border-radius: 4px 4px 0 0; display: flex; justify-content: space-between; align-items: center; cursor: move; min-height: 28px; }
.node-title { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.node-symbol { font-weight: bold; font-size: 14px; flex-shrink: 0; }
.node-analog { font-size: 9px; color: #9ca3af; background: #111827; padding: 1px 4px; border-radius: 3px; white-space: nowrap; }

.header-actions { display: flex; gap: 4px; flex-shrink: 0; }
.header-btn { width: 18px; height: 18px; border-radius: 3px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 10px; border: 1px solid rgba(255,255,255,0.1); }
.btn-delete { background: #991b1b; color: #fca5a5; }
.btn-toggle { background: #2563eb; color: white; }
.btn-reset { background: #374151; color: #9ca3af; }

.node-body { padding: 4px; font-size: 11px; position: relative; max-height: 250px; overflow-y: auto; }

.layer-section { margin-bottom: 4px; border-bottom: 1px solid #374151; }
.layer-header { font-size: 9px; color: #6b7280; margin: 2px 0; display: flex; justify-content: space-between; align-items: center; }
.valence-meter { font-size: 9px; color: #fbbf24; }
.valence-meter.full { color: #ef4444; font-weight: bold; }
.desc-row { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; margin: 1px 0; background: rgba(0,0,0,0.2); border-radius: 3px; position: relative; }
.desc-name { flex: 1; margin: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10px; color: #d1d5db; }
.move-btn { background: #374151; color: #9ca3af; border: none; border-radius: 3px; padding: 0px 4px; font-size: 9px; cursor: pointer; margin-left: 2px; line-height: 1.2; }
.move-btn:hover { background: #4b5563; color: white; }
.move-btn.warn { background: #991b1b; color: white; }

.port {
    width: 12px; height: 12px; border-radius: 50%; background: #4b5563; 
    border: 2px solid #1f2937; cursor: crosshair; z-index: 6; transition: all 0.2s; flex-shrink: 0;
}
.port:hover { transform: scale(1.3); border-color: #fff; }
.port.output { background: #ef4444; box-shadow: 0 0 5px #ef4444; border-color: #ef4444; }
.port.input { background: #3b82f6; box-shadow: 0 0 5px #3b82f6; border-color: #3b82f6; }

.structure-list { font-size: 10px; padding: 4px; }
.structure-item { display: flex; justify-content: space-between; padding: 1px 0; border-bottom: 1px dotted #374151; }

/* Склад Молекул */
#palette-bar {
    height: 140px;
    background: #0f172a;
    border-top: 2px solid #334155;
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}
.palette-header {
    padding: 4px 15px;
    font-size: 11px;
    color: #94a3b8;
    border-bottom: 1px solid #1e293b;
    background: #1e293b;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.palette-content {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0 10px;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
}
.molecule-card {
    min-width: 80px;
    height: 90px;
    background: #1e2937;
    border: 1px solid #4b5563;
    border-radius: 6px;
    padding: 4px;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    border-left-width: 3px;
    border-left-style: solid;
}
.molecule-card:hover {
    border-color: #3b82f6;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.molecule-card .sym { font-weight: bold; font-size: 14px; color: #fff; margin-bottom: 2px; }
.molecule-card .name { font-size: 9px; color: #9ca3af; text-align: center; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#toast { position: fixed; bottom: 160px; left: 50%; transform: translateX(-50%); background: #1f2937; border: 1px solid #fbbf24; color: #fbbf24; padding: 10px 20px; border-radius: 6px; display: none; z-index: 9999; }

/* === СТИЛИ ТАБЛИЦЫ ПТЭИ === */
.table-container { padding: 20px; height: 100%; overflow-y: auto; box-sizing: border-box; }
.table-container h1 { color: #60a5fa; margin-bottom: 20px; font-size: 24px; }
.grid-table {
    display: grid;
    grid-template-columns: repeat(18, 60px);
    gap: 2px;
    background: #1f2937;
    padding: 10px;
    border-radius: 8px;
    width: fit-content;
}
.element-cell {
    background: #374151;
    border: 1px solid #4b5563;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    border-radius: 4px;
    position: relative;
}
.element-cell:hover { background: #4b5563; transform: scale(1.1); z-index: 10; border-color: #9ca3af; }
.element-cell.empty { background: transparent; border: none; cursor: default; }
.element-cell.empty:hover { transform: none; }

.el-num { font-size: 10px; color: #9ca3af; position: absolute; top: 2px; left: 4px; }
.el-sym { font-weight: bold; font-size: 16px; }
.el-name { font-size: 8px; color: #d1d5db; }