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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    background-color: #0b0d12;
    color: #e2e8f0;
}

#app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #0b0d12;
}

/* -------------------------------------------------------------
   1. Top Global Header Bar (AutoEducate 상단 네비게이션)
------------------------------------------------------------- */
#top-header {
    height: 52px;
    background: #12151e;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 50;
    flex-shrink: 0;
}

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

.brand-icon {
    height: 34px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.brand-icon img {
    height: 100%;
    width: auto;
    display: block;
}

.brand-title {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #ffffff;
}

.brand-subtitle {
    font-size: 9px;
    color: #64748b;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-item {
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
}

.nav-item:hover {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: #10b981;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

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

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 12px;
    font-weight: 600;
    color: #e2e8f0;
}

/* -------------------------------------------------------------
   2. Main Workspace Body (3단 구조: 좌측 트리 + 중앙 뷰포트 + 우측 AI 패널)
------------------------------------------------------------- */
#main-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* 좌측 고정 PARTS TREE 사이드바 */
#left-sidebar {
    width: 270px;
    background: #12151e;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 20;
}

.sidebar-header {
    padding: 14px 16px;
    font-size: 11px;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.parts-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.tree-node-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 4px;
}

.part-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.15s ease;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    margin-bottom: 2px;
}

.part-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
}

.part-item.selected {
    background: rgba(16, 185, 129, 0.18) !important;
    color: #34d399 !important;
    border: 1px solid rgba(16, 185, 129, 0.4);
    font-weight: 600;
}

.part-item.faulty {
    background: rgba(239, 68, 68, 0.18) !important;
    color: #fca5a5 !important;
    border: 1px solid rgba(239, 68, 68, 0.4);
    font-weight: 600;
}

.part-item.is-group {
    font-weight: 700;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.06);
}

.toggle-icon {
    display: inline-block;
    width: 14px;
    font-size: 10px;
    margin-right: 6px;
    color: #94a3b8;
    text-align: center;
}

.leaf-icon {
    font-size: 11px;
    margin-right: 6px;
}

.part-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-child-group {
    margin-left: 14px;
    padding-left: 6px;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

/* 중앙 3D 뷰포트 영역 */
#center-viewport-container {
    flex: 1;
    position: relative;
    background: radial-gradient(circle at 50% 50%, #1a1e2a 0%, #0b0d12 100%);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

/* 중앙 상단 조작바 (검색창 + 핫키 태그 칩) */
#center-top-bar {
    position: absolute;
    top: 14px;
    left: 16px;
    right: 16px;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}

.viewport-search-box {
    pointer-events: auto;
    background: rgba(18, 21, 30, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 260px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.viewport-search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: #f8fafc;
    font-size: 12px;
    width: 100%;
}

.viewport-chips-group {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
}

.chip {
    background: rgba(18, 21, 30, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    font-size: 11px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.chip:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.2);
}

/* 우측 AI Diagnostic Copilot 패널 (고정 사이드바) */
#right-chat-drawer {
    width: 380px;
    background: #12151e;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 20;
    position: relative;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
}

.drawer-header {
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-title {
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-log {
    user-select: text;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-message {
    display: flex;
    gap: 10px;
    font-size: 13px;
    line-height: 1.5;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

.user .avatar {
    background: #6366f1;
    color: #fff;
}

.assistant .avatar {
    background: #10b981;
    color: #fff;
}

.message-bubble {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 14px;
    border-radius: 12px;
    color: #cbd5e1;
    max-width: 85%;
}

.user .message-bubble {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.35);
    color: #e0e7ff;
}

.fault-badge {
    display: inline-block;
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.4);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 6px;
}

/* 채팅 내 선택지 버튼 (기존에 클래스만 쓰이고 정의가 없었음) */
.btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-primary {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #6ee7b7;
}
.btn-primary:hover { background: rgba(16, 185, 129, 0.28); color: #fff; }

.drawer-footer {
    padding: 14px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.prompt-input-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px 10px;
    gap: 8px;
}

#prompt-textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: #f8fafc;
    font-family: inherit;
    font-size: 12px;
    resize: none;
    outline: none;
    height: 24px;
    line-height: 24px;
}

.send-btn {
    background: #10b981;
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: background 0.2s;
}

.send-btn:hover {
    background: #059669;
}

.guide-action-btn {
    width: 100%;
    background: #10b981;
    color: #ffffff;
    border: none;
    padding: 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s;
}

.guide-action-btn:hover {
    background: #059669;
}

/* -------------------------------------------------------------
   3. 3D Pin Markers (이미지 스타일: 초록 뱃지 + 라벨)
------------------------------------------------------------- */
.part-marker {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
    cursor: pointer;
    transform: translate(-50%, -50%);
    z-index: 30;
}

.marker-badge {
    width: 26px;
    height: 26px;
    background: #10b981;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.8);
    transition: transform 0.2s;
}

.marker-label {
    background: rgba(18, 21, 30, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.part-marker:hover .marker-badge {
    transform: scale(1.2);
    background: #34d399;
}

/* -------------------------------------------------------------
   4. 모달, 로딩, WASD 및 조향 제어 UI
------------------------------------------------------------- */
#steering-ui {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 25;
    background: rgba(18, 21, 30, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 14px;
    border-radius: 10px;
    color: #fff;
}

#dpad-ui {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 25;
    background: rgba(18, 21, 30, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.dpad-row { display: flex; gap: 4px; }
.dpad-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dpad-btn:hover { background: #10b981; color: #fff; }

#loading-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(8, 9, 13, 0.88);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#loading-overlay.active { opacity: 1; pointer-events: auto; }
.spinner {
    width: 44px; height: 44px;
    border: 3px solid rgba(16, 185, 129, 0.2);
    border-top: 3px solid #10b981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.progress-container { width: 320px; background: rgba(255, 255, 255, 0.08); height: 5px; border-radius: 3px; overflow: hidden; margin-top: 12px; }
.progress-bar { width: 0%; height: 100%; background: linear-gradient(90deg, #10b981, #34d399); transition: width 0.2s ease; }
#loading-status { font-size: 13px; color: #94a3b8; margin-top: 8px; }

#quick-search-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(5, 6, 9, 0.8);
    backdrop-filter: blur(12px);
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
}
#quick-search-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.qs-container { width: 780px; max-width: 92%; background: rgba(20, 22, 32, 0.95); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 20px; padding: 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6); display: flex; flex-direction: column; gap: 20px; }
.qs-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(255, 255, 255, 0.08); padding-bottom: 14px; }
.qs-title { font-size: 18px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 10px; }
.qs-close-btn { background: none; border: none; color: #9ca3af; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px; }
.qs-close-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.qs-group-title { font-size: 12px; font-weight: 600; color: #10b981; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 10px; }
.qs-options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; margin-bottom: 6px; }
.qs-card { background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 12px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: pointer; color: #9ca3af; transition: all 0.2s; }
.qs-card:hover { background: rgba(255, 255, 255, 0.08); color: #fff; border-color: rgba(255, 255, 255, 0.2); }
.qs-card.active { background: rgba(16, 185, 129, 0.18); border-color: #10b981; color: #10b981; }
.qs-submit-btn { background: #10b981; color: #fff; border: none; padding: 12px 20px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
.qs-submit-btn:hover { background: #059669; }

.anim-chip-btn {
    background: #334155; color: #94a3b8; border: 1px solid #475569;
    padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px;
}
.anim-chip-btn:hover { background: #475569; color: #fff; }
.anim-chip-btn.active { background: #10b981; color: #fff; border-color: #10b981; font-weight: bold; }

.detail-part-row {
    display: flex; flex-direction: column; gap: 6px; padding: 8px;
    border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03); cursor: pointer; flex-shrink: 0;
}
.detail-part-row:hover { background: rgba(255, 255, 255, 0.07); }
.detail-part-row.selected { background: rgba(16, 185, 129, 0.18); border-color: rgba(16, 185, 129, 0.5); }
.detail-thumb { width: 100%; aspect-ratio: 16 / 10; border-radius: 6px; background: #12151e; overflow: hidden; }
.detail-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.detail-part-id {
    font-size: 12px; font-weight: 600; color: #e2e8f0; text-align: center;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.detail-part-row.selected .detail-part-id { color: #34d399; }

/* 상세 모델 로딩 중에도 로딩창이 팝업 위에 보이도록 */
#loading-overlay { z-index: 200; }
.detail-part-row:hover { background: rgba(255, 255, 255, 0.07); }
.detail-part-row.selected { background: rgba(16, 185, 129, 0.18); border-color: rgba(16, 185, 129, 0.5); color: #34d399; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
.hidden { display: none !important; }