:root {
    --primary-color: #007cba;
    --primary-color-dark: #005a8a;
    --secondary-color: #28a745;
    --secondary-color-dark: #1e7e34;
    --neutral-color: #6c757d;
    --neutral-color-dark: #5a6268;
    --background-color: #f5f5f5;
    --surface-color: #ffffff;
    --text-color: #333;
    --text-color-light: #666;
    --border-color: #ddd;
    --border-color-light: #eee;
    --header-bg: #333;
    --header-text: #ffffff;
    --panel-header-bg: #e9ecef;
    --hover-bg: #e8e8e8;
    --active-bg: var(--primary-color);
    --active-text: #ffffff;
    --selected-bg: var(--primary-color);
    --selected-text: #ffffff;
    --overlay-bg: rgba(0,0,0,0.5);
    --focus-ring: 0 0 0 2px rgba(0,124,186,0.2);

    --font-family: Arial, sans-serif;
    --font-size-base: 14px;
    --font-size-small: 12px;
    --font-size-large: 16px;
    --font-size-xl: 18px;
    --font-size-title: 20px;

    --border-radius: 4px;
    --spacing-small: 4px;
    --spacing-medium: 8px;
    --spacing-large: 15px;
    --box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    margin: 0;
    font-family: var(--font-family);
    color: var(--text-color);
}

h1 {
    background: var(--header-bg);
    color: var(--header-text);
    padding: var(--spacing-large);
    text-align: center;
    margin: 0;
    font-size: var(--font-size-title);
}

.container {
    display: flex;
    height: calc(100vh - 60px);
}

#layers-panel {
    width: 320px;
    background: var(--background-color);
    border-right: 1px solid var(--border-color);
    padding: var(--spacing-large);
    overflow-y: auto;
}

#layers-panel h3 {
    margin: 0 0 var(--spacing-large) 0;
    font-size: var(--font-size-xl);
}

#search-bar {
    width: 100%;
    padding: var(--spacing-medium);
    margin-bottom: var(--spacing-medium);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-sizing: border-box;
    font-size: var(--font-size-base);
    background: var(--surface-color);
}

#sort-select {
    width: 100%;
    padding: var(--spacing-medium);
    margin-bottom: var(--spacing-medium);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-sizing: border-box;
    font-size: var(--font-size-base);
    background: var(--surface-color);
}

.sort-options {
    margin-bottom: var(--spacing-large);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-medium);
    font-size: var(--font-size-base);
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    transform: scale(1.2);
}

#layers-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-small);
}

.workspace-header {
    background: var(--panel-header-bg);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: var(--spacing-medium);
    margin-top: var(--spacing-medium);
}

.workspace-header:hover {
    background: #dde3e7;
}

.workspace-toggle {
    font-size: var(--font-size-small);
    transition: transform 0.2s;
}

.workspace-name {
    flex: 1;
}

.workspace-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-small);
    margin-left: var(--spacing-large);
    margin-bottom: var(--spacing-medium);
}

.layer-item {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: var(--font-size-base);
    display: flex;
    align-items: center;
    gap: 10px;
}

.layer-item:hover {
    background: var(--hover-bg);
}

.layer-item.active {
    background: var(--active-bg);
    color: var(--active-text);
}

.layer-checkbox {
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
    transform: scale(1.3);
}

.layer-name {
    flex: 1;
}


/* Buttons - unified styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    cursor: pointer;
    padding: 8px 12px;
    color: #fff;
    transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.btn:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}
.btn-sm {
    padding: 6px 10px;
    font-size: var(--font-size-small);
}
.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
}
.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
}
.btn-primary:hover { background: var(--primary-color-dark); }
.btn-secondary {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}
.btn-secondary:hover { background: var(--secondary-color-dark); }
.btn-neutral {
    background: var(--neutral-color);
    border-color: var(--neutral-color);
}
.btn-neutral:hover { background: var(--neutral-color-dark); }

/* Icon buttons used in layer list */
.zoom-btn,
.table-btn,
.config-btn {
    color: var(--active-text);
    border: none;
    border-radius: var(--border-radius);
    width: 28px;
    height: 28px;
    font-size: var(--font-size-small);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.zoom-btn { background: var(--primary-color); }
.zoom-btn:hover { background: var(--primary-color-dark); }
.table-btn { background: var(--secondary-color); margin-left: var(--spacing-small); }
.table-btn:hover { background: var(--secondary-color-dark); }
.config-btn { background: var(--neutral-color); margin-left: var(--spacing-small); }
.config-btn:hover { background: var(--neutral-color-dark); }

.zoom-btn:hover,
.table-btn:hover,
.config-btn:hover {
    background: var(--primary-color-dark);
}

.table-btn {
    background: var(--secondary-color);
    margin-left: var(--spacing-small);
}

.table-btn:hover {
    background: var(--secondary-color-dark);
}

.config-btn {
    background: #6c757d;
    margin-left: var(--spacing-small);
}

.config-btn:hover {
    background: #5a6268;
}

.layer-item.active .zoom-btn,
.layer-item.active .table-btn,
.layer-item.active .config-btn {
    background: rgba(255, 255, 255, 0.2);
    color: var(--active-text);
}

.layer-item.active .zoom-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.layer-item.active .table-btn:hover {
    background: rgba(40, 167, 69, 0.3);
}

.layer-item.active .config-btn:hover {
    background: rgba(108, 117, 125, 0.3);
}

#map {
    flex: 1;
    min-height: 30%;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

#layer-attributes-panel {
    height: 35%;
    background: var(--background-color);
    border-top: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    display: none;
    min-width: 0;
    overflow: hidden;
    min-height: 0;
}

#layer-attributes-header {
    background: var(--panel-header-bg);
    padding: 10px var(--spacing-large);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#layer-attributes-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-large);
}

#attribute-search {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 13px;
    min-width: 180px;
    background: var(--surface-color);
}

#attribute-search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--focus-ring);
}

#layer-attributes-header h3 {
    margin: 0;
    font-size: var(--font-size-large);
}

#close-layer-attributes {
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
}

#close-layer-attributes:hover {
    background: #d6d8db;
}

#layer-attributes-content {
    flex: 1;
    padding: var(--spacing-large);
    overflow: hidden;
    background: var(--background-color);
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.layer-attributes-table-container {
    overflow: auto;
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    width: 100%;
    max-width: 100%;
    min-height: 0;
}

#no-layer-selection {
    color: var(--text-color-light);
    font-style: italic;
    text-align: center;
    margin-top: 50px;
}

.layer-attributes-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--box-shadow);
    font-size: var(--font-size-small);
    table-layout: fixed;
    min-width: 800px;
}

.layer-attributes-table th,
.layer-attributes-table td {
    padding: 8px 10px;
    width: 150px;
    min-width: 80px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-right: 1px solid var(--border-color-light);
    border-bottom: 1px solid var(--border-color-light);
}

.layer-attributes-table th:first-child,
.layer-attributes-table td:first-child {
    width: 60px;
    min-width: 60px;
    max-width: 60px;
}

.layer-attributes-table th {
    background: var(--panel-header-bg);
    font-weight: bold;
    font-size: var(--font-size-small);
    text-transform: uppercase;
    color: var(--text-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.layer-attributes-table td {
    font-size: var(--font-size-small);
}

.layer-attributes-table tr:last-child td {
    border-bottom: none;
}

.layer-attributes-table tr:hover {
    background: var(--hover-bg);
}

.layer-attributes-table tr.selected {
    background: var(--selected-bg) !important;
    color: var(--selected-text);
}

.layer-attributes-table tr.selected td {
    border-bottom-color: rgba(255, 255, 255, 0.3);
    border-right-color: rgba(255, 255, 255, 0.3);
}

.layer-attributes-table th:last-child,
.layer-attributes-table td:last-child {
    border-right: none;
}

.feature-info {
    background: var(--surface-color);
    padding: 12px;
    margin-bottom: var(--spacing-large);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.feature-info h4 {
    margin: 0 0 var(--spacing-medium) 0;
    color: var(--primary-color);
    font-size: var(--font-size-base);
}

/* Feature Popup Styles */
.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.feature-popup .leaflet-popup-content {
    margin: 12px;
    font-size: var(--font-size-small);
    line-height: 1.4;
    max-width: 280px;
}

.feature-popup h4 {
    margin: 0 0 8px 0;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color-light);
    padding-bottom: 4px;
    font-size: var(--font-size-base);
}

.feature-popup p {
    margin: 3px 0;
    word-wrap: break-word;
}

.feature-popup button {
    margin-top: 5px;
    font-size: 11px;
}

/* Config Panel Overlay & Panel */
#popup-config-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    z-index: 1999;
}

#popup-config-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    min-width: 360px;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 2000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

#popup-config-panel h3 {
    margin: 0 0 15px 0;
    color: var(--text-color);
    font-size: var(--font-size-large);
}

#popup-config-panel label {
    display: block;
    margin: 5px 0;
    cursor: pointer;
    font-size: var(--font-size-base);
}

#popup-config-panel input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.1);
}

.popup-config-desc {
    margin: 0 0 15px 0;
    color: var(--text-color-light);
    font-size: var(--font-size-base);
}
.popup-config-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color-light);
    border-radius: var(--border-radius);
    padding: 10px;
}
.popup-config-actions {
    margin-top: 15px;
    text-align: right;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Inline status messages */
.status-message {
    text-align: center;
    padding: 20px;
    color: var(--text-color);
}
.status-message.error { color: #dc3545; }