/* ===================================
   Unified Control Panel Styles
   =================================== */

/* Main control panel container */
.control-panel {
    position: fixed;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none; /* Allow click-through except on actual controls */
}

/* Control panel positioning to avoid SuperSplat view cube (SuperSplat-only app) */
.control-panel {
    top: 115px; /* Additional clearance to fully avoid viewcube overlap */
}

/* Layer controls max-height adjustment for lower positioning */
.layer-controls {
    max-height: calc(100vh - 220px); /* Adjust for lower positioning */
}

/* Focus panel positioning to avoid SuperSplat view cube */
.focus-panel {
    top: 115px; /* Match control panel positioning */
    bottom: 115px; /* Adjust bottom to maintain panel height */
}

/* Control groups */
.control-group {
    display: flex;
    gap: 10px;
    align-items: center;
    pointer-events: auto; /* Re-enable pointer events for controls */
}

/* Main controls styling - single row with buttons, site selector, and layer controls */
.main-controls {
    justify-content: flex-end;
    align-items: flex-start; /* Allow layer controls to expand downward */
}

/* Base control item styling */
.control-item {
    display: flex;
    align-items: center;
}

/* Dropdown container styling */
.control-item select {
    background-color: #072b2e;
    color: white;
    border: none;
    border-radius: 25px;
    height: 50px; /* Match circular button height */
    padding: 0 20px;
    padding-right: 40px; /* Make room for arrow in circular area */
    font-size: 14px;
    font-family: 'Oxygen', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    
    /* Width to match 4 buttons + 3 gaps = 230px */
    width: 230px;
    
    /* Elegant text handling */
    text-overflow: ellipsis;
    overflow: hidden;
    
    /* Custom dropdown arrow styling */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23ffffff' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center; /* Center in the circular right area */
    background-size: 12px 8px;
}

.control-item select:hover {
    background-color: #0a3c46;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    /* Arrow stays white on hover */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23ffffff' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
}

.control-item select:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

/* Style dropdown options */
.control-item select option {
    background-color: #072b2e;
    color: white;
    padding: 10px;
    font-style: normal; /* Reset italic for option elements */
}

/* Site selector - heavier font weight */
.site-selector select {
    font-weight: 600;
}

/* Parameter filter - italic text */
.parameter-filter select {
    font-style: italic;
}

/* Base button styling */
.control-button {
    background-color: #072b2e;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    font-family: 'Oxygen', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-button:hover {
    background-color: #0a3c46;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.control-button:active {
    transform: translateY(0);
}

/* Icon buttons (circular) */
.icon-button {
    width: 50px;
    height: 50px;
    border-radius: 40px;
    background-size: 30px 30px;
    background-repeat: no-repeat;
    background-position: center;
}

/* Text buttons (circular for 2D/3D) */
.text-button {
    width: 50px;
    height: 50px;
    border-radius: 40px;
    font-size: 18px;
    font-weight: bold;
    padding: 0;
}

/* Mode toggle buttons with Unicode icons */
.globe-icon-button,
.supersplat-icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: normal;
    text-align: center;
    line-height: 1;
    background-image: none; /* Override any background image */
}

.globe-icon-button::before {
    content: '🌍';
    display: inline-block;
}

.supersplat-icon-button::before {
    content: '🧪';
    display: inline-block;
}

/* Responsive icon sizes */
@media screen and (max-width: 767px) {
    .globe-icon-button,
    .supersplat-icon-button {
        font-size: 20px;
    }
}

@media screen and (max-width: 480px) {
    .globe-icon-button,
    .supersplat-icon-button {
        font-size: 18px;
    }
}

/* Active state for toggle buttons */
.control-button.active {
    background-color: rgba(76, 175, 80, 0.9);
}

.control-button.active:hover {
    background-color: rgba(76, 175, 80, 1);
}

/* ===================================
   Mobile Responsive Design
   =================================== */

@media screen and (max-width: 767px) {
    /* Move control panel to bottom */
    .control-panel {
        top: auto;
        bottom: 20px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        flex-direction: column-reverse; /* Buttons at bottom, dropdowns above */
        max-width: calc(100vw - 20px);
        gap: 15px;
    }
    
    /* Keep data controls aligned on mobile */
    .data-controls {
        width: 100%;
        margin-left: 0;
        justify-content: center;
    }
    
    /* Center view controls */
    .view-controls {
        justify-content: center;
    }
    
    /* Smaller buttons on mobile */
    .icon-button,
    .text-button {
        width: 44px;
        height: 44px;
        background-size: 26px 26px;
    }
    
    /* Adjust text button font */
    .text-button {
        font-size: 16px;
    }
    
    /* Adjust dropdown sizing for mobile */
    .control-item select {
        height: 44px; /* Match reduced button height */
        padding: 0 16px;
        padding-right: 36px; /* Room for arrow */
        font-size: 13px;
        width: 230px;
    }
    
    /* Tighter gaps on mobile */
    .control-group {
        gap: 8px;
    }
}

/* Small mobile devices */
@media screen and (max-width: 480px) {
    /* Even smaller sizing for very small screens */
    .icon-button,
    .text-button {
        width: 40px;
        height: 40px;
        background-size: 24px 24px;
    }
    
    .text-button {
        font-size: 14px;
    }
    
    .control-item select {
        height: 40px; /* Match reduced button height */
        padding: 0 14px;
        padding-right: 34px; /* Room for arrow */
        font-size: 12px;
        width: 200px; /* Proportionally smaller for very small screens */
    }
    
    /* Reduce gaps further */
    .control-panel {
        gap: 10px;
    }
    
    .control-group {
        gap: 6px;
    }
}

/* ===================================
   Animations and Transitions
   =================================== */

/* Smooth appearance animation */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.control-panel {
    animation: fadeInDown 0.3s ease-out;
}

/* Loading state for dropdowns */
.control-item select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Focus states for accessibility */
.control-button:focus,
.control-item select:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .control-button,
    .control-item select {
        border: 2px solid white;
    }
    
    .control-button:hover,
    .control-item select:hover {
        border-color: #4CAF50;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .control-button,
    .control-item select {
        transition: none;
    }
    
    .control-panel {
        animation: none;
    }
}

/* ===================================
   Dark mode support (future)
   =================================== */

/* Dark mode inherits the same Ecodash brand colors */

/* ===================================
   Layer Controls Styles
   =================================== */

/* Layer controls container */
.layer-controls {
    background: rgba(7, 43, 46, 0.95);
    border-radius: 25px;
    padding: 15px;
    width: 290px; /* Width of 5 circular buttons (50*5 + 4*10 gaps) */
    margin-top: 10px;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    overflow-x: visible; /* Allow selected items to extend outside */
    position: relative; /* Ensure proper stacking context */
    z-index: 1000; /* Above focus panel */
}

/* Custom scrollbar for layer controls */
.layer-controls::-webkit-scrollbar {
    width: 6px;
}

.layer-controls::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.layer-controls::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    transition: background 0.2s;
}

.layer-controls::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Firefox scrollbar */
.layer-controls {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.05);
}

.layer-section {
    margin-bottom: 12px;
    position: relative;
    overflow: visible; /* Allow selected items to extend */
}

.layer-section:last-child {
    margin-bottom: 0;
}

.layer-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background-color 0.2s;
    color: white;
    user-select: none;
}

.layer-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Container for visibility button and dropdown arrow */
.layer-controls-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Visibility toggle button */
.visibility-toggle-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    /* Prevent event bubbling conflicts */
    z-index: 10;
    position: relative;
}

.visibility-toggle-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.visibility-toggle-button img {
    width: 16px;
    height: 16px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.visibility-toggle-button:hover img {
    opacity: 1;
}

.layer-toggle-arrow {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid white;
    transition: transform 0.2s;
}

.layer-toggle.expanded .layer-toggle-arrow {
    transform: rotate(180deg);
}

.layer-checkbox span {
    font-size: 14px;
    font-weight: 600;
}

.sub-options {
    margin-left: 12px;
    margin-top: 4px;
    overflow: visible; /* Allow selected items to show outside */
    position: relative;
}

.sub-checkbox {
    font-size: 13px;
}

.sub-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
}

.metrics-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 8px;
    margin-left: 30px;
}

.metric-radio {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
    color: white;
}

.metric-radio:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.metric-radio input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    margin-right: 6px;
    width: 14px;
    height: 14px;
    border: 2px solid white;
    border-radius: 50%;
    background-color: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.metric-radio input[type="radio"]:checked {
    background-color: white;
}

.metric-radio input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #072b2e;
}

/* NPA category styles */
.npa-category {
    display: flex;
    align-items: center;
    padding: 3px 6px;
    margin-bottom: 2px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: background-color 0.2s;
    color: white;
}

.npa-category:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.npa-category input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    margin-right: 8px;
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    border: 2px solid #FF6B6B;
    border-radius: 50%;
    background-color: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.npa-category input[type="radio"]:checked {
    background-color: #FF6B6B;
}

.npa-category input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #072b2e;
    animation: radioSelect 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Plantable area category styles */
.pa-category {
    display: flex;
    align-items: center;
    padding: 3px 6px;
    margin-bottom: 2px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: background-color 0.2s;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pa-category:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Selected PA highlighting with connection indicator */
.pa-category.selected {
    position: relative;
    z-index: 10; /* Higher z-index to prevent clipping */
    margin: 2px 4px; /* Add horizontal margin to prevent clipping */
}

.pa-category.selected::before {
    content: '';
    position: fixed; /* Use fixed positioning to escape overflow container */
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid white;
    border-radius: 20px;
    pointer-events: none;
    z-index: 1001; /* Above layer controls */
}

/* We'll set the position dynamically via JavaScript since we need getBoundingClientRect */

.pa-category input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    margin-right: 8px;
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    border: 2px solid white;
    border-radius: 50%;
    background-color: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pa-category input[type="radio"]:checked {
    background-color: white;
}

.pa-category input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #072b2e;
    animation: radioSelect 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes radioSelect {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.pa-number {
    font-weight: 600;
    margin-right: 4px;
    color: rgba(255, 255, 255, 0.7);
}

/* PA category grouping */
.pa-category-group {
    margin-bottom: 8px;
    position: relative; /* Create stacking context */
    z-index: 1; /* Base z-index */
}

.pa-category-group-title {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 2px;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pa-category-group .pa-category {
    margin-left: 6px;
}

/* Ensure selected group is on top */
.pa-category-group:has(.pa-category.selected) {
    z-index: 100;
}

.npa-color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 8px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Ensure layer controls are visible */
#layerControls {
    display: none; /* Hidden by default, shown when ecological data site is selected */
}

/* Allow selected items to extend outside containers */
#plantableSubOptions,
#nonPlantableSubOptions {
    overflow: visible !important;
    position: relative;
}

/* Mobile adjustments for layer controls */
@media screen and (max-width: 767px) {
    .layer-controls {
        width: 100%;
        max-width: 300px;
    }
    
    .metrics-options {
        grid-template-columns: 1fr;
    }
}

/* Full-width site selector when buttons are hidden */
.view-controls {
    width: 100%;
    justify-content: stretch \!important;
}

.site-selector {
    width: 100%;
    flex: 1;
}

.site-selector select,
.control-item select {
    width: 100% \!important;
    max-width: none \!important;
}

/* Override mobile widths too */
@media screen and (max-width: 767px) {
    .control-item select {
        width: 100% \!important;
    }
}

@media screen and (max-width: 480px) {
    .control-item select {
        width: 100% \!important;
    }
}
