/* ========================================
   GLOBAL STYLES
   ======================================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #1a1a1a;
    color: #ffffff;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    height: 100vh;
}

/* ========================================
   NAVIGATION BAR
   ======================================== */

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 16px 32px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-icon {
    font-size: 28px;
}

.nav-title {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    color: #cbd5e1;
    text-decoration: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.nav-link.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
}

.link-icon {
    font-size: 18px;
}

.nav-user {
    color: #cbd5e1;
    font-size: 16px;
    font-weight: 500;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    height: 40px;
    box-sizing: border-box;
}

/* ========================================
   DASHBOARD LAYOUT
   ======================================== */

.dashboard {
    display: flex;
    height: calc(100vh - 64px);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: linear-gradient(180deg, #2d3748 0%, #1a202c 100%);
    color: #f1f5f9;
    padding: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.sidebar h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
}

.subtitle {
    font-size: 15px;
    color: #a0aec0;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

.sidebar h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

/* Map Container */
#map {
    flex: 1;
    height: 100%;
    position: relative;
}

.map-filter-controls {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    background: rgba(45, 55, 72, 0.95);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.map-filter-controls label {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
}

.map-filter-controls .filter-select {
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    font-size: 14px;
    min-width: 200px;
    background: rgba(26, 32, 44, 0.9);
    color: #ffffff;
    cursor: pointer;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
    min-height: 42px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

.map-filter-controls .filter-select:focus {
    outline: none;
    border-color: #667eea;
}

.map-style-controls {
    left: auto;
    right: 12px;
}

.depth-filter {
    position: absolute;
    top: 110px;
    right: 14px;
    z-index: 10;
    background: rgba(26, 32, 44, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    border-radius: 12px;
    padding: 12px 10px;
    width: 88px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    color: #e2e8f0;
}

.depth-filter-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

.depth-filter-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #cbd5f5;
}

.depth-filter-reset {
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(30, 41, 59, 0.8);
    color: #e2e8f0;
    font-size: 11px;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    width: 100%;
}

.depth-filter-reset:hover {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(51, 65, 85, 0.85);
}

.depth-filter-reset:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.depth-filter-value {
    font-size: 13px;
    font-weight: 600;
    color: #f8fafc;
    background: transparent;
    border: 1px solid rgba(148, 163, 184, 0.7);
    border-radius: 6px;
    width: 100%;
    text-align: center;
    padding: 2px 4px;
    appearance: textfield;
}

.depth-filter-value:focus {
    outline: none;
    border-color: #cbd5f5;
    background: rgba(15, 23, 42, 0.45);
}

.depth-filter-value::-webkit-outer-spin-button,
.depth-filter-value::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.depth-filter-track {
    position: relative;
    height: 180px;
    width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: none;
}

.depth-filter-line {
    position: absolute;
    left: 50%;
    top: 0;
    width: 4px;
    height: 100%;
    background: rgba(148, 163, 184, 0.5);
    border-radius: 999px;
    transform: translateX(-50%);
    pointer-events: none;
}

.depth-range {
    position: absolute;
    left: 50%;
    top: 0;
    width: 32px;
    height: 180px;
    transform: translateX(-50%);
    appearance: slider-vertical;
    -webkit-appearance: slider-vertical;
    writing-mode: bt-lr;
    background: transparent;
    touch-action: none;
    pointer-events: none;
    opacity: 0;
}

.depth-range::-webkit-slider-runnable-track {
    width: 4px;
    height: 100%;
    background: transparent;
    border: none;
}

.depth-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #667eea;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    pointer-events: auto;
}

.depth-range:hover::-webkit-slider-thumb {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.depth-range:active::-webkit-slider-thumb {
    transform: scale(1.1);
}

.depth-range::-moz-range-track {
    width: 4px;
    height: 100%;
    background: transparent;
    border: none;
}

.depth-range::-moz-range-progress {
    background: transparent;
}

.depth-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #667eea;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    pointer-events: auto;
}

.depth-range:hover::-moz-range-thumb {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.depth-range:active::-moz-range-thumb {
    transform: scale(1.1);
}

.depth-handle {
    position: absolute;
    left: 50%;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border: 3px solid #667eea;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 2;
}

.compass-reset-control {
    margin-top: 8px;
}

.compass-reset-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: #ffffff;
    color: #111827;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    border: none;
}

.compass-reset-btn:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

.compass-reset-needle {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 10px solid #e53e3e;
    transform-origin: 50% 70%;
}

.compass-reset-label {
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.5px;
}

/* ========================================
   CONTROLS SECTION
   ======================================== */

.controls {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: block;
    margin-bottom: 6px;
    color: #e2e8f0;
    font-size: 14px;
    font-weight: 600;
}

.view-as-select {
    width: 100%;
    padding: 12px 15px;
    background: rgba(26, 32, 44, 0.6);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-sizing: border-box;
    min-height: 46px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

.view-as-select:hover {
    background: rgba(26, 32, 44, 0.8);
    border-color: rgba(255, 255, 255, 0.25);
}

.view-as-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.layer-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.layer-controls-toolbar {
    display: flex;
    justify-content: flex-end;
}

.layer-controls-toggle-all {
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: rgba(15, 23, 42, 0.5);
    color: #e2e8f0;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.layer-controls-toggle-all:hover {
    background: rgba(148, 163, 184, 0.2);
    border-color: rgba(148, 163, 184, 0.5);
}

.layer-group {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.35);
}

.layer-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.layer-group-title-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.layer-collapse-btn {
    border: none;
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.15);
    color: #cbd5f5;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background 0.2s ease;
}

.layer-collapse-btn:hover {
    background: rgba(148, 163, 184, 0.3);
}

.layer-collapse-symbol {
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.layer-group-title {
    font-size: 13px;
    font-weight: 700;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.layer-group-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.layer-group.is-collapsed .layer-group-list {
    display: none;
}

.layer-group.is-collapsed .layer-group-header {
    margin-bottom: 0;
}

.layer-group-empty {
    font-size: 12px;
    color: rgba(226, 232, 240, 0.6);
    padding: 6px 8px;
}

.layer-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 6px;
    transition: background-color 0.2s;
    user-select: none;
    color: #e2e8f0;
    font-size: 13px;
}

.layer-toggle:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.layer-toggle.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.layer-toggle-text {
    flex: 1;
}

.layer-toggle-input {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    margin-right: 12px;
    position: relative;
    transition: all 0.2s;
}

.layer-toggle-input:checked + .checkmark {
    border-color: transparent;
    background-color: var(--checkmark-color, #64748b);
}

.layer-toggle-input:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 14px;
    font-weight: bold;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.layer-toggle-input:disabled + .checkmark {
    opacity: 0.5;
}

.layer-type {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 4px;
}

.layer-type-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.layer-type-title-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.layer-type-title {
    font-size: 12px;
    font-weight: 600;
    color: #cbd5f5;
}

.layer-type-list {
    margin-left: 18px;
    padding-left: 12px;
    border-left: 2px solid rgba(148, 163, 184, 0.2);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.layer-type.is-collapsed .layer-type-list {
    display: none;
}

.layer-type-empty {
    font-size: 12px;
    color: rgba(226, 232, 240, 0.6);
    padding: 4px 6px;
}

.layer-item-toggle {
    position: relative;
    padding-left: 6px;
    font-size: 12px;
}

.layer-item-toggle::before {
    content: '';
    position: absolute;
    left: -18px;
    top: 50%;
    width: 12px;
    height: 1px;
    background: rgba(148, 163, 184, 0.35);
}

/* ========================================
   INFO BOX
   ======================================== */

.info-box {
    background-color: rgba(26, 32, 44, 0.5);
    padding: 16px;
    border-radius: 8px;
    border-left: 3px solid #667eea;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.info-box h3 {
    font-size: 15px;
    margin-bottom: 12px;
    color: #90cdf4;
    font-weight: 600;
}

.info-box ul {
    list-style: none;
    padding: 0;
}

.info-box li {
    font-size: 14px;
    line-height: 1.6;
    color: #cbd5e1;
    margin-bottom: 8px;
    padding-left: 16px;
    position: relative;
}

.info-box li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: #667eea;
}

.sensor-preview-box {
    margin-top: 16px;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sensor-preview-box h3 {
    margin: 0;
    font-size: 14px;
    color: #93c5fd;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sensor-preview-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 230px;
    overflow-y: auto;
}

.sensor-preview-empty {
    font-size: 12px;
    color: #94a3b8;
}

.sensor-preview-item {
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.62);
    padding: 8px 10px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.sensor-preview-item:hover {
    border-color: rgba(147, 197, 253, 0.65);
    background: rgba(30, 41, 59, 0.84);
}

.sensor-preview-item__head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    align-items: baseline;
}

.sensor-preview-item__name {
    font-size: 12px;
    font-weight: 700;
    color: #e2e8f0;
}

.sensor-preview-item__status {
    font-size: 10px;
    text-transform: uppercase;
    color: #bfdbfe;
}

.sensor-preview-item__meta {
    font-size: 11px;
    color: #cbd5e1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sensor-preview-item__metric {
    font-size: 11px;
    color: #f8fafc;
}

/* ========================================
   POPUP STYLES
   ======================================== */

.mapboxgl-popup-content {
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    width: max-content;
    max-width: min(860px, 92vw);
    min-width: 360px;
}

.mapboxgl-popup {
    max-width: min(860px, 92vw);
    z-index: 20;
}

.mapboxgl-marker {
    z-index: 15;
}

/* Make popup close button larger and easier to click */
.mapboxgl-popup-close-button {
    font-size: 28px !important;
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    line-height: 32px !important;
    color: #64748b !important;
    transition: all 0.2s ease !important;
}

.mapboxgl-popup-close-button:hover {
    background-color: #f1f5f9 !important;
    color: #1e293b !important;
}

.popup-content {
    padding: 16px;
    width: max-content;
    min-width: 360px;
    max-width: min(860px, 92vw);
    --popup-font-base: 11.5px;
    --popup-font-title: calc(var(--popup-font-base) * 1.618);
    font-size: var(--popup-font-base);
    line-height: 1.25;
}

.popup-content h3 {
    font-size: var(--popup-font-title);
    font-weight: 600;
    margin-bottom: 8px;
    color: #1e293b;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 6px;
}

.popup-content table {
    width: 100%;
    font-size: var(--popup-font-base);
    line-height: 1.25;
}

.popup-content table tr {
    border-bottom: 1px solid #f1f5f9;
}

.popup-content table tr:last-child {
    border-bottom: none;
}

.popup-content table td {
    padding: 4px 4px;
    white-space: nowrap;
}

.popup-content table td:first-child {
    color: #64748b;
    width: 40%;
}

.popup-content table td:last-child {
    font-weight: 500;
    color: #1e293b;
    width: 60%;
}

.popup-notes {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.popup-notes-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 4px;
}

.popup-notes-text {
    font-size: var(--popup-font-base);
    line-height: 1.4;
    color: #1e293b;
    white-space: normal;
    overflow-wrap: anywhere;
}

.popup-edit {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
}

.popup-edit-link {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #f59e0b;
    text-decoration: none;
    font-size: 16px;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.popup-edit-link:hover {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #b45309;
}

.edge-device-marker {
    border: 2px solid #ffffff;
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    color: #ffffff;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.edge-device-marker:hover {
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 6px 12px rgba(15, 23, 42, 0.42);
}

.edge-device-marker__icon {
    width: 66%;
    height: 66%;
    display: block;
}

.edge-device-marker--sensor {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #60a5fa;
}

.edge-device-marker--gateway {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: #1e293b;
}

.edge-device-marker--inactive {
    opacity: 0.45;
}

.edge-device-popup {
    min-width: 360px;
}

.edge-device-popup__loading {
    margin-top: 12px;
    color: #475569;
    font-size: 12px;
}

.edge-device-popup__tabs {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 8px;
}

.edge-device-popup__nav-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #1e293b;
    cursor: pointer;
    font-weight: 700;
}

.edge-device-popup__nav-btn:hover {
    background: #e2e8f0;
}

.edge-device-popup__param-title {
    flex: 1;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.edge-device-popup__chart {
    margin-bottom: 8px;
}

.edge-device-popup__chart svg {
    width: 100%;
    height: auto;
    display: block;
}

.edge-device-popup__chart-empty {
    padding: 14px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    color: #64748b;
    text-align: center;
    font-size: 12px;
}

.edge-device-popup__stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 6px;
    border-top: 1px solid #e2e8f0;
}

.edge-device-popup__stat {
    font-size: 11px;
    color: #475569;
}

.edge-device-popup__detail-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #93c5fd;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 700;
}

.edge-device-popup__detail-btn:hover {
    background: #bfdbfe;
    border-color: #60a5fa;
}

body.edge-focus-clean-view #timeline-widget,
body.edge-focus-clean-view #depth-filter,
body.edge-focus-clean-view .info-box,
body.edge-focus-clean-view #layer-controls,
body.edge-focus-clean-view .timeline-widget {
    display: none !important;
}

body.edge-focus-clean-view .dashboard {
    display: block;
}

body.edge-focus-clean-view #map {
    width: 100%;
}

/* Field Hover Popup Styling */
.field-hover-popup .mapboxgl-popup-content {
    background: rgba(26, 32, 44, 0.95);
    color: #ffffff;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    max-width: 300px;
    pointer-events: none; /* Prevents popup from interfering with clicks */
}

.field-hover-popup .mapboxgl-popup-tip {
    border-top-color: rgba(26, 32, 44, 0.95);
}

.field-hover-content h4 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 6px;
}

.field-hover-content p {
    margin: 6px 0 0 0;
    font-size: 13px;
    color: #cbd5e1;
    line-height: 1.4;
}

.field-hover-content .field-area {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

/* ========================================
   SCROLLBAR STYLING (for sidebar)
   ======================================== */

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(26, 32, 44, 0.3);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    .dashboard {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    
    #map {
        height: 60vh;
    }

    .depth-filter {
        right: 8px;
        top: auto;
        bottom: 140px;
        width: 82px;
    }
}

/* ========================================
   MAPBOX CONTROL CUSTOMIZATION
   ======================================== */

.mapboxgl-ctrl-group {
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mapboxgl-ctrl-group button {
    border-radius: 0;
}

.mapboxgl-ctrl-group button:first-child {
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.mapboxgl-ctrl-group button:last-child {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}

/* ========================================
   SAMPLE LEGEND (Bottom-Left Corner)
   ======================================== */

.sample-legend {
    position: absolute;
    bottom: 40px;
    left: 20px;
    background: linear-gradient(180deg, #2d3748 0%, #1a202c 100%);
    color: #f1f5f9;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-width: 280px;
    max-width: 320px;
    z-index: 10;
}

.legend-header {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #334155;
    padding-bottom: 8px;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.legend-header:hover {
    color: #ffffff;
}

.legend-toggle {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.sample-legend.collapsed .legend-toggle {
    transform: rotate(180deg);
}

.sample-legend.collapsed .legend-content {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    overflow: hidden;
}

.sample-legend.collapsed .legend-search-container {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    margin-bottom: 0;
    overflow: hidden;
}

.legend-search-container {
    margin-top: 12px;
    margin-bottom: 8px;
    transition: all 0.3s ease;
    max-height: 200px;
    opacity: 1;
}

.legend-filters {
    display: flex;
    gap: 6px;
}

.legend-type-dropdown {
    flex: 0 0 auto;
    width: 95px;
    padding: 7px 8px;
    background: rgba(26, 32, 44, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #ffffff;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 12px;
    padding-right: 24px;
}

.legend-type-dropdown:focus {
    background-color: rgba(26, 32, 44, 0.8);
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.legend-search-wrapper {
    flex: 1;
    position: relative;
}

.legend-search-input {
    width: 100%;
    padding: 7px 28px 7px 10px;
    background: rgba(26, 32, 44, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #ffffff;
    font-size: 12px;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.legend-search-input::placeholder {
    color: #a0aec0;
}

.legend-search-input:focus {
    background: rgba(26, 32, 44, 0.8);
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.legend-search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #a0aec0;
    font-size: 14px;
    cursor: pointer;
    padding: 3px 5px;
    line-height: 1;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: none;
}

.legend-search-clear:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.legend-search-clear.visible {
    display: block;
}

.legend-content {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 8px;
    transition: all 0.3s ease;
    opacity: 1;
}

.legend-loading {
    color: #a0aec0;
    font-size: 14px;
    font-style: italic;
    text-align: center;
    padding: 8px 0;
}

.legend-no-results {
    color: #a0aec0;
    font-size: 13px;
    font-style: italic;
    text-align: center;
    padding: 16px 0;
    display: none;
}

.legend-sample-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.legend-sample-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(102, 126, 234, 0.5);
    transform: translateX(4px);
}

.legend-sample-item:active {
    transform: translateX(2px);
    background: rgba(255, 255, 255, 0.08);
}

.legend-sample-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 10px;
    border: 2px solid #ffffff;
    flex-shrink: 0;
}

.legend-sample-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
    gap: 8px;
}

.legend-sample-id {
    font-size: 14px;
    font-weight: 600;
    color: #e2e8f0;
}

.legend-sample-type {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 8px;
    display: inline-block;
    letter-spacing: 0.3px;
}

.legend-sample-type.soil {
    background: #fef3c7;
    color: #92400e;
}

.legend-sample-type.water {
    background: #dbeafe;
    color: #1e40af;
}

/* Client view (no colors shown) */
.legend-sample-item.no-color {
    padding-left: 0;
}

.legend-sample-item.no-color .legend-sample-color {
    display: none;
}

/* Scrollbar styling for legend */
.legend-content::-webkit-scrollbar {
    width: 6px;
}

.legend-content::-webkit-scrollbar-track {
    background: rgba(26, 32, 44, 0.3);
    border-radius: 10px;
}

.legend-content::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 10px;
}

.legend-content::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* Responsive adjustments for legend */
@media (max-width: 768px) {
    .sample-legend {
        bottom: 10px;
        left: 10px;
        min-width: 200px;
        max-width: 280px;
        padding: 12px 16px;
    }

    .legend-content {
        max-height: 250px;
    }
}

/* ========================================
   UNIFIED TIMELINE & LEGEND WIDGET - SIDE-BY-SIDE LAYOUT
   ======================================== */

/* Main layout container */
.timeline-layout {
    display: flex;
    gap: 20px;
}

/* Left panel: Legend */
.timeline-legend-panel {
    flex: 0 0 300px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding-right: 20px;
}

.legend-header-inline {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #334155;
    padding-bottom: 8px;
    user-select: none;
}

.legend-panel-content {
    display: block;
}

.timeline-legend-panel .legend-content {
    max-height: 280px;
    overflow-y: auto;
    padding-right: 8px;
}

/* Right panel: Timeline */
.timeline-main-panel {
    flex: 1;
}

/* ========================================
   TIMELINE WIDGET (Bottom of Map)
   ======================================== */

.timeline-widget {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 400px);
    max-width: 1200px;
    min-width: 600px;
    background: linear-gradient(180deg, #2d3748 0%, #1a202c 100%);
    color: #f1f5f9;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    z-index: 500;
    transition: all 0.3s ease;
}

.timeline-widget.collapsed .timeline-content {
    display: none;
}

.timeline-widget.collapsed {
    width: auto;
    min-width: auto;
}

/* Hide expandable buttons when collapsed */
.timeline-widget.collapsed .timeline-btn-expandable {
    display: none;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    user-select: none;
}

.timeline-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    margin-right: 16px;
}

.timeline-icon {
    font-size: 20px;
}

.timeline-controls {
    display: flex;
    gap: 8px;
}

.timeline-btn {
    background: rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.3);
    color: #cbd5e1;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.timeline-btn:hover {
    background: rgba(102, 126, 234, 0.3);
    color: #ffffff;
    transform: translateY(-1px);
}

.timeline-play-btn.playing {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
}

.timeline-play-btn.playing:hover {
    background: rgba(239, 68, 68, 0.3);
}

.timeline-collapse-btn .collapse-icon {
    transition: transform 0.3s ease;
}

.timeline-widget.collapsed .collapse-icon {
    transform: rotate(180deg);
}

.timeline-content {
    padding: 20px;
}

/* Preset buttons */
.timeline-presets {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.timeline-preset-btn {
    background: rgba(71, 85, 105, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.timeline-preset-btn:hover {
    background: rgba(102, 126, 234, 0.3);
    border-color: rgba(102, 126, 234, 0.5);
    color: #ffffff;
}

.timeline-preset-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: #ffffff;
}

/* Date range display */
.timeline-date-range {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.timeline-date-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.timeline-date-input label {
    font-size: 13px;
    color: #94a3b8;
    font-weight: 500;
}

.timeline-date-picker {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #f1f5f9;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.timeline-date-picker:hover {
    border-color: rgba(102, 126, 234, 0.5);
}

.timeline-date-picker:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.timeline-sample-count {
    margin-left: auto;
    font-size: 13px;
    color: #94a3b8;
    padding: 6px 12px;
    background: rgba(30, 41, 59, 0.6);
    border-radius: 6px;
    font-weight: 500;
}

.timeline-sample-count span {
    color: #667eea;
    font-weight: 700;
}

/* Slider container */
.timeline-slider-container {
    position: relative;
    margin-top: 20px;
}

.timeline-histogram {
    width: 100%;
    height: 80px;
    display: block;
    border-radius: 6px;
    margin-bottom: 8px;
}

.timeline-slider {
    position: relative;
    height: 40px;
    margin: 0 16px;
}

.timeline-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 8px;
    background: rgba(71, 85, 105, 0.4);
    border-radius: 4px;
    transform: translateY(-50%);
}

.timeline-range {
    position: absolute;
    top: 50%;
    height: 8px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    transform: translateY(-50%);
    pointer-events: none;
}

.timeline-handle {
    position: absolute;
    top: 50%;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border: 3px solid #667eea;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    z-index: 10;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.timeline-handle:hover {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.timeline-handle:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.1);
}

.timeline-handle-label {
    position: absolute;
    top: -32px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.95);
    color: #f1f5f9;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.timeline-axis {
    display: flex;
    justify-content: space-between;
    padding: 8px 16px 0;
    font-size: 11px;
    color: #64748b;
}

.timeline-axis-label {
    text-align: center;
}

/* Responsive timeline */
@media (max-width: 1200px) {
    .timeline-widget {
        width: calc(100% - 200px);
        min-width: 400px;
    }

    .timeline-layout {
        flex-direction: column;
        gap: 16px;
    }

    .timeline-legend-panel {
        flex: 0 0 auto;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        padding-right: 0;
        padding-bottom: 16px;
    }

    .timeline-legend-panel .legend-content {
        max-height: 200px;
    }
}

@media (max-width: 768px) {
    .timeline-widget {
        width: calc(100% - 40px);
        min-width: 300px;
        bottom: 10px;
    }

    .timeline-presets {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .timeline-date-range {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .timeline-sample-count {
        margin-left: 0;
        width: 100%;
        text-align: center;
    }

    .timeline-legend-panel .legend-content {
        max-height: 150px;
    }
}
