/* COOP Extremes App Styles */

/* Loading indicator */
.spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Sticky table header */
.sticky {
    position: sticky;
    top: 0;
    background-color: var(--bs-light);
    z-index: 10;
}

/* Table styling improvements */
.table-responsive {
    margin-top: 1rem;
    overflow-x: auto;
}

/* Tabulator horizontal scrolling */
.tabulator {
    overflow-x: auto !important;
    width: 100% !important;
}

.tabulator .tabulator-tableHolder {
    overflow-x: auto !important;
}

#data-table {
    margin-bottom: 0;
    min-width: 1300px; /* Ensure minimum width for all columns */
}

#data-table th {
    background-color: var(--bs-light);
    font-weight: 600;
    border-bottom: 2px solid var(--bs-border-color);
}

#data-table th a {
    color: var(--bs-primary);
    text-decoration: none;
}

#data-table th a:hover {
    color: var(--bs-primary);
    text-decoration: underline;
}

/* Mobile responsive improvements */
@media (max-width: 768px) {
    .table-responsive {
        font-size: 0.875rem;
    }
    
    #data-table th,
    #data-table td {
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }
    
    /* Hide less critical columns on small screens */
    .hide-mobile {
        display: none;
    }
}

/* API info styling */
#api-info {
    margin-top: 1rem;
    margin-bottom: 1rem;
}

#api-info code {
    word-break: break-all;
    background-color: var(--bs-gray-100);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

/* Form styling */
#controls-form {
    margin-bottom: 1rem;
}

#controls-form .table {
    margin-bottom: 0;
}

/* Form controls styling */
#controls-form .card {
    border: 1px solid #dee2e6;
    margin-bottom: 1.5rem;
}

#controls-form .card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 0.75rem 1rem;
}

#controls-form .card-header h6 {
    color: #0d6efd;
    font-weight: 600;
}

#controls-form .form-label {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

#controls-form .form-select,
#controls-form .btn {
    font-size: 0.875rem;
}

/* Header section */
#header-section h3 {
    color: #0d6efd;
    font-size: 1.5rem;
}

#header-section h4 {
    font-size: 1.25rem;
    font-weight: 600;
}

#header-section .text-muted {
    font-size: 0.9rem;
}

/* Error state styling */
.error-message {
    color: var(--bs-danger);
    padding: 1rem;
    background-color: var(--bs-danger-bg-subtle);
    border: 1px solid var(--bs-danger-border-subtle);
    border-radius: 0.375rem;
    margin: 1rem 0;
}

/* Mode explanation alert */
.alert-info h5 {
    color: #0c5460;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.alert-info .row > div {
    padding: 0.5rem;
}

.alert-info strong {
    color: #0c5460;
    font-size: 0.95rem;
}

.alert-info .small {
    line-height: 1.4;
    margin-top: 0.25rem;
}

/* Back button styling */
.btn-outline-primary.btn-sm {
    font-size: 0.8rem;
    padding: 0.375rem 0.75rem;
}

/* Column grouping visual separation */
.temp-group {
    border-left: 3px solid var(--bs-warning);
}

.precip-group {
    border-left: 3px solid var(--bs-info);
}

/* Sortable column indicators */
.sortable {
    cursor: pointer;
    user-select: none;
}

.sortable:hover {
    background-color: var(--bs-gray-100);
}

.sort-indicator {
    margin-left: 0.25rem;
    opacity: 0.5;
    font-size: 0.75rem;
}

.sort-indicator.active {
    opacity: 1;
}

/* Map container and view toggle */
#view-toggle {
    margin-bottom: 1rem;
}

#view-toggle .btn-group {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#map-container {
    height: 500px;
    width: 100%;
    border: 2px solid var(--bs-border-color);
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    position: relative;
}

#map-container.hidden {
    display: none;
}

/* Map popup styling */
.ol-popup {
    position: absolute;
    background-color: white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #cccccc;
    bottom: 12px;
    left: -50px;
    min-width: 280px;
    max-width: 400px;
}

.ol-popup:after, .ol-popup:before {
    top: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}

.ol-popup:after {
    border-top-color: white;
    border-width: 10px;
    left: 48px;
    margin-left: -10px;
}

.ol-popup:before {
    border-top-color: #cccccc;
    border-width: 11px;
    left: 48px;
    margin-left: -11px;
}

.ol-popup-closer {
    text-decoration: none;
    position: absolute;
    top: 2px;
    right: 8px;
    font-size: 16px;
    color: #999;
}

.ol-popup-closer:after {
    content: "✖";
}

.ol-popup-content {
    font-size: 14px;
}

.ol-popup-content h5 {
    margin: 0 0 5px 0;
    color: var(--bs-primary);
}

.popup-data-table {
    width: 100%;
    font-size: 12px;
    margin-top: 8px;
}

.popup-data-table td {
    padding: 2px 6px;
    border-bottom: 1px solid #eee;
}

.popup-data-table .label {
    font-weight: bold;
    color: #666;
}

/* Mobile responsive map */
@media (max-width: 768px) {
    #map-container {
        height: 400px;
    }
    
    .ol-popup {
        min-width: 200px;
        max-width: 280px;
        font-size: 12px;
    }
    
    .map-controls {
        position: relative;
        top: auto;
        left: auto;
        margin-bottom: 10px;
        width: 100%;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .map-controls label {
        white-space: nowrap;
    }
}

/* Layer switcher customization */
.layer-switcher {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.layer-switcher button {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
}

.layer-switcher button:hover {
    background: rgba(0,0,0,0.1);
}

/* Legend for temperature colors */
.legend-title {
    font-weight: bold;
    margin-bottom: 3px;
    color: var(--bs-primary);
    font-size: 12px;
}

.legend-subtitle {
    font-size: 10px;
    color: #666;
    margin-bottom: 3px;
    font-style: italic;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 2px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    margin-right: 5px;
    border: 1px solid #fff;
}

/* Map controls */
.map-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 100;
    font-size: 13px;
    min-width: 200px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.control-row:last-of-type {
    margin-bottom: 0;
}

.control-row label {
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
}

/* Year filter specific styling */
.control-row:has(#year-filter) {
    border-top: 1px solid #e9ecef;
    padding-top: 8px;
    margin-top: 8px;
}

.control-row:has(#year-filter) label {
    color: #6c757d;
    font-size: 12px;
}

.legend-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.legend-row label {
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
    margin-top: 2px;
}

.map-legend {
    flex: 1;
    font-size: 11px;
}

.map-controls select {
    width: auto;
    display: inline-block;
}

/* Tabulator table styling overrides */
.tabulator {
    border: 1px solid var(--bs-border-color) !important;
    border-radius: 0.375rem !important;
    font-size: 0.875rem !important;
    background-color: var(--bs-body-bg) !important;
}

.tabulator .tabulator-header {
    background-color: var(--bs-light) !important;
    border-bottom: 2px solid var(--bs-border-color) !important;
    font-weight: 600 !important;
}

.tabulator .tabulator-header .tabulator-col {
    background-color: var(--bs-light) !important;
    border-right: 1px solid var(--bs-border-color) !important;
    color: var(--bs-body-color) !important;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    padding: 8px 6px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row {
    border-bottom: 1px solid var(--bs-border-color) !important;
    background-color: transparent !important;
}

.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row:hover {
    background-color: var(--bs-light) !important;
}

.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row .tabulator-cell {
    border-right: 1px solid var(--bs-border-color) !important;
    padding: 6px 8px !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Tabulator row striping */
.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.05) !important;
}

.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row:nth-child(even):hover {
    background-color: var(--bs-light) !important;
}

/* Station/Date column special styling */
.tabulator .tabulator-cell.station-col {
    font-weight: 600 !important;
    background-color: rgba(13, 110, 253, 0.1) !important;
}

.tabulator .tabulator-cell.years-col {
    text-align: center !important;
    font-weight: 500 !important;
}

/* Numeric cell alignment */
.tabulator .tabulator-cell.temp-group,
.tabulator .tabulator-cell.precip-group {
    text-align: right !important;
}

/* Column header improvements */
.tabulator .tabulator-header .tabulator-col.temp-group .tabulator-col-content {
    background-color: rgba(255, 193, 7, 0.1) !important;
}

.tabulator .tabulator-header .tabulator-col.precip-group .tabulator-col-content {
    background-color: rgba(13, 202, 240, 0.1) !important;
}

/* Frozen column styling */
.tabulator .tabulator-cell.station-col {
    position: sticky !important;
    left: 0 !important;
    z-index: 5 !important;
    border-right: 2px solid var(--bs-border-color) !important;
}

.tabulator .tabulator-header .tabulator-col:first-child {
    position: sticky !important;
    left: 0 !important;
    z-index: 10 !important;
    border-right: 2px solid var(--bs-border-color) !important;
}

/* Enhanced Tabulator styling for frozen columns and height */
.tabulator .tabulator-freeze-left {
    border-right: 2px solid var(--bs-primary) !important;
    background-color: var(--bs-light) !important;
    z-index: 10 !important;
}

.tabulator .tabulator-freeze-left .tabulator-cell {
    background-color: var(--bs-light) !important;
    font-weight: 500 !important;
}

.tabulator .tabulator-freeze-left:hover .tabulator-cell {
    background-color: var(--bs-info) !important;
}

/* Ensure proper table height and scrolling */
.tabulator .tabulator-tableHolder {
    max-height: calc(70vh - 120px) !important; /* Account for header and pagination */
    overflow-y: auto !important;
}

/* Pagination styling for better visibility */
.tabulator .tabulator-footer {
    border-top: 2px solid var(--bs-border-color) !important;
    background-color: var(--bs-light) !important;
    padding: 8px !important;
}

.tabulator .tabulator-paginator {
    color: var(--bs-body-color) !important;
}

.tabulator .tabulator-page {
    color: var(--bs-primary) !important;
    border: 1px solid var(--bs-border-color) !important;
    background-color: var(--bs-body-bg) !important;
}

.tabulator .tabulator-page.active {
    background-color: var(--bs-primary) !important;
    color: white !important;
}

/* Column grouping visual indicators for Tabulator */
.tabulator .tabulator-header .temp-group {
    border-left: 3px solid var(--bs-warning) !important;
}

.tabulator .tabulator-header .precip-group {
    border-left: 3px solid var(--bs-info) !important;
}

.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row .temp-group {
    border-left: 3px solid var(--bs-warning) !important;
}

.tabulator .tabulator-tableHolder .tabulator-table .tabulator-row .precip-group {
    border-left: 3px solid var(--bs-info) !important;
}

/* Links in Tabulator cells */
.tabulator .tabulator-cell a {
    color: var(--bs-primary) !important;
    text-decoration: none !important;
}

.tabulator .tabulator-cell a:hover {
    color: var(--bs-primary) !important;
    text-decoration: underline !important;
}

/* Prevent text wrapping in table cells */
.tabulator .tabulator-cell {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Sort arrow styling */
.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-sorter {
    right: 4px !important;
}

.tabulator .tabulator-header .tabulator-col.tabulator-sortable .tabulator-col-content:hover {
    background-color: rgba(0, 0, 0, 0.1) !important;
}

/* Improve frozen column appearance */
.tabulator .tabulator-frozen.tabulator-frozen-left {
    border-right: 2px solid var(--bs-primary) !important;
}

/* Better responsive handling */
@media (max-width: 1200px) {
    .tabulator {
        font-size: 0.75rem !important;
    }
    
    .tabulator .tabulator-header .tabulator-col .tabulator-col-content {
        padding: 6px 4px !important;
    }
    
    .tabulator .tabulator-tableHolder .tabulator-table .tabulator-row .tabulator-cell {
        padding: 4px 6px !important;
    }
}
