* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0066cc;
    --primary-hover: #0052a3;
    --secondary-color: #64748b;
    --bg-color: #e8e8e8;
    --panel-bg: #f5f5f5;
    --card-bg: #ffffff;
    --border-color: #ccc;
    --text-primary: #333;
    --text-secondary: #666;
    --header-bg: #4a90d9;
    --success-color: #10b981;
    --error-color: #ef4444;
    --row-hover: #e6f3ff;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-size: 13px;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.app-header {
    background: linear-gradient(180deg, #5a9fd4 0%, #4a90d9 100%);
    color: white;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-center {
    flex: 1;
    text-align: center;
}

.current-page {
    font-size: 14px;
    font-weight: 500;
}

.btn-icon {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.3);
}

/* Main Layout - 3 Panels */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panel Headers */
.panel-header {
    background: linear-gradient(180deg, #f8f8f8 0%, #e8e8e8 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    font-size: 12px;
}

/* Tree Panel (Left) */
.tree-panel {
    width: 280px;
    min-width: 200px;
    max-width: 400px;
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    resize: horizontal;
    overflow: hidden;
}

.search-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 12px;
    margin-right: 6px;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 10px;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
}

.breadcrumb-item {
    background: #e8e8e8;
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
}

.breadcrumb-item:hover {
    background: var(--primary-color);
    color: white;
}

.breadcrumb-item.active {
    background: var(--primary-color);
    color: white;
}

.tree-container {
    flex: 1;
    overflow-y: auto;
    background: white;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 13px;
}

/* Tree Item - Windows Explorer Style */
.tree-item {
    padding: 3px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: background 0.1s;
    white-space: nowrap;
    user-select: none;
    border-bottom: none;
}

.tree-item:hover {
    background: #e5f3ff;
}

.tree-item.selected {
    background: #cce8ff;
}

/* Arrow indicator */
.tree-arrow {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.tree-arrow.empty {
    visibility: hidden;
}

/* Açık durumda ok aşağı döner */
.tree-arrow.expanded {
    transform: rotate(90deg);
}

.tree-arrow-icon {
    width: 10px;
    height: 10px;
    color: #666;
}

/* Loading spinner for tree items */
.tree-arrow.loading .spinner {
    width: 10px;
    height: 10px;
    border: 2px solid #ddd;
    border-top-color: #666;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* SVG Icons */
.tree-icon-svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-right: 4px;
}

/* Text */
.tree-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #333;
}

/* Folder styling */
.tree-item.folder .tree-text {
    font-weight: normal;
}

/* Book styling (model) */
.tree-item.book .tree-text {
    color: #0066cc;
}

/* Leaf styling (page) */
.tree-item.leaf .tree-text {
    color: #333;
}

.tree-item.leaf:hover .tree-text {
    color: #0066cc;
}

/* Diagram Panel (Center) */
.diagram-panel {
    flex: 1;
    min-width: 300px;
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diagram-title {
    flex: 1;
    font-weight: 500;
}

.diagram-tools {
    display: flex;
    gap: 4px;
}

.diagram-tools .btn-icon {
    background: #e8e8e8;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 2px 6px;
    font-size: 12px;
}

.diagram-container {
    flex: 1;
    overflow: auto;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

/* Diagram wrapper for labels */
.diagram-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%; /* Container küçüldüğünde wrapper da küçülsün */
    line-height: 0; /* img altındaki boşluğu kaldır */
    transition: transform 0.1s ease-out; /* Smooth zoom */
}

.diagram-img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
}

.labels-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    /* JS tarafından boyutlar ayarlanacak */
}

/* Individual label on diagram */
.diagram-label {
    position: absolute;
    transform: translate(-50%, -50%);
    background: #c00;
    color: white;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform 0.15s, background 0.15s;
    z-index: 10;
}

.diagram-label:hover {
    background: #f00;
    transform: translate(-50%, -50%) scale(1.2);
    z-index: 20;
}

/* Blue labels for some items */
.diagram-label.blue {
    background: #0066cc;
}

.diagram-label.blue:hover {
    background: #0088ff;
}

.diagram-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: var(--shadow);
}

/* Parts Panel (Right) */
.parts-panel {
    width: 450px;
    min-width: 300px;
    max-width: 600px;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    resize: horizontal;
    overflow: hidden;
}

.parts-container {
    flex: 1;
    overflow: auto;
    background: white;
}

/* Parts Table */
.parts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.parts-table thead {
    background: linear-gradient(180deg, #f8f8f8 0%, #e8e8e8 100%);
    position: sticky;
    top: 0;
    z-index: 10;
}

.parts-table th {
    padding: 8px 6px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.parts-table td {
    padding: 6px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
}

.parts-table tbody tr:hover {
    background: var(--row-hover);
}

.parts-table tbody tr.highlighted {
    background: #fff3cd !important;
    animation: highlight-pulse 0.5s ease-out;
}

@keyframes highlight-pulse {
    0% { background: #ffc107; }
    100% { background: #fff3cd; }
}

.parts-table .col-no {
    width: 30px;
    text-align: center;
    color: var(--text-secondary);
}

.parts-table .col-number {
    font-family: 'Consolas', 'Courier New', monospace;
    font-weight: 600;
    color: var(--primary-color);
}

.parts-table .col-name {
    min-width: 120px;
}

.parts-table .col-qty {
    width: 40px;
    text-align: center;
}

.parts-table .col-price {
    width: 60px;
    text-align: right;
    font-weight: 500;
}

.parts-table .col-options {
    font-size: 11px;
    color: var(--text-secondary);
}

.parts-table .col-ref {
    font-size: 11px;
    color: var(--text-secondary);
}

.part-row-checkbox {
    width: 20px;
}

.part-row-checkbox input {
    cursor: pointer;
}

/* Part Sign Icons */
.part-sign {
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-right: 4px;
    cursor: help;
}

/* Tooltip styling for sign icons */
.part-sign[title] {
    position: relative;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

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

/* Loading */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error Message */
.error-message {
    background: #fee2e2;
    color: var(--error-color);
    padding: 12px;
    border-radius: 4px;
    margin: 10px;
    border-left: 3px solid var(--error-color);
    font-size: 12px;
}

/* Price styling */
.price-available {
    color: #059669;
    font-weight: 600;
}

.price-unavailable {
    color: #999;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f0f0f0;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Responsive */
@media (max-width: 1200px) {
    .tree-panel {
        width: 220px;
    }
    .parts-panel {
        width: 350px;
    }
}

@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }
    
    .tree-panel,
    .diagram-panel,
    .parts-panel {
        width: 100% !important;
        max-width: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .tree-panel {
        max-height: 200px;
    }
    
    .diagram-panel {
        max-height: 300px;
    }
}
