/* ============ BASE STYLES ============ */
body {
    margin: 0;
    overflow: hidden;
    font-family: Arial, sans-serif;
    background: #000;
}

canvas {
    display: block;
    opacity: 0;
    transition: opacity 0.5s ease;
}

canvas.fade-in {
    opacity: 1;
}

/* ============ LABELS OVERLAY ============ */
#labels {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.label {
    position: absolute;
    color: white;
    font-size: 12px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    white-space: nowrap;
    pointer-events: none;
}

.group-label {
    position: absolute;
    font-size: 16px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.9);
    pointer-events: none;
    background: rgba(40, 40, 40, 0.85);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Hover tooltip */
#tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    max-width: 450px;
    pointer-events: none;
    z-index: 15;  /* Below UI panels (20-30) so tooltip doesn't leak over them */
    display: none;
    white-space: normal;
    line-height: 1.3;
}

#tooltip.visible {
    display: block;
}

/* ============ PANEL COLLAPSE TOGGLE ============ */
.panel-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 1;
}

.panel-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.panel-toggle.collapsed {
    transform: rotate(-90deg);
}

.panel-content {
    transition: max-height 0.3s ease, opacity 0.2s ease, margin 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}

.panel-content.collapsed {
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
    margin: 0;
    padding: 0;
}

#headerPanel .panel-content {
    max-height: 500px;
}

#searchPanel .panel-content {
    max-height: 80vh;
}

/* Header panel title - always visible */
.header-title {
    margin: 0 0 10px 0;
    font-size: 18px;
    font-weight: 600;
    color: white;
    text-align: center;
}

#headerPanel.collapsed .header-title {
    margin-bottom: 0;
}

/* Detail section (collapsible "Ko nozīmē..." part) */
.detail-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.15);
}

.detail-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s ease;
}

.detail-toggle:hover {
    color: rgba(255,255,255,0.9);
}

.detail-toggle .toggle-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.detail-toggle.expanded .toggle-arrow {
    transform: rotate(90deg);
}

.detail-content {
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255,255,255,0.5);
    text-align: justify;
    max-height: 300px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
}

.detail-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

/* Collapsed search panel */
#searchPanel.collapsed .panel-header {
    margin-bottom: 0;
}

#searchPanel.collapsed .panel-header h3 {
    margin-right: 32px;
}

#searchPanel .panel-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

#searchPanel .panel-header h3 {
    margin: 0;
    font-size: 15px;
    color: rgba(255,255,255,0.9);
}

/* Clear button inside search wrapper */
#searchWrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
}

#searchWrapper #courseSearch {
    flex: 1;
    padding: 8px;
    box-sizing: border-box;
    border: none;
    border-radius: 4px;
    font-size: 14px;
}

.clear-btn {
    padding: 6px 10px;
    background: rgba(255, 100, 100, 0.3);
    border: none;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.clear-btn:hover {
    background: rgba(255, 100, 100, 0.5);
    color: white;
}

.clear-btn.hidden {
    display: none;
}

/* ============ FADE-IN ANIMATION ============ */
#searchPanel, #headerPanel, #controlPanel, #labels {
    opacity: 0;
    transition: opacity 0.3s ease;
}

#searchPanel.fade-in, #headerPanel.fade-in, #controlPanel.fade-in, #labels.fade-in {
    opacity: 1;
}

/* ============ TOP-RIGHT: HEADER ============ */
#headerPanel {
    position: absolute;
    top: 30px;
    right: 40px;
    max-width: 350px;
    max-height: calc(100vh - 250px);  /* Leave space for control panel */
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    border-radius: 4px;
    padding: 16px;
    z-index: 20;
    pointer-events: auto;
    transition: padding 0.3s ease;
}

#headerPanel h1 {
    margin: 0 0 10px 0;
    font-size: 28px;
    font-weight: 600;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

#headerPanel .description {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: rgba(255,255,255,0.75);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    text-align: justify;
}

/* ============ BOTTOM-RIGHT PANEL: CONTROLS ============ */
#controlPanel {
    position: absolute;
    bottom: 70px;  /* Above the group filter bar */
    right: 40px;
    background: rgba(0, 0, 0, 0.75);
    font-size: 14px;
    padding: 12px;
    border-radius: 6px;
    color: gray;
    z-index: 20;
}

#distanceSlider {
    width: 150px;
}

#resetCamera {
    margin-top: 8px;
    padding: 6px 12px;
    background: rgba(100, 150, 255, 0.3);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

#resetCamera:hover {
    background: rgba(100, 150, 255, 0.5);
}

#instructions {
    font-size: 14px;
    margin-top: 8px;
    line-height: 1.6;
}

/* Camera mode toggle switch */
#cameraModeToggle {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

#autoRotateToggle {
    margin-bottom: 8px;
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    gap: 10px;
}

.toggle-label input {
    display: none;
}

.toggle-slider {
    width: 36px;
    height: 20px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.toggle-label input:checked + .toggle-slider {
    background: rgba(100, 150, 255, 0.6);
}

.toggle-label input:checked + .toggle-slider::after {
    transform: translateX(16px);
}

.toggle-text {
    color: rgba(255,255,255,0.8);
    font-size: 13px;
}

/* ============ TOP-LEFT: SEARCH + SIMILAR ============ */
#searchPanel {
    position: absolute;
    top: 60px;
    left: 40px;
    width: 450px;
    background: rgba(30, 30, 50, 0.75);
    padding: 12px;
    border-radius: 6px;
    z-index: 30;
    color: white;
    transition: padding 0.3s ease;
}

/* #searchTitle is now .panel-header - styles in PANEL COLLAPSE TOGGLE section */
/* Search wrapper styles are in PANEL COLLAPSE section */

/* Selected course item (looks like list item but highlighted) */
#selectedCourse {
    margin-top: 8px;
}

#selectedCourse.hidden {
    display: none;
}

#selectedCourse .selected-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    background: rgba(100,180,255,0.15);
    border: 1px solid rgba(100,180,255,0.3);
    border-radius: 4px;
}

#selectedCourse .icon {
    min-width: 20px;
    height: 20px;
    background: rgba(100,180,255,0.4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    margin-right: 8px;
    flex-shrink: 0;
}

#selectedCourse .details {
    flex: 1;
    min-width: 0;
}

#selectedCourse .title {
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 2px;
    line-height: 1.2;
}

#selectedCourse .meta {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
}

#selectedCourse .code {
    color: rgba(150,200,255,0.9);
    font-family: monospace;
}

#selectedCourse .link-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 8px;
    background: rgba(100,150,255,0.3);
    border-radius: 4px;
    color: white;
    text-decoration: none;
    font-size: 12px;
    flex-shrink: 0;
    transition: background 0.2s;
}

#selectedCourse .link-btn:hover {
    background: rgba(100,150,255,0.6);
}

#searchResults {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 100%;
    max-height: min(250px, calc(100vh - 250px));
    overflow-y: auto;
    font-size: 13px;
    background: rgba(40, 40, 70, 0.98);
    border-radius: 4px;
    z-index: 100;
}

#searchResults:empty {
    display: none;
}

.search-item {
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 3px;
}

.search-item:hover,
.search-item.active {
    background: rgba(255,255,255,0.2);
}

/* ECTS Filter */
#ectsFilter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding: 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
    font-size: 13px;
}

#ectsFilter > label {
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
    flex-shrink: 0;
}

#ectsRangeLabel {
    color: rgba(255,200,100,0.9);
    font-weight: 500;
}

#rangeSliderContainer {
    position: relative;
    height: 20px;
    flex: 1;
}

#rangeSliderContainer input[type="range"] {
    position: absolute;
    width: 100%;
    height: 6px;
    top: 5px;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    z-index: 10;
    background: transparent;
}

#rangeSliderContainer input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: rgba(255,200,100,0.9);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    border: 2px solid rgba(255,255,255,0.3);
}

#rangeSliderContainer input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: rgba(255,200,100,0.9);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    border: 2px solid rgba(255,255,255,0.3);
}

#rangeTrack {
    position: absolute;
    top: 7px;
    left: 0;
    right: 0;
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    pointer-events: none;
}

#rangeTicks {
    display: none;
}

/* ============ SIMILAR COURSES SECTION (inside search panel) ============ */
#similarSection {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.2);
}

#similarSection h3 {
    margin: 0 0 6px 0;
    font-size: 13px;
    color: rgba(255,255,255,0.9);
}

#similarResults {
    font-size: 14px;
    max-height: calc(100vh - 340px);
    overflow-y: auto;
}

.placeholder {
    color: rgba(255,255,255,0.5);
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

.no-results {
    color: rgba(255,255,255,0.5);
    text-align: center;
    padding: 20px 0;
}

/* Similar course item */
.similar-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    margin-bottom: 3px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s;
}

.similar-item:last-child {
    margin-bottom: 0;
}

.similar-item:hover {
    background: rgba(255,255,255,0.18);
}

/* Similarity bar */
.similarity-container {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.similarity-bar {
    flex: 1;
    height: 12px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
    min-width: 60px;
}

.similarity-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
    opacity: 0.65;
}

.similarity-label {
    font-size: 10px;
    color: rgba(255,255,255,0.95);
    font-weight: 500;
    text-shadow: 0 0 3px rgba(0,0,0,0.9);
    white-space: nowrap;
    min-width: 30px;
}

.similar-item .details {
    flex: 1;
    min-width: 0;
}

.similar-item .title {
    font-weight: 500;
    font-size: 13.5px;
    margin-bottom: 2px;
    line-height: 1.25;
    word-wrap: break-word;
}

.similar-item .meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.similar-item .meta {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    line-height: 1.3;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 110px;  /* Fixed width so bars align */
}

.similar-item .code {
    color: rgba(150,200,255,0.9);
    font-family: monospace;
}

.similar-item .link-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 6px;
    background: rgba(100,150,255,0.3);
    border-radius: 3px;
    color: white;
    text-decoration: none;
    font-size: 12px;
    flex-shrink: 0;
    transition: background 0.2s;
}

.similar-item .link-btn:hover {
    background: rgba(100,150,255,0.6);
}

/* ============ LOADING INDICATOR ============ */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
}

#loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

/* ============ SCROLLBAR STYLING ============ */
#similarResults::-webkit-scrollbar,
#searchResults::-webkit-scrollbar {
    width: 6px;
}

#similarResults::-webkit-scrollbar-track,
#searchResults::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

#similarResults::-webkit-scrollbar-thumb,
#searchResults::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 3px;
}

#similarResults::-webkit-scrollbar-thumb:hover,
#searchResults::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.5);
}

/* ============ GROUP FILTER BAR ============ */
#groupFilterBar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.75);
    z-index: 25;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#groupFilterBar.fade-in {
    opacity: 1;
}

#groupFilterHeader {
    display: flex;
    align-items: center;
    gap: 12px;
}

#groupFilterTitle {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
}

#groupFilterButtons {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
}

#groupButtons {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.group-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    padding: 6px 10px;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(100, 100, 100, 0.4);
}

.group-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.2);
}

.group-btn.active {
    border-color: white;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.group-btn.dimmed {
    opacity: 0.4;
}

.group-btn .group-code {
    font-size: 11px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.group-btn .group-count {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.7);
}

#courseCountIndicator {
    display: flex;
    align-items: center;
    padding: 4px 10px;
    background: rgba(50, 50, 50, 0.6);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
}

#courseCountIndicator #courseCount {
    color: rgba(100, 180, 255, 1);
    font-weight: bold;
}

.reset-btn {
    background: rgba(80, 80, 80, 0.6);
    border-color: rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.reset-btn:hover {
    background: rgba(100, 100, 100, 0.8);
}

/* Hide scrollbar but allow scrolling */
#groupFilterButtons::-webkit-scrollbar {
    height: 4px;
}

#groupFilterButtons::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

#groupFilterButtons::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

/* ============ RESPONSIVE DESIGN ============ */

/* Medium screens (laptops, tablets landscape) */
@media (max-width: 1200px) {
    #searchPanel {
        width: 380px;
        left: 20px;
        top: 40px;
    }

    #headerPanel {
        max-width: 280px;
        right: 20px;
        top: 20px;
        padding: 12px;
        max-height: calc(100vh - 220px);
    }

    #headerPanel .detail-section {
        display: none;  /* Hide detailed explanation on smaller screens */
    }

    #controlPanel {
        right: 20px;
        bottom: 20px;
    }
}

/* Short screens (any width but limited height) */
@media (max-height: 700px) {
    #headerPanel {
        max-height: calc(100vh - 200px);
    }

    #headerPanel .detail-section {
        display: none;
    }

    #similarResults {
        max-height: calc(100vh - 320px);
    }
}

/* Very short screens */
@media (max-height: 550px) {
    #headerPanel {
        display: none;
    }
}

/* Small screens (tablets portrait, small laptops) */
@media (max-width: 900px) {
    #searchPanel {
        width: calc(100% - 40px);
        max-width: 400px;
        left: 20px;
        top: 20px;
        padding: 10px;
    }

    #headerPanel {
        display: none;  /* Hide header on small screens - takes too much space */
    }

    #controlPanel {
        right: 20px;
        bottom: 20px;
        font-size: 12px;
        padding: 10px;
    }

    #distanceSlider {
        width: 120px;
    }

    #similarResults {
        max-height: calc(100vh - 300px);
    }

    .similar-item .title {
        font-size: 12px;
    }

    .similar-item .meta {
        font-size: 10px;
    }
}

/* Very small screens */
@media (max-width: 600px) {
    #searchPanel {
        width: calc(100% - 20px);
        left: 10px;
        top: 10px;
        padding: 8px;
    }

    #controlPanel {
        right: 10px;
        bottom: 10px;
        padding: 8px;
    }

    #instructions {
        font-size: 11px;
    }

    #ectsFilter {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    #rangeSliderContainer {
        width: 100%;
    }

    #similarResults {
        max-height: calc(100vh - 280px);
    }
}
