/* Design Tokens & CSS Variables */
:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(51, 65, 85, 0.8);
    --glass-bg: rgba(15, 23, 42, 0.75);
    --glass-border: rgba(255, 255, 255, 0.1);
    
    --primary: #38bdf8;
    --primary-hover: #0284c7;
    --secondary: #818cf8;
    --accent: #f43f5e;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    
    --border-color: #334155;
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --font-family: 'Inter', 'Rubik', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body, html {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
}

#app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* Glassmorphism Common Class */
.glass-pane {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

#app-header, #top-navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    padding: 0 24px;
    background: rgba(15, 23, 42, 0.9);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-logos {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo {
    height: 42px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.logo-icon {
    font-size: 22px;
}

.brand h1 {
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.version-badge {
    font-size: 10px;
    background: rgba(56, 189, 248, 0.15);
    color: var(--primary);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
}

.btn-xs {
    padding: 4px 8px;
    font-size: 11px;
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7, #2563eb);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0369a1, #1d4ed8);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(51, 65, 85, 0.8);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(71, 85, 105, 0.9);
}

.btn-outline {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--primary);
}

/* Main Dual Pane Content */
#main-content {
    display: flex;
    flex: 1;
    height: calc(100vh - 56px);
    overflow: hidden;
    position: relative;
}

/* Left/Data Pane (Responsive Proportional Width, Max 600px) */
#data-pane {
    width: 38vw;
    min-width: 320px;
    max-width: 600px;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    z-index: 10;
}

html[dir="rtl"] #data-pane {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pane-header h2 {
    font-size: 16px;
    font-weight: 600;
}

/* Badges */
.badge {
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 12px;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Tab Content Container Scoping */
#tab-content-coordination {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    gap: 8px;
}

.mc-visibility-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px;
    gap: 12px;
}

.mc-checkboxes-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.matrix-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.coordination-footer {
    flex-shrink: 0;
}
.filter-section {
    background: var(--bg-card);
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 12px;
    color: var(--text-muted);
}

.filter-group select {
    width: 100%;
    padding: 8px 10px;
    background: #0f172a;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    font-family: inherit;
    font-size: 13px;
    transition: border-color 0.2s ease;
}

.filter-group select:focus:not(:disabled) {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.filter-group select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Statistics Card */
.stats-card {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* CSV Files Summary */
.csv-files-summary {
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.csv-files-summary h4 {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.file-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 100px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    padding: 4px 8px;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 4px;
}

.file-item .file-name {
    color: var(--primary);
    font-family: monospace;
}

.file-item .file-count {
    color: var(--text-dim);
}

.empty-file-item {
    font-size: 11px;
    color: var(--text-dim);
    font-style: italic;
}

/* Table Container */
.elements-table-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    min-height: 200px;
}

.elements-table-container h4 {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.table-wrapper {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

table, .coord-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

html[dir="rtl"] table, html[dir="rtl"] .coord-table {
    text-align: right;
}

/* Matrix Category Columns: 80px fixed width each */
.coord-table th:nth-child(2),
.coord-table th:nth-child(3),
.coord-table th:nth-child(4),
.coord-table th:nth-child(5),
.coord-table td:nth-child(2),
.coord-table td:nth-child(3),
.coord-table td:nth-child(4),
.coord-table td:nth-child(5) {
    width: 80px !important;
    min-width: 80px !important;
    max-width: 80px !important;
    text-align: center !important;
}

/* Matrix Space Name Column: Fits remaining width of the 600px container */
.coord-table th:first-child,
.coord-table td:first-child {
    width: auto !important;
    text-align: left !important;
}

html[dir="rtl"] .coord-table th:first-child,
html[dir="rtl"] .coord-table td:first-child {
    text-align: right !important;
}

th {
    position: sticky;
    top: 0;
    background: #1e293b;
    color: var(--primary);
    padding: 8px 10px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
}

td {
    padding: 6px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

tr:hover td {
    background: var(--bg-card-hover);
}

tr.selected td {
    background: rgba(56, 189, 248, 0.2);
    color: #ffffff;
}

.no-data-cell {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
    font-style: italic;
}

/* Range Filter Box & Dual Slider */
.coordination-footer {
    padding: 12px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.range-filter-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(15, 23, 42, 0.6);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.range-inputs {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
}

.range-inputs input[type="number"] {
    width: 45px;
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: var(--primary);
    border-radius: 4px;
    padding: 2px 4px;
    font-size: 11px;
    text-align: center;
}

.dual-slider-wrapper {
    position: relative;
    width: 100%;
    height: 20px;
    display: flex;
    align-items: center;
}

.slider-track {
    position: absolute;
    width: 100%;
    height: 6px;
    background: linear-gradient(to right, #334155 0%, #38bdf8 0%, #38bdf8 100%, #334155 100%);
    border-radius: 3px;
    z-index: 1;
}

.dual-slider-wrapper input[type="range"] {
    position: absolute;
    width: 100%;
    height: 6px;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    z-index: 2;
    margin: 0;
}

.dual-slider-wrapper input[type="range"]::-webkit-slider-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    pointer-events: auto;
    -webkit-appearance: none;
    cursor: pointer;
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    border: 2px solid #ffffff;
}

.dual-slider-wrapper input[type="range"]::-moz-range-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    pointer-events: auto;
    cursor: pointer;
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    border: 2px solid #ffffff;
}

/* Split Resizer */
#pane-resizer {
    width: 6px;
    background: rgba(255, 255, 255, 0.05);
    cursor: col-resize;
    transition: background 0.2s;
}

#pane-resizer:hover, #pane-resizer.active {
    background: var(--primary);
}

/* Right/3D Viewer Pane (Default 60%) */
#viewer-pane {
    flex: 1;
    height: 100%;
    position: relative;
    background-color: #0b0f19;
}

#canvas-container {
    width: 100%;
    height: 100%;
}

#canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* 3D Controls & Hierarchy Overlay Bar Container */
#viewer-toolbar-container {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 20;
    flex-wrap: nowrap;
    white-space: nowrap;
    max-width: calc(100% - 32px);
}

html[dir="rtl"] #viewer-toolbar-container {
    left: auto;
    right: 16px;
}

/* Action Buttons Container (With Glass Frame) */
#viewer-toolbar {
    position: relative;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    z-index: 20;
    width: auto;
    white-space: nowrap;
    flex-wrap: nowrap;
}

/* Separate Hierarchy Filters Container (With Glass Frame) */
#viewer-hierarchy-toolbar {
    position: relative;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    z-index: 20;
    width: auto;
    white-space: nowrap;
    flex-wrap: nowrap;
}

#viewer-hierarchy-toolbar select {
    height: 30px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 500;
    color: #f8fafc;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    max-width: 160px;
}

#viewer-hierarchy-toolbar select:hover:not(:disabled) {
    border-color: #38bdf8;
    background: rgba(51, 65, 85, 0.95);
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.3);
}

#viewer-hierarchy-toolbar select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Single Sub-project/Floor Checkbox Label in Hierarchy Toolbar */
.checkbox-filter-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.checkbox-filter-label:hover {
    color: var(--text-main);
}

.checkbox-filter-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 3px;
    background: rgba(30, 41, 59, 0.85);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
}

.checkbox-filter-label input[type="checkbox"]:hover {
    border-color: var(--primary);
}

.checkbox-filter-label input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.4);
}

.checkbox-filter-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 1px;
    width: 5px;
    height: 8px;
    border: 2px solid #0f172a;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

.checkbox-filter-label:has(input:checked) {
    color: var(--primary);
}

.toolbar-dropdown-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-dropdown-group select {
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 500;
    color: #f8fafc;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    max-width: 140px;
}

.toolbar-dropdown-group select:hover:not(:disabled) {
    border-color: #38bdf8;
    background: rgba(51, 65, 85, 0.95);
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.3);
}

.toolbar-dropdown-group select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 2px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Segmented Control Switch */
.segmented-control {
    display: inline-flex;
    background: #0f172a;
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.segmented-control button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.segmented-control button.active {
    background: var(--primary);
    color: #0f172a;
    font-weight: 600;
}

/* Floating Category Color Customizer Panel */
.floating-panel {
    position: absolute;
    top: 64px;
    right: 16px;
    width: 280px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 30;
    padding: 12px;
}

html[dir="rtl"] .floating-panel {
    right: auto;
    left: 16px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h4 {
    font-size: 13px;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
}

.close-btn:hover {
    color: var(--accent);
}

.color-list-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.color-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
}

.color-row input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
}

.color-row input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-row input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 50%;
}

.panel-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
}

#tooltip-3d {
    position: fixed !important;
    pointer-events: none;
    z-index: 9999;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 260px;
    max-width: 420px;
    transition: opacity 0.1s ease;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
}

.tooltip-header {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 4px;
    word-break: break-all;
}

.tooltip-body {
    font-size: 11px;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tt-cover-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
    margin-left: 4px;
    background: rgba(56, 189, 248, 0.2);
    color: var(--primary);
}

.tt-sec-section {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tt-sec-header {
    font-weight: 700;
    color: #94a3b8;
    margin-bottom: 4px;
    font-size: 11px;
}

.tt-sec-list {
    max-height: 160px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
}

.tt-sec-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: rgba(255, 255, 255, 0.05);
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.tt-sec-main-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tt-sec-uid {
    font-family: monospace;
    color: #cbd5e1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 260px;
}

.tt-sec-pct {
    font-weight: 700;
    color: var(--primary);
}

.tt-sec-meta {
    display: flex;
    gap: 12px;
    font-size: 10px;
    color: #94a3b8;
}

.tt-sec-meta strong {
    color: #f1f5f9;
}

/* Model Element Visibility Toolbar in MC View */
.mc-visibility-toolbar {
    display: flex;
    gap: 16px;
    align-items: center;
    background: var(--bg-card);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-size: 12px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 600;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Loading Overlay */
#viewer-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 99999;
    background: #0b0f19;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(56, 189, 248, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Tab Navigation Bar */
.tab-bar {
    display: flex;
    gap: 4px;
    background: #0f172a;
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    background: var(--primary);
    color: #0f172a;
}

.tab-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

/* Model Coordination Matrix Table */
.matrix-wrapper {
    flex: 1;
    overflow: auto;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    min-height: 250px;
    color: #1e293b;
}

.coord-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: center;
}

.coord-table th {
    background: #f8fafc;
    color: #1e293b;
    padding: 10px 12px;
    font-weight: 700;
    border-bottom: 2px solid #cbd5e1;
    position: sticky;
    top: 0;
    z-index: 10;
}

.coord-table td {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, filter 0.15s ease;
}

.coord-table td:hover:not(.tree-cell) {
    filter: brightness(0.92);
    transform: scale(0.98);
}

.coord-table td.selected-cell {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}

.tree-cell {
    text-align: left;
    background: #ffffff !important;
    color: #0f172a !important;
    font-weight: 700;
    cursor: default !important;
}

html[dir="rtl"] .tree-cell {
    text-align: right;
}

.tree-root {
    background: #f1f5f9;
}

.tree-root .tree-cell {
    background: #f1f5f9 !important;
    font-size: 14px;
    font-weight: 700;
}

.tree-child .tree-cell {
    padding-left: 28px;
    font-weight: 500;
}

html[dir="rtl"] .tree-child .tree-cell {
    padding-left: 12px;
    padding-right: 28px;
}

.tree-toggle {
    display: inline-block;
    width: 16px;
    height: 16px;
    line-height: 14px;
    text-align: center;
    border-radius: 3px;
    border: 1px solid #94a3b8;
    background: #ffffff;
    color: #0f172a;
    font-size: 11px;
    margin-right: 6px;
    cursor: pointer;
}

html[dir="rtl"] .tree-toggle {
    margin-right: 0;
    margin-left: 6px;
}

/* Heatmap Status Cell Colors (Matching reference image) */
.cell-critical {
    background: #f87171 !important;
    color: #0f172a !important;
}

.cell-medium {
    background: #fb923c !important;
    color: #0f172a !important;
}

.cell-good {
    background: #fde047 !important;
    color: #0f172a !important;
}

.cell-high {
    background: #4ade80 !important;
    color: #0f172a !important;
}

.cell-empty {
    background: #e2e8f0 !important;
    color: #94a3b8 !important;
}

/* Coordination Legend & Footer */
.coordination-footer {
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.legend-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    font-size: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-main);
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.dot-critical { background: #ef4444; }
.dot-medium { background: #f97316; }
.dot-good { background: #eab308; }
.dot-high { background: #10b981; }
.dot-manual { background: #e2e8f0; border: 1px solid #94a3b8; }

.range-filter-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.range-inputs {
    display: flex;
    gap: 12px;
    font-size: 12px;
}

.range-inputs input[type="number"] {
    width: 55px;
    padding: 4px 6px;
    background: #0f172a;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
}

.range-filter-box input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
}

/* Projects Portal Landing Page Styles */
.portal-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 24px 60px 24px;
    flex: 1;
    height: calc(100vh - 64px);
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    box-sizing: border-box;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.portal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.portal-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 4px;
}

.portal-subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.empty-portal-card {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 24px;
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

.project-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 180px;
    box-shadow: var(--shadow-sm);
}

.project-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.project-number {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary);
    background: rgba(56, 189, 248, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.project-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    margin-top: 6px;
}

.project-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.project-card-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(11, 15, 25, 0.75);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-box {
    width: 440px;
    max-width: 90vw;
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.input-field {
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.input-field:focus {
    border-color: var(--primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* 3D Viewport Pane & Canvas Container */
#viewer-pane {
    position: relative;
    flex: 1;
    height: 100%;
    overflow: hidden;
    background: #0b0f19;
}

#canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

#canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}


#viewer-loading-overlay {
    z-index: 30;
}

/* ============================================================
   Portrait-Mode Overlay
   Shown on mobile/tablet devices in portrait orientation only.
   Hides when device is rotated to landscape.
   ============================================================ */
#portrait-overlay {
    display: none;             /* hidden by default (landscape / desktop) */
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--bg-dark);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    text-align: center;
    padding: 32px;
    font-family: var(--font-family);
}

/* Show overlay only in portrait on screens ≤ 1024px (mobile / tablet) */
@media (orientation: portrait) and (max-width: 1024px) {
    #portrait-overlay {
        display: flex;
    }
}

.portrait-overlay-logos {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 12px;
    opacity: 0.9;
}

.portrait-logo {
    height: 36px;
    width: auto;
    object-fit: contain;
    filter: brightness(1.1);
}

.portrait-overlay-icon {
    font-size: 72px;
    color: var(--primary);
    line-height: 1;
    animation: portrait-rotate-hint 2.4s ease-in-out infinite;
    filter: drop-shadow(0 0 16px rgba(56, 189, 248, 0.5));
}

@keyframes portrait-rotate-hint {
    0%   { transform: rotate(0deg);   opacity: 1; }
    40%  { transform: rotate(90deg);  opacity: 1; }
    60%  { transform: rotate(90deg);  opacity: 0.7; }
    100% { transform: rotate(0deg);   opacity: 1; }
}

.portrait-overlay-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    letter-spacing: -0.01em;
}

.portrait-overlay-sub {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-muted);
    margin: 0;
}

/* ============================================================
   Mobile Landscape Overall UI Scaling (Browser-like Zoom)
   Scales all text, controls, toolbars, and buttons uniformly.
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
    #app-container {
        zoom: 0.78; /* Uniform 78% scaling like browser zoom out */
    }

    #app-header, #top-navbar {
        height: 48px;
        padding: 0 16px;
    }

    .portal-container {
        height: calc(100vh / 0.78 - 48px);
        max-height: calc(100vh / 0.78 - 48px);
        padding: 16px 20px 40px 20px;
    }

    .portal-header {
        margin-bottom: 16px;
        padding-bottom: 10px;
    }

    .portal-header h2 {
        font-size: 18px;
    }

    .portal-subtitle {
        font-size: 12px;
    }

    .projects-grid {
        grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
        gap: 14px;
    }

    .project-card {
        padding: 14px;
        min-height: 140px;
    }

    #main-content {
        height: calc(100vh / 0.78 - 48px);
    }

    #data-pane {
        width: 42vw;
        min-width: 280px;
        max-width: 460px;
        padding: 10px;
    }
}

