/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #1a1a2e;
    --bg-panel: #16213e;
    --bg-toolbar: #0f3460;
    --accent: #4a90d9;
    --accent-hover: #5ba0e9;
    --text: #e0e0e0;
    --text-muted: #8899aa;
    --border: #2a3a5e;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --shadow: rgba(0, 0, 0, 0.4);
}

body {
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text);
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    user-select: none;
}

#viewport {
    display: block;
    width: 100vw;
    height: 100vh;
}

/* ===== LOADING OVERLAY ===== */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s;
}

#loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loader-container {
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-bar {
    width: 300px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin: 15px auto;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
    border-radius: 3px;
}

/* ===== NO MODEL MESSAGE ===== */
#no-model-message {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.no-model-content {
    text-align: center;
    max-width: 500px;
    padding: 40px;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 40px 30px;
    margin-top: 20px;
    transition: all 0.3s;
    cursor: pointer;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(74, 144, 217, 0.1);
}

.drop-zone i {
    font-size: 40px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.btn-upload {
    margin-top: 15px;
    padding: 10px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-upload:hover {
    background: var(--accent-hover);
}

/* ===== TOOLBAR ===== */
#toolbar {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-toolbar);
    padding: 6px 12px;
    border-radius: 10px;
    box-shadow: 0 4px 20px var(--shadow);
    z-index: 100;
    backdrop-filter: blur(10px);
}

.toolbar-group {
    display: flex;
    gap: 2px;
}

.toolbar-separator {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 6px;
}

/* Model switcher */
.model-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
}

.model-label {
    color: var(--text-muted);
    font-size: 14px;
}

.model-select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    min-width: 120px;
}

.model-select:hover {
    border-color: var(--accent);
}

.model-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.tool-btn {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.tool-btn.active {
    background: var(--accent);
    color: white;
}

/* ===== PANELS ===== */
.panel {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 20px var(--shadow);
    z-index: 90;
    min-width: 280px;
    max-height: 60vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
}

.panel.hidden {
    display: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.btn-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    background: rgba(244, 67, 54, 0.2);
    color: var(--danger);
}

/* Info panel */
#info-panel {
    top: 70px;
    right: 12px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    color: var(--text);
    font-weight: 500;
    text-align: right;
    max-width: 60%;
    word-break: break-word;
}

.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

/* Breadcrumb */
.info-breadcrumb {
    padding: 6px 16px;
    font-size: 11px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    overflow-x: auto;
    white-space: nowrap;
}

.info-breadcrumb:empty {
    display: none;
}

.breadcrumb-item {
    cursor: pointer;
    transition: color 0.15s;
}

.breadcrumb-item:hover {
    color: var(--accent);
}

.breadcrumb-sep {
    margin: 0 4px;
    color: var(--border);
}

.breadcrumb-current {
    color: var(--accent);
    font-weight: 600;
}

/* Component info extras */
.info-section-header {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 0 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 6px;
}

.info-children-count {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
}

/* Section controls */
#section-controls {
    bottom: 60px;
    right: 12px;
    min-width: 260px;
}

#section-controls label {
    display: block;
    margin: 8px 0 4px;
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.section-axis-buttons {
    display: flex;
    gap: 4px;
}

.section-axis {
    flex: 1;
    padding: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.section-axis:hover {
    border-color: var(--accent);
}

.section-axis.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

#section-slider {
    width: 100%;
    margin: 8px 0;
    accent-color: var(--accent);
}

#section-controls input[type="checkbox"] {
    accent-color: var(--accent);
    margin-right: 6px;
}

/* Model tree */
#model-tree-panel {
    top: 70px;
    left: 12px;
    max-width: 300px;
}

.tree-view {
    font-size: 13px;
}

.tree-node {
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
}

.tree-node:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tree-node.selected {
    background: rgba(74, 144, 217, 0.2);
    color: var(--accent);
}

.tree-node i {
    font-size: 11px;
    width: 16px;
    text-align: center;
    color: var(--text-muted);
}

.tree-children {
    padding-left: 16px;
}

.tree-children.collapsed {
    display: none;
}

/* ===== MEASUREMENT ===== */
.measure-display {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-toolbar);
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 100;
    font-size: 18px;
    font-weight: 600;
}

.measure-display.hidden {
    display: none;
}

.measure-display i {
    color: var(--accent);
}

.btn-small {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.btn-small:hover {
    background: rgba(244, 67, 54, 0.2);
    color: var(--danger);
}

/* ===== INFO PANEL ACTIONS ===== */
.panel-actions {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
}

.panel-actions.hidden {
    display: none;
}

.action-btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.action-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 0 8px rgba(91, 160, 233, 0.4);
}

/* Badge for hidden count */
.badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--danger);
    color: white;
    font-size: 9px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.badge.hidden {
    display: none;
}

.tool-btn {
    position: relative;
}

/* Tree node visibility */
.tree-visibility {
    margin-left: auto;
    padding: 2px 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    font-size: 11px;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.tree-node:hover .tree-visibility {
    opacity: 1;
}

.tree-visibility:hover {
    color: var(--accent);
}

.tree-node.hidden-obj {
    opacity: 0.4;
}

.tree-node.hidden-obj .tree-visibility {
    opacity: 1;
    color: var(--warning);
}

/* ===== VIEWPOINTS ===== */
#viewpoints-panel {
    bottom: 60px;
    right: 12px;
    min-width: 280px;
    max-height: 70vh;
}

.viewpoint-presets {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-top: 6px;
}

.viewpoint-btn {
    padding: 8px 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.viewpoint-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.viewpoint-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.saved-viewpoints {
    max-height: 150px;
    overflow-y: auto;
    margin: 6px 0;
}

.saved-vp-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.saved-vp-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.saved-vp-item .vp-name {
    flex: 1;
    font-size: 13px;
}

.saved-vp-item .vp-delete {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.saved-vp-item .vp-delete:hover {
    background: rgba(244, 67, 54, 0.2);
    color: var(--danger);
}

.saved-vp-item .vp-star {
    color: var(--warning);
    font-size: 10px;
}

.action-btn.full-width {
    width: 100%;
    margin-top: 6px;
}

.action-btn.muted {
    color: var(--text-muted);
    border-color: transparent;
    font-size: 11px;
    padding: 5px 8px;
}

.action-btn.muted:hover {
    background: rgba(244, 67, 54, 0.1);
    color: var(--danger);
    border-color: transparent;
}

/* First person mode info bar */
.fp-info {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 52, 96, 0.9);
    color: var(--text);
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 12px;
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 4px 15px var(--shadow);
    border: 1px solid var(--border);
}

.fp-info.hidden {
    display: none;
}

.fp-info i {
    color: var(--accent);
    margin-right: 6px;
}

/* ===== STATUS BAR ===== */
#status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 28px;
    background: var(--bg-toolbar);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 20px;
    font-size: 12px;
    color: var(--text-muted);
    z-index: 100;
    border-top: 1px solid var(--border);
}

#status-mode {
    color: var(--accent);
    font-weight: 600;
}

/* ===== FLOATING BUTTONS ===== */
.floating-btn {
    position: fixed;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--bg-toolbar);
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    z-index: 90;
    transition: all 0.2s;
    box-shadow: 0 2px 10px var(--shadow);
}

.floating-btn:hover {
    background: var(--accent);
    color: white;
}

.floating-btn.left {
    top: 70px;
    left: 12px;
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.help-table {
    width: 100%;
    border-collapse: collapse;
}

.help-table td {
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.help-table td:first-child {
    width: 100px;
}

kbd {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-family: monospace;
}

/* ===== MEASUREMENT MARKERS ===== */
.measure-label {
    position: absolute;
    background: var(--bg-toolbar);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    #toolbar {
        top: auto;
        bottom: 36px;
        left: 8px;
        right: 8px;
        transform: none;
        overflow-x: auto;
        justify-content: flex-start;
    }

    .tool-btn {
        width: 34px;
        height: 34px;
        font-size: 13px;
    }

    .panel {
        left: 8px !important;
        right: 8px !important;
        max-width: none !important;
        min-width: auto !important;
    }

    #info-panel {
        top: auto !important;
        bottom: 90px;
    }

    .floating-btn.left {
        top: 12px;
    }

    #status-bar {
        font-size: 11px;
    }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}
