html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/*******************
* Loading
*******************/

/* Loading overlay */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.loading-content {
    text-align: center;
    padding: 30px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid #2196F3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

    100% {
        transform: rotate(360deg);
    }
}

#retryButton {
    padding: 10px 20px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

/*******************
* Controls
*******************/

#controls {
    position: absolute;
    top: 50px;
    right: 10px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1;
    width: 280px;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.control-section {
    margin-bottom: 20px;
}

.control-section h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

/* Category checkboxes + counters */

.category-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.category-table th {
    background: #f7f7f7;
    padding: 8px 4px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
    font-size: 11px;
}

.category-table th:nth-child(2), .category-table th:nth-child(3) {
    text-align: right;
}

.category-table th:nth-child(2), .category-table td:nth-child(2) {
    width: 60px;
    min-width: 60px;
}

.category-table th:nth-child(3), .category-table td:nth-child(3) {
    width: 70px;
    min-width: 70px;
}

.category-table td {
    padding: 6px 4px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.category-table .source-cell {
    display: flex;
    align-items: center;
    gap: 0;
}

.category-table tr:hover {
    background: #f9f9f9;
}

.category-table .totals-row {
    font-weight: 600;
    background: #f7f7f7;
    border-top: 2px solid #ccc;
}

.category-table .totals-row td {
    border-bottom: none;
}

.category-checkbox {
    margin: 0;
    margin-right: 6px;
}

.category-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 11px;
}

.color-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid #ccc;
    margin-right: 6px;
    flex-shrink: 0;
}

.count-cell,
.capacity-cell {
    text-align: right;
    font-size: 11px;
}

/* Power range slider */

.power-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 20px;
    padding-right: 20px;
}

.power-values {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #666;
}

#powerRangeSlider {
    margin: 15px 0;
}

.noUi-target {
    background: #e0e0e0;
    border-radius: 8px;
    border: none;
    height: 8px;
}

.noUi-connect {
    background: #2196F3;
}

.noUi-handle {
    width: 24px !important;
    height: 24px !important;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #2196F3;
    cursor: grab;
    outline: none;
    top: -8px !important;
}

.noUi-handle:active {
    cursor: grabbing;
}

.noUi-handle:before, .noUi-handle:after {
    display: none;
}

/* Search widget */

#searchInput {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    box-sizing: border-box;
    transition: border-color 0.3s;
}

#searchInput:focus {
    border-color: #2196F3;
    outline: none;
}

/* Facility selectors */

.energy-source-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #ccc;
    flex-shrink: 0;
}

/* Annotations */

.annotations {
    font-size: 11px;
    color: #666;
    text-align: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
    line-height: 1.3;
}

.info-asterisk {
    color: #2196F3;
    cursor: pointer;
    margin-left: 3px;
    font-weight: bold;
    position: relative;
}

.info-asterisk:hover {
    color: #1976D2;
}

.tooltip {
    position: absolute;
    bottom: 20px;
    right: 0;
    background: #333;
    color: white;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 10px;
    width: 200px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
    box-sizing: border-box;
}

.info-asterisk:hover .tooltip {
    opacity: 1;
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 15px;
    border: 4px solid transparent;
    border-top-color: #333;
}

/* Mobile responsiveness for controls*/

@media (max-width: 480px) {
    #controls {
        width: 260px;
        font-size: 11px;
    }

    .category-table th:nth-child(2),
    .category-table td:nth-child(2) {
        width: 50px;
        min-width: 50px;
    }

    .category-table th:nth-child(3),
    .category-table td:nth-child(3) {
        width: 60px;
        min-width: 60px;
    }

    .category-table th,
    .category-table td {
        padding: 4px 2px;
    }

    .category-label {
        font-size: 10px;
    }

    .count-cell,
    .capacity-cell {
        font-size: 10px;
    }
}

/*******************
* Tab navigation
*******************/

.tab-navigation {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: #f7f7f7;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: flex-end;
    padding: 0 10px;
    z-index: 1000;
}

.tab-button {
    padding: 8px 24px 8px 24px;
    background: #e9e9e9;
    color: #495057;
    border: 1px solid #dee2e6;
    border-bottom: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    margin-right: 2px;
    position: relative;
    top: 1px;
}

.tab-button:hover:not(.active) {
    background: #f8f9fa;
    color: #212529;
}

.tab-button.active {
    background: white;
    color: #212529;
    border-color: #dee2e6;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05);
}

.tab-button.active:hover {
    background: white;
}

/*******************
* Top-level modes
*******************/

.time-series-mode {
    position: absolute;
    top: 50px;
    bottom: 0;
    left: 0;
    right: 320px; /* Leave space for controls panel */
}

#productionMode {
    background: white;
    overflow: hidden;
    display: none;
}

#productionContainer {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin-top: 40px;
}

#tradeMode {
    background: white;
    overflow: hidden;
    display: none;
}

#tradeContainer {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin-top: 40px;
}

/* Map */

#map {
    position: absolute;
    top: 40px;
    bottom: 0;
    width: 100%;
}

.maplibregl-ctrl-group {
    display: none;
}

/*******************
* Table view
*******************/

#tableView {
    position: absolute;
    top: 40px;
    bottom: 0;
    left: 0;
    right: 320px;
    /* Leave space for controls panel */
    background: white;
    overflow: hidden;
}

#tableContainer {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#tableHeader {
    padding: 15px 20px;
    border-bottom: 1px solid #ddd;
    
    display: flex;
    justify-content: center;
    align-items: center;
}

#tableControls {
    font-size: 14px;
    color: #666;
}

#paginationControls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#paginationControls button {
    padding: 4px 8px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

#paginationControls button:hover:not(:disabled) {
    background: #f0f0f0;
}

#paginationControls button:disabled {
    opacity: 0.8;
    cursor: not-allowed;
}

#currentPageNumber {
    cursor: pointer;
    text-decoration: underline;
    color: #2196F3;
}

#pageNumberInput {
    width: 50px;
    text-align: center;
    border: 1px solid #2196F3;
    border-radius: 3px;
    padding: 2px;
    font-size: 12px;
}

#pageInfo {
    font-size: 12px;
    color: #666;
    min-width: 180px;
    text-align: center;
}

#tableWrapper {
    flex: 1;
    overflow: auto;
}

#facilitiesTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

#facilitiesTable th:nth-child(1) { /* Energy Type */
    width: 25%;
}

#facilitiesTable th:nth-child(2) { /* Power */
    width: 15%;
}

#facilitiesTable th:nth-child(3) { /* Town */
    width: 25%;
}

#facilitiesTable th:nth-child(4) { /* Canton */
    width: 12%;
}

#facilitiesTable th:nth-child(5) { /* Date */
    width: 15%;
}

#facilitiesTable th:nth-child(6) { /* GPS */
    width: 8%;
}

#facilitiesTable th {
    background: #f7f7f7;
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
    position: sticky;
    top: 0;
    white-space: nowrap;
}

#facilitiesTable th.sortable {
    cursor: pointer;
    user-select: none;
}

#facilitiesTable th.sortable:hover {
    background: #e8e8e8;
}

#facilitiesTable th.numeric {
    text-align: right;
}

#facilitiesTable td {
    padding: 8px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#facilitiesTable td.numeric {
    text-align: right;
}

#facilitiesTable tr:hover {
    background: #f9f9f9;
}

.sort-indicator {
    margin-left: 5px;
    opacity: 0.5;
}

.sort-indicator.asc::before {
    content: '↑';
    opacity: 1;
}

.sort-indicator.desc::before {
    content: '↓';
    opacity: 1;
}

.gps-indicator {
    text-align: center;
}

.gps-yes {
    color: #4CAF50;
    font-weight: bold;
}

.gps-no {
    color: #f44336;
    font-weight: bold;
}

#viewToggle {
    width: 100%;
    padding: 10px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

#viewToggle:hover {
    background: #1976D2;
}

/*******************
* Time series charts
*******************/

.chart-controls {
    position: fixed;
    top: 55px;
    left: 20px;
    right: 320px;
    /* Leave space for the controls panel */
    background: white;
    padding: 5px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
    /* Cut off content if window is too narrow */
    white-space: nowrap;
    /* Prevent text wrapping */
}

.chart-help {
    font-size: 11px;
    color: #666;
    line-height: 1.3;
    margin: 0;
}

.reset-zoom-btn {
    padding: 6px 12px;
    margin-left: 5px;
    background: #f7f7f7;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.3s;
}

.reset-zoom-btn:hover {
    background: #e8e8e8;
}

#productionChartContainer {
    flex: 1;
    padding: 20px;
    overflow: hidden;
}

.chart-canvas {
    width: 100% !important;
    height: 100% !important;
    user-select: none;
}

.chart-canvas:focus {
    outline: none;
}

#tradeChartContainer {
    flex: 1;
    padding: 20px;
    overflow: hidden;
}

.production-controls {
    display: none;
}

.production-controls.active {
    display: block;
}

.trade-controls {
    display: none;
}

.trade-controls.active {
    display: block;
}

/*******************
* About mode
*******************/

#aboutMode {
    right: 0;
    background: white;
    overflow: auto;
    display: none;
    padding: 20px;
}

.about-content {
    background: white;
    max-width: 800px;
    padding: 25px;
    margin: 0 auto;
    font-size: 14px;
    line-height: 1.6;
    overflow-y: auto;
}

.about-content h3 {
    color: #333;
    margin: 0 0 15px 0;
    font-size: 18px;
}

.about-content h4 {
    color: #555;
    margin: 15px 0 8px 0;
    font-size: 16px;
}

.about-content p,
.about-content li {
    line-height: 1.4;
    color: #666;
    margin: 8px 0;
}

.about-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.about-content a {
    color: #2196F3;
    text-decoration: none;
}

.about-content a:hover {
    text-decoration: underline;
}
