* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    width: min(1880px, 100vw - 40px);
    margin: 0 auto;
    padding: 22px clamp(22px, 3.5vw, 40px) 40px;
}

header {
    background: linear-gradient(135deg, #2f80ed, #56ccf2);
    color: #fff;
    padding: 14px 20px;
    margin-bottom: 14px;
    border-radius: 14px;
    box-shadow: 0 12px 22px rgba(47, 128, 237, 0.12);
}

header h1 {
    font-size: 24px;
    line-height: 1.2;
}

.main-content {
    display: grid;
    grid-template-columns: 360px minmax(0, 2fr) minmax(0, 1.35fr);
    gap: 28px;
    align-items: stretch;
    margin-bottom: 32px;
    min-height: calc(100vh - 220px);
}

.sidebar {
    background-color: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 26px;
    align-self: start;
    height: calc(100vh - 88px);
    max-height: calc(100vh - 88px);
}

.sidebar-scrollable {
    flex: 1 1 auto;
    overflow-y: auto;
    padding-right: 8px;
    margin-right: -8px;
}

.map-container {
    min-height: clamp(600px, 82vh, 1080px);
}

.panel {
    background-color: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 46px rgba(15, 23, 42, 0.08);
    padding: 30px 32px 36px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100%;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
}

.panel-subtitle {
    margin-top: 4px;
    font-size: 14px;
    color: #64748b;
    max-width: 420px;
}

.map-frame {
    flex: 1 1 auto;
    border-radius: 12px;
    overflow: hidden;
    background: linear-gradient(180deg, #eff6ff 0%, #f8fafc 100%);
    box-shadow: inset 0 0 0 1px #e2e8f0;
    min-height: 600px;
}

#map {
    height: 100%;
    width: 100%;
    min-height: 600px;
}

.map-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    text-align: right;
    color: #475569;
}

.map-status .label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #2563eb;
}

#area-summary {
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', monospace;
    font-size: 13px;
    padding: 6px 10px;
    background-color: #f1f5f9;
    border-radius: 8px;
    border: 1px solid #dbeafe;
    color: #1f2937;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    max-width: 260px;
}

#area-summary.has-selection {
    background-color: #e0f2fe;
    border-color: #93c5fd;
    color: #0f172a;
}

@media (max-width: 1720px) {
    .main-content {
        grid-template-columns: 340px minmax(0, 1.85fr) minmax(0, 1.15fr);
        gap: 26px;
    }

    .panel {
        padding: 28px 28px 32px;
    }

    .map-frame,
    #map {
        min-height: clamp(560px, 78vh, 940px);
    }
}

@media (max-width: 1360px) {
    .main-content {
        grid-template-columns: 320px minmax(0, 1fr);
        gap: 24px;
    }

    .map-container,
    .map-frame,
    #map {
        min-height: clamp(520px, 74vh, 860px);
    }

    .data-display {
        grid-column: 1 / -1;
    }
}

@media (max-width: 1200px) {
    .main-content {
        gap: 22px;
    }

    .panel {
        padding: 24px 24px 30px;
    }

    .map-container,
    .map-frame,
    #map {
        min-height: clamp(480px, 70vh, 780px);
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .map-status {
        align-items: flex-start;
        text-align: left;
    }
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        height: auto;
        max-height: none;
    }

    .sidebar-scrollable {
        max-height: none;
        padding-right: 0;
        margin-right: 0;
    }

    .map-container,
    .map-frame,
    #map {
        min-height: clamp(420px, 64vh, 680px);
    }

    .data-categories {
        max-height: none;
    }

    .view-tabs {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 24px 20px 40px;
    }

    header {
        padding: 24px;
    }

    .panel {
        padding: 20px;
    }

    .panel-header {
        gap: 12px;
    }

    .map-container,
    .map-frame,
    #map {
        min-height: clamp(360px, 56vh, 620px);
    }

    .view-tab {
        flex: 1 1 45%;
        text-align: center;
    }

    .table-container {
        border-radius: 10px;
    }

    #data-table th,
    #data-table td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .static-button-container {
        position: static;
        padding-top: 16px;
        box-shadow: none;
    }
}

.section {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5edf8;
}

.section:last-child {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.section h2 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #1e293b;
    font-weight: 700;
}

.section h3 {
    font-size: 15px;
    margin: 14px 0 8px;
    color: #334155;
    font-weight: 600;
}

.area-selection {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 2px;
}

.search-container {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

#location-search {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #d0d7e2;
    border-radius: 10px 0 0 10px;
    border-right: none;
}

#location-search-btn {
    padding: 9px 16px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff;
    border: 1px solid #1d4ed8;
    border-radius: 0 10px 10px 0;
    font-weight: 600;
}

#location-search-btn:hover {
    background: linear-gradient(135deg, #1d4ed8, #0284c7);
}

.area-selection button, .data-options .option {
    margin-bottom: 6px;
}

.area-selection input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d0d7e2;
    border-radius: 10px;
}

.option {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.option input {
    margin-right: 10px;
}

textarea#query-editor {
    width: 100%;
    padding: 12px;
    border: 1px solid #d0d7e2;
    border-radius: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    min-height: 160px;
    background-color: #f8fafc;
}

input[type="text"],
textarea#query-editor {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
textarea#query-editor:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

button {
    padding: 10px 14px;
    background-color: #f8fafc;
    border: 1px solid #d0d7e2;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

button:hover {
    background-color: #eef2ff;
    border-color: #c3d0f7;
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.15);
}

button:disabled,
button:disabled:hover {
    background-color: #f1f5f9;
    border-color: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
}

.primary-btn {
    background-color: #2563eb;
    color: #fff;
    border-color: #1d4ed8;
}

.primary-btn:hover {
    background-color: #1e40af;
}


.data-display {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
}

.data-display h2 {
    font-size: 20px;
    margin-bottom: 15px;
    color: #2c3e50;
}

.data-info {
    font-size: 14px;
    color: #475569;
    background: #f1f5f9;
    border: 1px solid #dbeafe;
    border-radius: 999px;
    padding: 6px 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.data-info span {
    font-size: 18px;
    font-weight: 700;
    color: #1d4ed8;
}

.data-preview {
    background-color: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 12px;
    padding: 20px;
    flex: 1 1 auto;
    overflow-y: auto;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.1);
}

.data-preview pre {
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', monospace;
    font-size: 13px;
    color: #e2e8f0;
}

.download-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.download-options h3 {
    margin-right: 4px;
    font-size: 15px;
    color: #1e293b;
}

.download-options button {
    background: linear-gradient(135deg, #22c55e, #10b981);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 999px;
    font-weight: 600;
    box-shadow: 0 12px 20px rgba(16, 185, 129, 0.2);
}

.download-options button:hover {
    background: linear-gradient(135deg, #16a34a, #0d9488);
}

.leaflet-draw-toolbar {
    margin-top: 15px !important;
}

/* Button styling for selection buttons */
.button-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
}

.button-group button {
    font-size: 13px;
    font-weight: 600;
    padding: 10px 14px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff;
    border: none;
    border-radius: 10px;
    box-shadow: 0 10px 18px rgba(14, 165, 233, 0.18);
}

.button-group button:hover {
    background: linear-gradient(135deg, #1d4ed8, #0284c7);
}

.button-group button.secondary {
    background: #f8fafc;
    color: #1f2937;
    border: 1px dashed #cbd5f5;
    box-shadow: none;
    border-radius: 10px;
}

.button-group button.secondary:hover {
    background: #eef2ff;
    border-style: solid;
    color: #0f172a;
}

.button-group button:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    border: 1px solid #dbeafe;
    box-shadow: none;
    border-radius: 10px;
}

/* View tabs styling */
.view-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 4px;
}

.view-tab {
    padding: 10px 18px;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    cursor: pointer;
    font-weight: 600;
    color: #475569;
}

.view-tab.active {
    background-color: #fff;
    border-color: #94a3b8;
    color: #1e293b;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
}

.view-content {
    display: none;
    height: 100%;
}

.view-content.active {
    display: flex;
    flex-direction: column;
}

/* Table styling */
.table-container {
    flex: 1 1 auto;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background-color: #fff;
}

#data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

#data-table th {
    background-color: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    color: #1e293b;
    font-weight: 700;
}

#data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #edf2f7;
    vertical-align: top;
}

#data-table tr:hover {
    background-color: #f8fafc;
}

#data-table .empty-state {
    text-align: center;
    padding: 24px 16px;
    font-size: 14px;
    color: #64748b;
}

.tag-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.tag-list li {
    margin-bottom: 4px;
}

.tag-key {
    font-weight: bold;
    color: #2c3e50;
}

/* Data selection search */
.data-selection-search {
    display: flex;
    margin-bottom: 8px;
}

.data-selection-search input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d0d7e2;
    border-radius: 10px;
}

.category {
    margin-bottom: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    background-color: #fff;
    box-shadow: 0 12px 22px rgba(15, 23, 42, 0.06);
}

.category:last-child {
    margin-bottom: 0;
}

.category-header {
    padding: 9px 12px;
    background-color: #f1f5f9;
    cursor: pointer;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.category-header:hover {
    background-color: #e2e8f0;
}

.category-checkbox {
    margin-right: 10px;
}

.category-name {
    flex: 1;
    font-weight: 600;
    color: #1e293b;
}

.category-name[role="button"],
.subcategory-name[role="button"] {
    cursor: pointer;
}

.expand-icon {
    font-size: 12px;
    transition: transform 0.3s ease;
    color: #64748b;
    margin-left: auto;
}

.category.collapsed .expand-icon {
    transform: rotate(-90deg);
}

.category-content {
    padding: 9px 12px 10px;
    display: grid;
    gap: 8px;
    background-color: #fff;
}

.category.collapsed .category-content {
    display: none;
}

.subcategory-group {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background-color: #f8fafc;
}

.subcategory-group.collapsed {
    border-radius: 12px;
}

.subcategory-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 7px 11px;
    background-color: #f1f5f9;
    border-radius: 12px 12px 0 0;
    font-weight: 600;
    color: #334155;
}

.subcategory-name {
    flex: 1;
    font-weight: 600;
    color: #334155;
}

.subcategory-header .expand-icon {
    margin-left: auto;
}

.subcategory-group.collapsed .subcategory-header {
    border-radius: 12px;
}

.subcategory-options {
    padding: 7px 12px 9px;
    display: grid;
    gap: 5px;
    background-color: #fff;
    border-radius: 0 0 12px 12px;
}

.subcategory-options.single-group {
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background-color: #f8fafc;
    gap: 4px;
}

.subcategory-group.collapsed .subcategory-options {
    display: none;
}

.subcategory-options > div {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.category-name:focus-visible,
.subcategory-name:focus-visible {
    outline: 2px solid #94a3b8;
    outline-offset: 2px;
}

/* Add styles for the static fetch button */
.static-button-container {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 252, 0.98) 100%);
    padding: 18px 0 0;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -12px 24px rgba(15, 23, 42, 0.06);
}

.static-button {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.02em;
    border-radius: 14px;
}

/* Hide coordinates input */
#coordinates {
    display: none;
}
