/* Calculadora de Sumideros de Carbono - Custom Styles */

/* Card component */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #e9ecef;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    padding: 1rem 1.5rem;
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    border-radius: 8px 8px 0 0;
    font-weight: 500;
    -webkit-border-radius: 8px 8px 0 0;
    -moz-border-radius: 8px 8px 0 0;
    -ms-border-radius: 8px 8px 0 0;
    -o-border-radius: 8px 8px 0 0;
}

.card-body {
    padding: 0;
}

/* Button styles */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    margin-bottom: 0;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 6px;
    transition: all 0.2s ease-in-out;
}

.btn-success {
    color: white;
    background-color: #28a745;
    border-color: #28a745;
}

.btn-success:hover {
    color: white;
    background-color: #218838;
    border-color: #1e7e34;
    text-decoration: none;
}

.btn-success:focus,
.btn-success:active {
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.25);
    outline: none;
}

/* Form styles */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: 6px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
    color: #495057;
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* Results section styles */
.resultados-numericos {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid #dee2e6;
}

.resultados-numericos h2 {
    color: #2c3e50;
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #28a745;
    display: inline-block;
    width: 100%;
}

.resultados-numericos p {
    background: white;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border-left: 4px solid #28a745;
    font-size: 1.1rem;
    color: #495057;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.resultados-numericos p:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.resultados-numericos p:last-child {
    margin-bottom: 0;
}

/* Highlight specific result types with different colors */
.resultados-numericos p:nth-child(2) {
    border-left-color: #007bff; /* NPP - Blue */
}

.resultados-numericos p:nth-child(3) {
    border-left-color: #28a745; /* Stock Carbono - Green */
}

.resultados-numericos p:nth-child(4) {
    border-left-color: #17a2b8; /* CO2 Fijado - Teal */
}

.resultados-numericos p:nth-child(5) {
    border-left-color: #fd7e14; /* Stock Comprobado - Orange */
}

.resultados-numericos p:nth-child(6) {
    border-left-color: #6f42c1; /* CO2 Comprobado - Purple */
}

/* Add icons or emphasis to values */
.resultados-numericos p strong {
    color: #2c3e50;
    font-weight: 600;
}

/* Results container needs relative positioning for spinner */
.container-resultados {
    position: relative;
    min-height: 200px;
}

/* Loading Spinner Styles - Full page overlay (legacy) */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Loading Spinner Styles - Results section only */
.spinner-overlay-results {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 200px;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
}

.spinner-container {
    text-align: center;
    background-color: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 300px;
    width: 90%;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #28a745;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem auto;
}

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

.spinner-text {
    color: #2c3e50;
    font-size: 1.1rem;
    font-weight: 500;
    margin: 0;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Responsive design for smaller screens */
@media (max-width: 768px) {
    .resultados-numericos {
        padding: 1.5rem;
        margin-top: 1.5rem;
    }
    
    .resultados-numericos h2 {
        font-size: 1.5rem;
    }
    
    .resultados-numericos p {
        padding: 0.875rem 1rem;
        font-size: 1rem;
    }
    
    .spinner-container {
        padding: 1.5rem;
        max-width: 250px;
    }
    
    .spinner {
        width: 40px;
        height: 40px;
    }
    
    .spinner-text {
        font-size: 1rem;
    }
}

/* Leaflet Legend Styles */
.legend-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    max-width: 280px;
    min-width: 220px;
    margin: 10px;
}

.legend-header {
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e9ecef;
    text-align: center;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.375rem 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease-in-out;
}

.legend-item:hover {
    background-color: rgba(0, 123, 255, 0.08);
    transform: translateX(2px);
}

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

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    margin-right: 0.75rem;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.legend-label {
    font-size: 0.875rem;
    color: #495057;
    font-weight: 400;
    line-height: 1.4;
    flex: 1;
}

/* Special styling for light colored items to improve contrast */
.legend-item:has(.legend-color[style*="#FFFF4C"]) .legend-color,
.legend-item:has(.legend-color[style*="#F0F0F0"]) .legend-color {
    border-color: rgba(0, 0, 0, 0.3);
}

/* Responsive design for legend */
@media (max-width: 768px) {
    .legend-container {
        max-width: 240px;
        min-width: 200px;
        padding: 0.875rem;
        margin: 8px;
    }
    
    .legend-header {
        font-size: 0.9rem;
        margin-bottom: 0.625rem;
    }
    
    .legend-color {
        width: 18px;
        height: 18px;
        margin-right: 0.625rem;
    }
    
    .legend-label {
        font-size: 0.8rem;
    }
    
    .legend-item {
        padding: 0.3rem 0.4rem;
        margin-bottom: 0.4rem;
    }
}

/* Animation for legend appearance */
.legend-container {
    animation: legendFadeIn 0.3s ease-out;
}

@keyframes legendFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Styled Toggle Switch for Base Map --- */
.legend-basemap-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 8px 0 12px 0;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle {
    --toggle-height: 34px;
    --toggle-padding: 4px;
    --on-bg: #2c3e50;
    --off-bg: #e9ecef;
    --on-color: #ffffff;
    --off-color: #495057;
    position: relative;
    display: inline-flex;
    align-items: center;
    height: var(--toggle-height);
    padding: var(--toggle-padding);
    border-radius: calc(var(--toggle-height) / 2);
    background: var(--off-bg);
    color: var(--off-color);
    min-width: 170px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12) inset, 0 2px 6px rgba(0,0,0,0.08);
    transition: background 1s ease, color 1s ease;
    user-select: none;
}

.toggle::before {
    content: attr(data-off);
    flex: 1;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.toggle-handle {
    position: absolute;
    top: var(--toggle-padding);
    bottom: var(--toggle-padding);
    width: calc(var(--toggle-height) - (var(--toggle-padding) * 2));
    background: #ffffff;
    border-radius: 999px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    left: var(--toggle-padding);
    transition: left 0.8s ease;
    -webkit-transition: left 0.8s ease;
    -moz-transition: left 0.8s ease;
    -ms-transition: left 0.8s ease;
    -o-transition: left 0.8s ease;
}

/* Checked (ON) state */
.toggle-input:checked + .toggle {
    background: var(--on-bg);
    color: var(--on-color);
}

.toggle-input:checked + .toggle::before {
    content: attr(data-on);
}

.toggle-input:checked + .toggle .toggle-handle {
    left: calc(100% - (var(--toggle-height) - (var(--toggle-padding) * 2)) - var(--toggle-padding));
}

/* Reduce size on small screens */
@media (max-width: 768px) {
    .toggle {
        --toggle-height: 30px;
        min-width: 120px;
    }
    .toggle::before {
        font-size: 11px;
    }
}

/* --- Layer Selection Radio Buttons --- */
.legend-layer-item {
    margin-bottom: 1rem;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.legend-layer-item:hover {
    background-color: rgba(0, 123, 255, 0.05);
}

.legend-layer-radio {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.legend-layer-radio input[type="radio"] {
    margin: 0 0.5rem 0 0;
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: #2c3e50;
}

.legend-layer-radio label {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: #2c3e50;
    margin: 0;
    user-select: none;
}

.legend-layer-radio input[type="radio"]:checked + label {
    color: #007bff;
    font-weight: 600;
}

/* Opacity slider nested under layer */
.legend-opacity {
    margin-left: 1.5rem;
    padding: 0.5rem;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    border-left: 3px solid #007bff;
}

.legend-opacity input[type="range"] {
    width: 100%;
    max-width: 160px;
    cursor: pointer;
}

.legend-opacity label {
    margin: 0;
    color: #495057;
}

/* Smooth transition for opacity slider show/hide */
.legend-opacity {
    transition: opacity 0.3s ease, max-height 0.3s ease;
}

/* Legend items container spacing with scroll */
#legend-items-container {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.25rem;
}

/* Nested legend items */
.legend-item-nested {
    position: relative;
}

.legend-item-nested.clickable {
    cursor: pointer;
}

/* Expand/collapse icon styling */
.legend-expand-icon {
    color: #495057;
    font-size: 0.75rem;
    user-select: none;
}

/* Children container */
.legend-children {
    transition: all 0.3s ease;
}

/* Nested items styling - reduce margins for compact view */
.legend-item-nested {
    margin-bottom: 0.35rem;
}

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

/* Hover effect for expandable items */
.legend-item-nested[style*="cursor: pointer"]:hover {
    background-color: rgba(0, 123, 255, 0.08);
}

/* Custom scrollbar styling for legend items */
#legend-items-container::-webkit-scrollbar {
    width: 8px;
}

#legend-items-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

#legend-items-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

#legend-items-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Firefox scrollbar styling */
#legend-items-container {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.05);
}

/* Responsive adjustments for layer items */
@media (max-width: 768px) {
    .legend-layer-item {
        margin-bottom: 0.75rem;
        padding: 0.375rem;
    }
    
    .legend-layer-radio {
        margin-bottom: 0.375rem;
    }
    
    .legend-layer-radio label {
        font-size: 0.85rem;
    }
    
    .legend-opacity {
        margin-left: 1.25rem;
        padding: 0.375rem;
    }
    
    .legend-opacity input[type="range"] {
        max-width: 140px;
    }
    
    /* Reduce max-height on mobile for better screen usage */
    #legend-items-container {
        max-height: 250px;
    }
}

/* --- Base Layer Radio Buttons --- */
.legend-header-small {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    margin-top: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid #e9ecef;
    text-align: center;
}

.legend-base-layer-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.375rem 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.legend-base-layer-item:hover {
    background-color: rgba(0, 123, 255, 0.05);
}

.legend-base-layer-item:last-child {
    margin-bottom: 0.5rem;
}

.legend-base-layer-item input[type="radio"] {
    margin: 0 0.5rem 0 0;
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: #2c3e50;
}

.legend-base-layer-item label {
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 400;
    color: #495057;
    margin: 0;
    user-select: none;
    flex: 1;
}

.legend-base-layer-item input[type="radio"]:checked + label {
    color: #007bff;
    font-weight: 500;
}

/* Responsive adjustments for base layer items */
@media (max-width: 768px) {
    .legend-header-small {
        font-size: 0.85rem;
        margin-bottom: 0.375rem;
    }
    
    .legend-base-layer-item {
        margin-bottom: 0.4rem;
        padding: 0.3rem 0.4rem;
    }
    
    .legend-base-layer-item label {
        font-size: 0.8rem;
    }
}

/* --- Collapsible Base Layer Control (Bottom-Left) --- */
.base-layer-control {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    margin: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
}

/* Collapsed view - default state */
.base-layer-collapsed {
    display: flex;
    align-items: center;
    padding: 0.625rem 0.875rem;
    gap: 0.5rem;
    white-space: nowrap;
}

.base-layer-icon {
    font-size: 1.125rem;
    line-height: 1;
}

.base-layer-current {
    font-size: 0.875rem;
    font-weight: 500;
    color: #2c3e50;
}

/* Expanded view - hidden by default */
.base-layer-expanded {
    display: none;
    padding: 0.75rem;
    padding-top: 0;
    border-top: 1px solid #e9ecef;
}

/* Show expanded view on hover */
.base-layer-control:hover .base-layer-collapsed {
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 0;
}

.base-layer-control:hover .base-layer-expanded {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Base layer header in expanded view */
.base-layer-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
}

/* Base layer option (radio button + label) */
.base-layer-option {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.375rem 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.base-layer-option:hover {
    background-color: rgba(0, 123, 255, 0.08);
}

.base-layer-option:last-child {
    margin-bottom: 0;
}

.base-layer-option input[type="radio"] {
    margin: 0 0.5rem 0 0;
    cursor: pointer;
    width: 14px;
    height: 14px;
    accent-color: #2c3e50;
}

.base-layer-option label {
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 400;
    color: #495057;
    margin: 0;
    user-select: none;
    flex: 1;
}

.base-layer-option input[type="radio"]:checked + label {
    color: #007bff;
    font-weight: 500;
}

/* Responsive adjustments for base layer control */
@media (max-width: 768px) {
    .base-layer-control {
        margin: 8px;
    }
    
    .base-layer-collapsed {
        padding: 0.5rem 0.75rem;
        gap: 0.4rem;
    }
    
    .base-layer-icon {
        font-size: 1rem;
    }
    
    .base-layer-current {
        font-size: 0.8rem;
    }
    
    .base-layer-expanded {
        padding: 0.625rem;
    }
    
    .base-layer-header {
        font-size: 0.7rem;
        margin-bottom: 0.4rem;
    }
    
    .base-layer-option {
        padding: 0.3rem 0.4rem;
        margin-bottom: 0.4rem;
    }
    
    .base-layer-option label {
        font-size: 0.75rem;
    }
}
