/* ===== RESET & VARIABLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2c3e50;
    --primary-light: #34495e;
    --secondary: #3498db;
    --secondary-light: #5dade2;
    --border: #dee2e6;
    --bg-light: #f8f9fa;
    --bg-hover: #e9ecef;
    --text: #212529;
    --text-muted: #6c757d;
    --font-size: 11px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Arial', sans-serif;
    --header-height: 60px;
    --footer-height: 36px;
    --sidebar-width: 600px;
    --diagram-height: 400px;
    --table-height: 40%;
}

/* ===== BASE STYLES ===== */
html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size);
    line-height: 1.45;
    color: var(--text);
    background-color: #f0f2f5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== APP LAYOUT ===== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 1440px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.08);
}

/* ===== HEADER ===== */
.header {
    height: var(--header-height);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    flex-shrink: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 350px;
}

.logo-img {
    height: 40px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

.logo-text-fallback {
    font-family: var(--font-family);
    font-size: 18px;
    font-weight: bold;
    background: rgba(255,255,255,0.2);
    padding: 6px 12px;
    border-radius: 6px;
}

.logo-text {
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    color: white;
}

/* ===== SEARCH ===== */
.search-container {
    position: relative;
    flex: 1;
    max-width: 450px;
}

#search-input {
    width: 100%;
    padding: 8px 16px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 30px;
    font-family: var(--font-family);
    font-size: 11px;
    background: rgba(255,255,255,0.15);
    color: white;
}

#search-input::placeholder {
    font-family: var(--font-family);
    color: rgba(255,255,255,0.7);
}

#search-input:focus {
    outline: none;
    background: white;
    color: var(--text);
    border-color: var(--secondary);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 6px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: 0 12px 24px rgba(0,0,0,0.12);
}

/* ===== MAIN LAYOUT ===== */
.main {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: white;
}

/* ===== LEFT SIDEBAR ===== */
.nodes-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-light);
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 16px 20px;
    background: white;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 5;
}

.sidebar-header h3 {
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.nodes-count {
    font-family: var(--font-family);
    background: var(--primary);
    color: white;
    padding: 5px 14px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 700;
}

.sidebar-search {
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
}

#sidebar-search-input {
    width: 100%;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 30px;
    font-family: var(--font-family);
    font-size: 11px;
    background: var(--bg-light);
}

#sidebar-search-input::placeholder {
    font-family: var(--font-family);
    color: var(--text-muted);
}

.nodes-list {
    list-style: none;
    padding: 12px;
    margin: 0;
    flex: 1;
}

.node-item {
    padding: 8px 14px;
    margin-bottom: 6px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.15s ease;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    min-height: 36px;
}

.node-item:hover {
    background: white;
    border-color: var(--secondary-light);
    box-shadow: 0 2px 6px rgba(52,152,219,0.08);
    transform: translateY(-1px);
}

.node-item.active {
    background: linear-gradient(135deg, var(--secondary) 0%, #2980b9 100%);
    border-color: var(--secondary);
    color: white;
    box-shadow: 0 4px 10px rgba(52,152,219,0.2);
}

.node-info {
    flex: 1;
    margin-right: 10px;
}

.node-name {
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 12px;
    line-height: 1.3;
    display: block;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.node-item.active .node-name {
    color: white;
}

.node-badges {
    display: flex;
    align-items: center;
    gap: 4px;
}

.node-parts-badge {
    font-family: var(--font-family);
    background: var(--secondary);
    color: white;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    min-width: 35px;
    text-align: center;
    line-height: 1.2;
}

.node-item.active .node-parts-badge {
    background: rgba(255,255,255,0.25);
    color: white;
}

.node-item.empty {
    cursor: default;
    background: transparent;
    border: 1px dashed var(--border);
    justify-content: center;
    padding: 20px;
}

.empty-message {
    font-family: var(--font-family);
    color: var(--text-muted);
    font-style: italic;
    font-size: 12px;
}

.sidebar-footer {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid var(--border);
    font-family: var(--font-family);
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
}

/* ===== RIGHT PANEL ===== */
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: calc(1440px - 600px);
}

/* ===== DIAGRAM SECTION ===== */
.diagram-section {
    height: var(--diagram-height);
    background: linear-gradient(135deg, #f5f7fa 0%, #fafbfc 100%);
    border-bottom: 2px solid var(--border);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.diagram-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#node-diagram {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: pointer;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}

.no-diagram-text {
    font-family: var(--font-family);
    color: var(--text-muted);
    font-size: 14px;
    padding: 30px;
    background: white;
    border-radius: 12px;
    border: 2px dashed var(--border);
}

.loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.98);
    padding: 16px 28px;
    border-radius: 40px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
}

.loading-indicator span {
    font-family: var(--font-family);
    font-size: 12px;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}



/* ===== PARTS TABLE ===== */
.parts-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
    height: var(--table-height);
}

.parts-table-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
}

.parts-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-family);
    font-size: 11px;
    min-width: 700px;
    table-layout: fixed;
}

.parts-table th {
    position: sticky;
    top: 0;
    background: var(--bg-light);
    padding: 6px 4px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    font-family: var(--font-family);
    font-weight: 700;
    color: var(--primary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    z-index: 10;
}

.parts-table td {
    padding: 2px 3px !important;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.2;
}

.parts-table td:nth-child(3) {
    word-break: break-word;
    padding-right: 2px !important;
    padding-left: 2px !important;
}

.parts-table td:nth-child(4) {
    padding-left: 0px !important;
    padding-right: 2px !important;
    width: 45px;
    text-align: center;
}

.position-number {
    display: inline-block;
    background: var(--secondary);
    color: white;
    font-family: var(--font-family);
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 10px;
    font-size: 9px;
    min-width: 30px;
    text-align: center;
    line-height: 1.2;
    margin: 0;
}

.position-number.empty {
    background: var(--text-muted);
    opacity: 0.6;
}

.parts-table td:nth-child(2) {
    font-family: var(--font-family);
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
    font-size: 12px;
    padding-left: 2px !important;
}

.part-thumbnail {
    width: 35px;
    height: 35px;
    object-fit: cover;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid var(--border);
    margin: 0;
    display: block;
}

.no-photo {
    font-family: var(--font-family);
    color: var(--text-muted);
    font-style: italic;
    font-size: 9px;
    cursor: pointer;
    padding: 1px 2px;
    background: var(--bg-light);
    border-radius: 2px;
    display: inline-block;
    line-height: 1.1;
    margin: 0;
}

.table-placeholder {
    text-align: center;
    padding: 20px !important;
    color: var(--text-muted);
    background: var(--bg-light);
}

.placeholder-icon {
    font-size: 24px;
    display: block;
    margin-bottom: 8px;
    opacity: 0.5;
}

.placeholder-text {
    font-family: var(--font-family);
    font-size: 11px;
    display: block;
}

.parts-table tbody tr.has-coords {
    border-left: 3px solid #27ae60;
}

.parts-table tbody tr.highlight {
    background-color: rgba(52, 152, 219, 0.15) !important;
    border-left: 4px solid #3498db;
    border-right: 4px solid #3498db;
}

.parts-table tbody tr.highlight-active {
    background-color: rgba(46, 204, 113, 0.15) !important;
    border-left: 4px solid #2ecc71;
    border-right: 4px solid #2ecc71;
}

@keyframes highlightPulse {
    0% { background-color: rgba(46, 204, 113, 0.15); }
    50% { background-color: rgba(46, 204, 113, 0.3); }
    100% { background-color: rgba(46, 204, 113, 0.15); }
}

.parts-table tbody tr.highlight-new {
    animation: highlightPulse 1s ease 2;
}

/* ===== MODAL ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    backdrop-filter: blur(8px);
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    background: white;
    padding: 25px;
    border-radius: 16px;
    max-width: 95%;
    max-height: 95%;
    overflow: auto;
    display: flex;
    flex-direction: row;
    gap: 25px;
    width: auto;
    min-width: 600px;
}

.modal-close {
    position: absolute;
    right: 16px;
    top: 12px;
    background: none;
    border: none;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    z-index: 10;
}

.modal-close:hover {
    background: #f0f0f0;
    color: #000;
}

/* ===== MODAL IMAGE SECTION ===== */
.modal-image-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.modal-image-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f8f9fa;
    border-radius: 10px;
    padding: 10px;
    min-height: 200px;
}

#modal-image {
    border-radius: 8px;
    object-fit: contain;
}

/* Схема - с ограничением */
#modal-image[alt*="Схема"] {
    max-width: 90vw;
    max-height: 70vh;
    width: auto;
    height: auto;
}

/* Фото детали - без ограничений */
#modal-image:not([alt*="Схема"]) {
    max-width: none !important;
    max-height: none !important;
    width: auto;
    height: auto;
    cursor: pointer;
}

.modal-image-caption {
    margin-top: 12px;
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
    text-align: center;
}

/* ===== МАРКЕРЫ В МОДАЛЬНОМ ОКНЕ ===== */
.modal-marker {
    position: absolute;
    width: 20px;
    height: 20px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    cursor: pointer;
    z-index: 200;
    pointer-events: auto;
    transform: translate(-50%, -50%);
}

/* ===== MODAL PARTS SECTION ===== */
.modal-parts-section {
    width: 400px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    padding-left: 20px;
}

.modal-parts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-parts-header h4 {
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
    text-transform: uppercase;
}

.modal-parts-count {
    font-family: var(--font-family);
    background: var(--secondary);
    color: white;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}

.modal-parts-list {
    flex: 1;
    overflow-y: auto;
    max-height: 60vh;
    padding-right: 5px;
}

/* ===== MODAL PARTS TABLE ===== */
.modal-parts-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-family);
    font-size: 11px;
    table-layout: fixed;
}

.modal-parts-table th {
    padding: 8px 6px;
    background: var(--bg-light);
    border-bottom: 2px solid var(--border);
    font-family: var(--font-family);
    font-weight: 700;
    color: var(--primary);
    font-size: 11px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 150;
}

.modal-parts-table td {
    padding: 6px 6px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: middle;
    font-family: var(--font-family);
    font-size: 11px;
}

.modal-parts-table td:nth-child(3) {
    word-break: break-word;
}

.modal-parts-table td:nth-child(4) {
    text-align: center;
    width: 45px;
}

.modal-parts-table tbody tr:hover {
    background: #f1f9ff;
}

.modal-parts-table tbody tr[style*="border-left: 3px solid #27ae60"] {
    border-left: 3px solid #27ae60;
}

.modal-highlight {
    background-color: rgba(52, 152, 219, 0.15) !important;
    border-left: 4px solid #3498db !important;
}

.modal-part-thumbnail {
    width: 35px;
    height: 35px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
    display: block;
    margin: 0 auto;
}

.modal-no-photo {
    font-family: var(--font-family);
    color: var(--text-muted);
    font-size: 10px;
    font-style: italic;
}

/* ===== FOOTER ===== */
.footer {
    height: var(--footer-height);
    background: var(--bg-light);
    border-top: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    font-family: var(--font-family);
    font-size: 11px;
    color: var(--text-muted);
}

.footer-left, .footer-center, .footer-right {
    flex: 1;
}

.footer-center {
    text-align: center;
}

.footer-right {
    text-align: right;
}

.footer-version {
    font-family: var(--font-family);
    color: #adb5bd;
}

/* ===== SEARCH RESULTS ===== */
.search-result-item {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 11px;
    transition: background 0.15s;
    color: var(--text);
}

.search-result-item:hover {
    background: #f0f7ff;
}

.search-result-item strong {
    font-family: var(--font-family);
    color: var(--secondary);
    font-weight: 700;
    font-size: 11px;
}

.search-result-item small {
    font-family: var(--font-family);
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
    font-size: 10px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ===== HINTS ===== */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(10px); }
    10% { opacity: 1; transform: translateY(0); }
    90% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

.diagram-hint,
.modal-hint {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: bold;
    z-index: 250;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    pointer-events: none;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.2);
    animation: fadeInOut 3s ease;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1400px) {
    :root {
        --sidebar-width: 550px;
        --diagram-height: 380px;
    }
}

@media (max-width: 1200px) {
    :root {
        --sidebar-width: 500px;
        --diagram-height: 350px;
    }
}

@media (max-width: 992px) {
    :root {
        --sidebar-width: 450px;
        --diagram-height: 320px;
    }
}

@media (max-width: 768px) {
    .main {
        flex-direction: column;
    }
    
    .nodes-sidebar {
        width: 100%;
        max-height: 350px;
    }
    
    .right-panel {
        width: 100%;
        height: calc(100% - 350px);
    }
    
    :root {
        --sidebar-width: 100%;
        --diagram-height: 300px;
    }
    
    .modal-content {
        flex-direction: column;
        min-width: auto;
        width: 95%;
    }
    
    .modal-parts-section {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-left: 0;
        padding-top: 20px;
        margin-top: 10px;
    }
    
    .diagram-marker {
        width: 25px;
        height: 25px;
        font-size: 10px;
    }
    
    .modal-marker {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }
}