/* ════════════════════════════════════════════════
   GEOSUITE PORTAL — DESIGN-SYSTEM FOUNDATION
   Shared portal tokens and utilities
   so the portal matches the marketing site visually.
   Per-page stylesheets (devices-styles.css, etc.) may still
   define their own scoped rules; foundation tokens are
   available to all of them via var(--…).
   ════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:ital,wght@0,400;0,500;0,600;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg:        #fafbfa;
    --bg-soft:   #f1f5f3;
    --surface:   #ffffff;
    --ink:       #0c1614;
    --ink-70:    #3a4644;
    --ink-50:    #6a7672;
    --ink-30:    #a2aba6;
    --line:      #e3e7e3;
    --line-soft: #ecefeb;

    --primary:        #0d6e63;
    --primary-dark:   #0a5249;
    --primary-soft:   #e6f3f0;
    --primary-tint:   #f0f8f6;

    --live:           #1ec077;
    --warn:           #d97706;
    --warn-soft:      #fef3e6;

    --font-h: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-b: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-m: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;

    --nav-h: 64px;
    --control-h: 46px;

    --shadow-sm: 0 1px 2px rgba(12, 22, 20, 0.04);
    --shadow-lg: 0 1px 2px rgba(12, 22, 20, 0.04),
                 0 12px 32px rgba(12, 22, 20, 0.08);
}

:root[data-theme="dark"],
:root.theme-dark {
    color-scheme: dark;
    --bg:        #0a1310;
    --bg-soft:   #131c19;
    --surface:   #131c19;
    --ink:       #ebf1ee;
    --ink-70:    #a5b4ad;
    --ink-50:    #6f7e76;
    --ink-30:    #4a544f;
    --line:      #233028;
    --line-soft: #1a2520;
    --primary:        #4dcfb8;
    --primary-dark:   #7de0cc;
    --primary-soft:   #1a3a34;
    --primary-tint:   #122520;
    --live:           #2ddc8a;
    --warn:           #f2a850;
    --warn-soft:      #2e2010;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.4),
                 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font-b);
    color: var(--ink);
    background: var(--bg);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}
/* The map page locks the viewport; other pages scroll normally. */
body.portal-map-page {
    overflow: hidden;
    height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-family: var(--font-h); font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.05; letter-spacing: -0.03em; }
h2 { font-size: clamp(22px, 2.6vw, 28px); line-height: 1.15; letter-spacing: -0.02em; }
h3 { font-size: 18px; line-height: 1.3; }
h4 { font-size: 14px; line-height: 1.35; }

/* ════════════════════════════════════════════════
   SHARED COMPONENT UTILITIES
   ════════════════════════════════════════════════ */
.eyebrow {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 5px 11px;
    background: var(--primary-soft);
    border-radius: 100px;
    color: var(--primary-dark);
    font-family: var(--font-m);
    font-size: 11px; font-weight: 500;
    letter-spacing: 0.06em; text-transform: uppercase;
}
.eyebrow .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--live);
    box-shadow: 0 0 0 0 rgba(30, 192, 119, 0.55);
    animation: pulse-dot 2s ease-in-out infinite;
}
.eyebrow.plain { background: transparent; padding: 0; color: var(--primary-dark); }
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(30, 192, 119, 0.55); }
    60%      { box-shadow: 0 0 0 8px rgba(30, 192, 119, 0); }
}

/* ════════════════════════════════════════════════
   BUTTON SYSTEM — canonical
   4 kinds: primary (filled ink), ghost (outlined),
            danger (filled warn), icon (square compact).
   Sizes: .btn-sm (32px) · default md (38px) · .btn-lg (44px).
   Legacy aliases (.btn-secondary, .btn-edit, .btn-delete,
   .btn-deactivate, .btn-activate, .btn-warning, .btn-refresh,
   .btn-action, .btn-details, .btn-remove, .btn-hide,
   .btn-reactivate, .btn-login, .btn-small) are mapped to one
   of the four kinds so HTML class names stay unchanged.
   ════════════════════════════════════════════════ */

/* Base box-model — applies to .btn AND every variant directly so HTML that
   uses only `class="btn-primary"` (no .btn) still gets the unified sizing.
   !important on height ensures we win over the per-page colour overrides
   later in this file that use !important for border-radius/font-family. */
.btn,
.btn-primary, .btn-secondary, .btn-ghost,
.btn-danger, .btn-warn, .btn-warning,
.btn-edit, .btn-view, .btn-hide,
.btn-delete, .btn-deactivate, .btn-remove,
.btn-activate, .btn-reactivate, .btn-refresh,
.btn-details, .btn-login,
.btn-icon, .btn-action,
.period-btn, .tab-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: var(--control-h) !important;
    min-height: var(--control-h) !important;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-b); font-size: 14px; font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1;
    box-sizing: border-box;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}
.btn:hover, .btn-primary:hover, .btn-secondary:hover, .btn-ghost:hover,
.btn-danger:hover, .btn-warn:hover, .btn-warning:hover,
.btn-edit:hover, .btn-view:hover, .btn-hide:hover,
.btn-delete:hover, .btn-deactivate:hover, .btn-remove:hover,
.btn-activate:hover, .btn-reactivate:hover, .btn-refresh:hover,
.btn-details:hover, .btn-login:hover,
.btn-icon:hover, .btn-action:hover,
.period-btn:hover, .tab-btn:hover { text-decoration: none; }

.btn:focus-visible, .btn-primary:focus-visible, .btn-secondary:focus-visible,
.btn-ghost:focus-visible, .btn-danger:focus-visible,
.btn-edit:focus-visible, .btn-delete:focus-visible,
.period-btn:focus-visible, .tab-btn:focus-visible,
.btn-action:focus-visible, .btn-icon:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn:disabled, .btn[aria-disabled="true"],
.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled,
.period-btn:disabled, .tab-btn:disabled,
.btn-action:disabled, .btn-icon:disabled { opacity: 0.55; cursor: not-allowed; }

/* Legacy size aliases — all resolve to the unified control height so every
   button across the app sits at the same baseline (no .btn-sm vs .btn-lg variance). */
.btn-sm, .btn-small,
.btn-lg            { height: var(--control-h); padding: 0 18px; font-size: 14px; }

/* ── Primary — filled ink, hover primary ── */
.btn-primary,
.btn-activate, .btn-reactivate, .btn-login {
    background: var(--ink); color: #fff;
    border-color: var(--ink);
}
.btn-primary:hover,
.btn-activate:hover, .btn-reactivate:hover, .btn-login:hover {
    background: var(--primary); border-color: var(--primary); color: #fff;
}

/* ── Ghost / secondary — outlined ── */
.btn-ghost, .btn-secondary,
.btn-edit, .btn-view, .btn-hide, .btn-refresh, .btn-details {
    background: transparent; color: var(--ink);
    border-color: var(--line);
}
.btn-ghost:hover, .btn-secondary:hover,
.btn-edit:hover, .btn-view:hover, .btn-hide:hover,
.btn-refresh:hover, .btn-details:hover {
    background: var(--bg-soft); border-color: var(--ink-30); color: var(--ink);
}

/* .btn-row is a LAYOUT WRAPPER (a <div>), not a button. Just an inline-flex
   container that lays out one or more buttons in a row with consistent gaps. */
.btn-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    background: transparent;
    border: 0;
    padding: 0;
    height: auto;
    width: auto;
}

/* ── Danger — filled warn for destructive actions ── */
.btn-danger, .btn-warn, .btn-warning,
.btn-delete, .btn-deactivate, .btn-remove {
    background: var(--warn); color: #fff;
    border-color: var(--warn);
}
.btn-danger:hover, .btn-warn:hover, .btn-warning:hover,
.btn-delete:hover, .btn-deactivate:hover, .btn-remove:hover {
    background: #b8620a; border-color: #b8620a; color: #fff;
}

/* ── Icon-only — square, transparent.
   Note: .btn-action is NOT in here — it's used everywhere with text labels
   (View / Edit / Delete / Deactivate / Reactivate / Details) and should be
   a normal-width pill button. Use .btn-icon for actually icon-only buttons. */
.btn-icon {
    width: var(--control-h) !important;
    padding: 0 !important;
    background: transparent;
    color: var(--ink-70);
    border-color: transparent;
    border-radius: var(--radius-sm);
}
.btn-icon:hover {
    background: var(--bg-soft); color: var(--ink);
    border-color: var(--ink-30);
}

/* Icon glyphs inside buttons */
.btn svg, .btn-action svg, .btn-icon svg {
    width: 16px; height: 16px; display: block;
    flex: 0 0 16px;
}

/* ── Dark-mode hover: primary-tint glow ─────────────────────────────
   On dark, neutral hover (bg-soft) becomes barely visible against
   the dark surface. Override ghost/icon hovers to a soft teal glow.
   Primary stays filled but hover goes to primary-dark for contrast.
   Danger stays warn-tinted (orange) and just darkens slightly. */
:root[data-theme="dark"] .btn-primary,
:root.theme-dark .btn-primary,
:root[data-theme="dark"] .btn-activate,
:root.theme-dark .btn-activate,
:root[data-theme="dark"] .btn-reactivate,
:root.theme-dark .btn-reactivate,
:root[data-theme="dark"] .btn-login,
:root.theme-dark .btn-login {
    background: var(--primary); color: var(--bg);
    border-color: var(--primary);
}
:root[data-theme="dark"] .btn-primary:hover,
:root.theme-dark .btn-primary:hover,
:root[data-theme="dark"] .btn-activate:hover,
:root.theme-dark .btn-activate:hover,
:root[data-theme="dark"] .btn-reactivate:hover,
:root.theme-dark .btn-reactivate:hover,
:root[data-theme="dark"] .btn-login:hover,
:root.theme-dark .btn-login:hover {
    background: var(--primary-dark); border-color: var(--primary-dark); color: var(--bg);
}

:root[data-theme="dark"] .btn-ghost:hover,
:root.theme-dark .btn-ghost:hover,
:root[data-theme="dark"] .btn-secondary:hover,
:root.theme-dark .btn-secondary:hover,
:root[data-theme="dark"] .btn-edit:hover,
:root.theme-dark .btn-edit:hover,
:root[data-theme="dark"] .btn-view:hover,
:root.theme-dark .btn-view:hover,
:root[data-theme="dark"] .btn-hide:hover,
:root.theme-dark .btn-hide:hover,
:root[data-theme="dark"] .btn-refresh:hover,
:root.theme-dark .btn-refresh:hover,
:root[data-theme="dark"] .btn-details:hover,
:root.theme-dark .btn-details:hover,
:root[data-theme="dark"] .btn-icon:hover,
:root.theme-dark .btn-icon:hover,
:root[data-theme="dark"] .btn-action:hover,
:root.theme-dark .btn-action:hover {
    background: rgba(77, 207, 184, 0.14);
    color: var(--primary);
    border-color: var(--primary);
}

:root[data-theme="dark"] .btn-danger:hover,
:root.theme-dark .btn-danger:hover,
:root[data-theme="dark"] .btn-warn:hover,
:root.theme-dark .btn-warn:hover,
:root[data-theme="dark"] .btn-warning:hover,
:root.theme-dark .btn-warning:hover,
:root[data-theme="dark"] .btn-delete:hover,
:root.theme-dark .btn-delete:hover,
:root[data-theme="dark"] .btn-deactivate:hover,
:root.theme-dark .btn-deactivate:hover,
:root[data-theme="dark"] .btn-remove:hover,
:root.theme-dark .btn-remove:hover {
    background: #b8620a; border-color: #b8620a; color: #fff;
}

/* ════════════════════════════════════════════════
   PORTAL FRAME — used by index.html
   Wraps the full-width Mapbox map and its controls
   ════════════════════════════════════════════════ */
.portal-frame {
    position: relative;
    height: calc(100vh - var(--nav-h));
    height: calc(100dvh - var(--nav-h));
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg);
}
.portal-frame > #map {
    position: relative;
    grid-column: 1;
    grid-row: 1;
    height: 100%;
    width: 100%;
}
.portal-bar {
    position: absolute;
    top: 12px; left: 12px;
    z-index: 20;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.85);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    backdrop-filter: saturate(180%) blur(10px);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    font-family: var(--font-m); font-size: 11px;
    color: var(--ink-70);
    letter-spacing: 0.02em;
}
:root[data-theme="dark"] .portal-bar,
:root.theme-dark .portal-bar { background: rgba(19, 28, 25, 0.85); }
.portal-bar-live { color: var(--ink); font-weight: 500; }
.portal-bar-sep  { color: var(--ink-30); }
.portal-bar-time { color: var(--ink-50); }
.portal-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--live);
    box-shadow: 0 0 0 0 rgba(30, 192, 119, 0.55);
    animation: pulse-dot 2s ease-in-out infinite;
}

@media (max-width: 900px) {
    .portal-frame { grid-template-columns: 1fr; }
    .portal-frame > #map {
        grid-column: 1;
        grid-row: 1;
    }
}

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

.dashboard {
    display: flex;
    height: calc(100vh - var(--nav-h));
    overflow: hidden;
}

body.portal-map-page .dashboard {
    height: calc(100vh - var(--nav-h));
    height: calc(100dvh - var(--nav-h));
}

/* 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: var(--surface);
    padding: 9px 10px 11px;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(12, 22, 20, 0.07), 0 16px 40px rgba(12, 22, 20, 0.14);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    border: 1px solid var(--line);
    width: min(260px, calc(100% - 24px));
    max-width: calc(100% - 24px);
    font-family: var(--font-m);
}

.map-filter-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
}

.map-controls-toggle {
    display: none;
}

.map-controls-body {
    display: grid;
    gap: 8px;
}

.map-filter-controls label {
    font-size: 10px;
    font-weight: 600;
    color: var(--ink-50);
    white-space: nowrap;
    letter-spacing: 0.04em;
}

.map-filter-controls .filter-select {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-family: var(--font-m);
    font-size: 12px;
    min-width: 0;
    width: 100%;
    background-color: var(--bg-soft);
    color: var(--ink);
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    box-sizing: border-box;
    min-height: 36px;
    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='%236a7672' 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: 14px;
    padding-right: 34px;
}

.map-filter-controls .filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.map-filter-controls .filter-select:disabled {
    cursor: wait;
    opacity: 0.65;
}

.map-style-controls {
    margin-left: 0;
}

.map-device-status-key {
    display: flex;
    flex-wrap: wrap;
    gap: 7px 12px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    color: var(--ink-50);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
}

.map-device-status-key__item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.map-device-status-key__dot {
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(12, 22, 20, 0.18);
}

.map-device-status-key__dot--online {
    background: #16875f;
}

.map-device-status-key__dot--offline {
    background: #dc2626;
}

.map-device-status-key__dot--gateway {
    background: var(--ink);
    border-radius: 3px;
}

.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;
}

.edge-device-mapbox-popup {
    max-width: min(280px, calc(100vw - 24px));
}

.edge-device-mapbox-popup .mapboxgl-popup-content {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    min-width: 0;
    width: auto;
    max-width: min(280px, calc(100vw - 24px));
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(12, 22, 20, 0.07), 0 16px 40px rgba(12, 22, 20, 0.14);
}

.edge-device-mapbox-popup .mapboxgl-popup-close-button {
    top: 6px !important;
    right: 7px !important;
    width: 18px !important;
    height: 18px !important;
    font-size: 16px !important;
    line-height: 18px !important;
    color: var(--ink-50) !important;
}

.edge-device-mapbox-popup .mapboxgl-popup-tip {
    border-top-color: var(--surface);
    border-bottom-color: var(--surface);
}

.edge-device-mapbox-popup.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip,
.edge-device-mapbox-popup.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip,
.edge-device-mapbox-popup.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip {
    border-top-color: var(--surface);
}

.edge-device-mapbox-popup.mapboxgl-popup-anchor-top .mapboxgl-popup-tip,
.edge-device-mapbox-popup.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip,
.edge-device-mapbox-popup.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip {
    border-bottom-color: var(--surface);
}

.mapboxgl-marker {
    z-index: 15;
    transition: none !important;
}

.edge-device-marker-host {
    display: block;
    pointer-events: auto;
}

/* 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 {
    position: relative;
    border: 0;
    background: transparent;
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    color: var(--primary);
    transition: none;
    font-family: var(--font-m);
    pointer-events: auto;
}

.edge-device-marker:hover {
    box-shadow: none;
}

.edge-device-marker:hover .edge-device-marker__dot {
    transform: scale(1.08);
}

.edge-device-marker:hover .edge-device-marker__pulse {
    opacity: 0.26;
}

.edge-device-marker__pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.15;
    animation: sensor-ripple-map 2.4s ease-out infinite;
}

.edge-device-marker__dot {
    position: relative;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: currentColor;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 7px rgba(12, 22, 20, 0.24);
}

.edge-device-marker__label {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--ink);
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9);
    white-space: nowrap;
}

:root[data-theme="dark"] .edge-device-marker__label,
:root.theme-dark .edge-device-marker__label {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}

.edge-device-marker--warn {
    color: var(--warn);
}

.edge-device-marker--warn .edge-device-marker__label {
    color: var(--warn);
}

.edge-device-marker--sensor.edge-device-marker--status-online {
    color: #16875f;
}

.edge-device-marker--sensor.edge-device-marker--status-offline {
    color: #dc2626;
}

.edge-device-marker--sensor.edge-device-marker--status-offline .edge-device-marker__label {
    color: #dc2626;
}

.edge-device-marker--sensor.edge-device-marker--status-offline .edge-device-marker__pulse,
.edge-device-marker--sensor.edge-device-marker--status-inactive .edge-device-marker__pulse {
    animation: none;
    opacity: 0.12;
    transform: scale(0.72);
}

@keyframes sensor-ripple-map {
    0% { transform: scale(0.42); opacity: 0.24; }
    70% { transform: scale(1); opacity: 0.06; }
    100% { transform: scale(1.08); opacity: 0; }
}

.edge-device-marker--sensor {
    width: 54px;
    height: 54px;
    border-radius: 999px;
}

.edge-device-marker--gateway {
    width: 58px;
    height: 58px;
    color: var(--ink);
}

.edge-device-marker--gateway .edge-device-marker__pulse,
.edge-device-marker--gateway .edge-device-marker__dot {
    border-radius: 10px;
}

.edge-device-marker--gateway .edge-device-marker__dot {
    width: 24px;
    height: 24px;
    background: var(--ink);
}

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

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

.edge-device-popup__loading {
    margin-top: 12px;
    color: var(--ink-50);
    font-size: 10px;
}

.edge-device-popup__empty {
    padding: 14px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--ink-50);
    text-align: center;
    font-size: 10px;
}

.popup-content.edge-device-popup {
    width: min(260px, calc(100vw - 32px));
    min-width: min(220px, calc(100vw - 32px));
    max-width: min(260px, calc(100vw - 32px));
    padding: 0;
    --popup-font-base: 10px;
    --popup-font-title: 11px;
    overflow: hidden;
    font-family: var(--font-m);
}

.edge-device-popup__header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 32px 8px 10px;
    background: rgba(13, 110, 99, 0.06);
    border-bottom: 1px solid var(--line);
}

.edge-device-popup__title {
    min-width: 0;
    flex: 1;
    color: var(--primary-dark);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.edge-device-popup__live {
    color: var(--live);
    font-size: 9px;
    white-space: nowrap;
}

.edge-device-popup__body {
    display: grid;
    gap: 7px;
    padding: 9px 10px 11px;
}

.popup-content.edge-device-popup table {
    margin: 0;
    font-size: 10px;
}

.popup-content.edge-device-popup table tr {
    border-bottom: 0;
}

.popup-content.edge-device-popup table td {
    padding: 2px 0;
    white-space: normal;
}

.popup-content.edge-device-popup table td:first-child {
    color: var(--ink-50);
    width: 44%;
}

.popup-content.edge-device-popup table td:last-child {
    color: var(--ink);
    font-weight: 600;
    text-align: right;
}

.popup-content.edge-device-popup .popup-edit {
    display: flex;
    justify-content: flex-end;
    margin: 6px 0 0;
}

.popup-content.edge-device-popup .edge-device-popup__latest {
    display: grid;
    gap: 7px;
}

.popup-content.edge-device-popup .edge-device-popup__latest-head {
    display: none;
}

.popup-content.edge-device-popup .edge-device-popup__latest-head span:last-child {
    color: #64748b;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: none;
    white-space: nowrap;
}

.popup-content.edge-device-popup .edge-device-popup__metric-list {
    display: grid;
    gap: 7px;
}

.popup-content.edge-device-popup .edge-device-popup__metric-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    min-height: 0;
    padding: 0;
    border-bottom: 0;
}

.popup-content.edge-device-popup .edge-device-popup__metric-name {
    min-width: 0;
    color: var(--ink-50) !important;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.popup-content.edge-device-popup .edge-device-popup__metric-reading {
    color: var(--ink) !important;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    text-align: right;
    white-space: nowrap;
}

.popup-content.edge-device-popup .sp-unit {
    color: var(--ink-50);
    font-size: 10px;
    font-weight: 500;
}

.popup-content.edge-device-popup .edge-device-popup__metric-row--empty .edge-device-popup__metric-reading {
    color: #94a3b8 !important;
}

.edge-device-popup__stats {
    display: grid;
    gap: 7px;
    padding-top: 0;
    border-top: 0;
}

.popup-content.edge-device-popup .edge-device-popup__stat {
    display: block;
    padding: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink-50) !important;
    font-size: 10px;
    font-weight: 500;
}

.popup-content.edge-device-popup .edge-device-popup__stat strong {
    color: var(--ink) !important;
    font-weight: 600;
}

.edge-device-popup__detail-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: 8px 11px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-family: var(--font-m);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.edge-device-popup__detail-btn:hover {
    background: var(--primary-tint);
    border-color: var(--primary);
    color: var(--primary-dark);
    text-decoration: none;
}

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: var(--line-soft);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

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

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

    body.portal-map-page .dashboard {
        height: calc(100vh - 72px);
        height: calc(100dvh - 72px);
        flex-direction: row;
    }

    .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;
    }

    body.portal-map-page #map {
        height: 100%;
        min-height: 0;
    }

    .map-filter-controls {
        top: 8px;
        left: 8px;
        width: min(260px, calc(100% - 16px));
        max-width: calc(100% - 16px);
        padding: 8px 10px;
        gap: 8px;
        border-radius: var(--radius);
    }

    .map-filter-group {
        width: 100%;
    }

    .map-filter-controls label {
        font-size: 12px;
    }

    .map-filter-controls .filter-select {
        min-width: 0;
        width: 100%;
        min-height: 38px;
        padding: 8px 12px;
        padding-right: 34px;
        font-size: 15px;
        background-size: 14px;
        background-position: right 10px center;
    }

    .map-controls-toggle {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        border: 1px solid var(--line);
        border-radius: var(--radius-sm);
        background: var(--bg-soft);
        color: var(--ink);
        padding: 8px 10px;
        font-family: var(--font-m);
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.04em;
        cursor: pointer;
    }

    .map-controls-toggle-icon {
        display: inline-flex;
        transition: transform 0.2s ease;
    }

    .map-filter-controls.is-collapsed .map-controls-body {
        display: none;
    }

    .map-filter-controls.is-collapsed .map-controls-toggle-icon {
        transform: rotate(-180deg);
    }

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

    .navbar {
        padding: 12px 16px;
    }

    .mapboxgl-popup-content,
    .popup-content,
    .edge-device-popup {
        min-width: min(340px, calc(100vw - 32px));
    }
}

/* ========================================
   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: var(--line-soft);
    border-radius: 10px;
}

.legend-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.legend-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* 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;
    }
}

/* ========================================
   PORTAL-WIDE STYLE NORMALIZATION
   Keeps legacy pages aligned with the home/map visual system.
   ======================================== */

body:not(.portal-map-page) {
    font-family: var(--font-b);
    background: var(--bg);
    color: var(--ink);
    padding: 0 !important;
    overflow-x: hidden;
    min-width: 0;
}

* {
    scrollbar-color: var(--primary) var(--line-soft);
}

::selection {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

input[type="checkbox"],
input[type="radio"],
input[type="range"],
progress {
    accent-color: var(--primary);
}

:root *::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

:root *::-webkit-scrollbar-track {
    background: var(--line-soft);
}

:root *::-webkit-scrollbar-thumb {
    background: var(--primary);
    border: 2px solid var(--line-soft);
    border-radius: 999px;
}

:root *::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

button,
input,
select,
textarea,
table {
    font-family: var(--font-b);
}

.nav-link,
.nav-user,
.tab-btn,
.badge,
.status-badge,
.role-badge,
.metric-chip,
.period-label,
.kpi-label,
.btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-warning,
.btn-refresh,
.btn-edit,
.btn-delete,
.btn-deactivate,
.btn-activate,
.btn-action {
    letter-spacing: 0;
}

.container,
.main-content,
.table-container,
.form-card,
.form-section,
.stats-section,
.modal-content,
.analytics-kpi,
.analytics-panel,
.org-form-card,
.org-sync-highlight,
.plot-editor-page .plot-editor-sidebar,
.plot-editor-page .plot-editor-map-panel,
.plot-editor-page .plot-map-surface,
.plot-editor-page .plot-map-toolbar,
.plot-editor-page .plot-stats-card,
.form-container {
    background: var(--surface) !important;
    color: var(--ink);
    border-color: var(--line) !important;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius) !important;
}

.container {
    border: 1px solid var(--line);
    border-radius: var(--radius) !important;
}

body:not(.portal-map-page) > .container,
body:not(.portal-map-page) > .tabs-wrapper,
body:not(.portal-map-page) > .management-container,
body:not(.portal-map-page) > .main-content,
body:not(.portal-map-page) .tabs-wrapper + .container {
    width: min(1480px, calc(100vw - clamp(1.5rem, 4vw, 3rem)));
    max-width: calc(100vw - clamp(1.5rem, 4vw, 3rem)) !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

body:not(.portal-map-page) > .container,
body:not(.portal-map-page) > .main-content {
    margin-top: clamp(1rem, 2.4vw, 1.6rem) !important;
    margin-bottom: clamp(1.5rem, 3vw, 2.5rem) !important;
}

body:not(.portal-map-page) > .tabs-wrapper {
    margin-top: clamp(1rem, 2.4vw, 1.6rem) !important;
}

body:not(.portal-map-page) > .management-container {
    margin-top: 0 !important;
    padding: 0 0 clamp(1.5rem, 3vw, 2.5rem) !important;
}

body:not(.portal-map-page) .tabs-wrapper + .container {
    margin-top: 0 !important;
}

body:not(.portal-map-page) > .dashboard,
body:not(.portal-map-page) .management-container,
body:not(.portal-map-page) .management-container .dashboard,
body:not(.portal-map-page) .dashboard > .sidebar,
body:not(.portal-map-page) .dashboard > .main-content,
body:not(.portal-map-page) .dashboard > .map-container,
body:not(.portal-map-page) .import-dashboard,
body.plot-editor-page .plot-editor-shell {
    max-width: 100vw;
    min-width: 0;
}

body:not(.portal-map-page) .dashboard > .main-content,
body:not(.portal-map-page) .import-content,
body.plot-editor-page .plot-editor-map-panel {
    min-width: 0;
}

body:not(.portal-map-page) .page-header,
body:not(.portal-map-page) .content-header,
body:not(.portal-map-page) .filter-controls,
body:not(.portal-map-page) .edge-filter-controls,
body:not(.portal-map-page) .device-controls,
body:not(.portal-map-page) .trend-toolbar,
body:not(.portal-map-page) .period-row,
body:not(.portal-map-page) .custom-date-row,
body:not(.portal-map-page) .table-container,
body:not(.portal-map-page) .table-wrapper,
body:not(.portal-map-page) .analytics-grid,
body:not(.portal-map-page) .analytics-kpi-grid {
    min-width: 0;
}

body:not(.portal-map-page) .table-wrapper,
body:not(.portal-map-page) .analytics-table-wrap {
    max-width: 100%;
}

@media (max-width: 768px) {
    body:not(.portal-map-page) > .container,
    body:not(.portal-map-page) > .tabs-wrapper,
    body:not(.portal-map-page) > .management-container,
    body:not(.portal-map-page) .tabs-wrapper + .container {
        width: calc(100vw - 1rem);
        max-width: calc(100vw - 1rem) !important;
    }

    body:not(.portal-map-page) > .container,
    body:not(.portal-map-page) > .main-content {
        padding: 1rem !important;
    }

    body:not(.portal-map-page) .page-header,
    body:not(.portal-map-page) .content-header,
    body:not(.portal-map-page) .form-card,
    body:not(.portal-map-page) .form-section,
    body:not(.portal-map-page) .stats-section,
    body:not(.portal-map-page) .analytics-panel {
        padding: 1rem !important;
    }
}

.page-header,
.content-header {
    background: var(--surface) !important;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius) !important;
}

.sidebar {
    background: var(--surface) !important;
    color: var(--ink);
    border-right-color: var(--line) !important;
    border-radius: 0 !important;
}

.tabs-wrapper + .container,
.tab-content.active .dashboard {
    border-radius: var(--radius) !important;
}

.tab-content.active .dashboard {
    overflow: hidden;
}

.table-container,
.analytics-kpi,
.analytics-panel,
.form-card,
.form-section,
.stats-section {
    overflow: hidden;
}

/* Portal islands need enough breathing room for dense forms, charts, and tables. */
.container,
.main-content,
.form-container {
    padding: clamp(1.5rem, 2.2vw, 2.4rem) !important;
}

.page-header,
.content-header,
.form-card,
.form-section,
.stats-section,
.analytics-panel,
.org-form-card,
.org-sync-highlight,
.plot-editor-page .plot-editor-sidebar,
.plot-editor-page .plot-editor-map-panel,
.plot-editor-page .plot-map-toolbar,
.plot-editor-page .plot-stats-card {
    padding: clamp(1.15rem, 1.8vw, 1.8rem) !important;
}

.analytics-panel {
    overflow: visible;
}

.table-container,
.form-card,
.form-section,
.stats-section,
.analytics-panel,
.analytics-kpi,
.org-form-card,
.org-sync-highlight {
    margin-bottom: clamp(1.25rem, 2vw, 1.8rem);
}

.table-container:last-child,
.form-card:last-child,
.form-section:last-child,
.stats-section:last-child,
.analytics-panel:last-child,
.analytics-kpi:last-child,
.org-form-card:last-child,
.org-sync-highlight:last-child {
    margin-bottom: 0;
}

.table-container {
    padding: clamp(0.7rem, 1.2vw, 1rem);
}

.table-container .table-header {
    border-radius: calc(var(--radius) - 4px) calc(var(--radius) - 4px) 0 0;
    margin: 0;
    padding: clamp(1rem, 1.6vw, 1.45rem) clamp(1.1rem, 1.8vw, 1.6rem);
}

.table-container .table-wrapper {
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 calc(var(--radius) - 4px) calc(var(--radius) - 4px);
    margin: 0;
}

.table-container .table-footer {
    padding: clamp(0.9rem, 1.4vw, 1.2rem) clamp(0.2rem, 0.8vw, 0.7rem) 0;
}

.panel-head {
    min-width: 0;
}

.panel-head > div,
.panel-meta {
    min-width: 0;
}

.panel-meta {
    overflow-wrap: anywhere;
}

.page-header h1,
.page-header h2,
.content-header h1,
.content-header h2,
.sidebar h1,
.form-section h2,
.stats-section h3,
.modal-content h2 {
    background: none !important;
    -webkit-background-clip: border-box !important;
    -webkit-text-fill-color: currentColor !important;
    background-clip: border-box !important;
    color: var(--ink) !important;
    font-family: var(--font-h);
}

.subtitle,
.page-description,
.panel-meta,
.helper-text,
.stat-label,
.form-group label,
.filter-controls label,
.trend-select-group label,
.analytics-controls label,
.data-table th,
#users-table th,
#inactive-users-table th,
#org-table th,
#org-table-inactive th,
#plot-table th,
#tenant-table th,
#org-tenant-overview-table th {
    color: var(--ink-70) !important;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group textarea,
.form-group select,
.filter-select,
.search-input,
.view-as-select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
    background-color: var(--bg-soft) !important;
    color: var(--ink) !important;
    border: 1px solid var(--line) !important;
    border-radius: var(--radius-sm) !important;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.filter-select:focus,
.search-input:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px var(--primary-soft) !important;
    outline: none !important;
}

.btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-warning,
.btn-refresh,
.btn-edit,
.btn-delete,
.btn-deactivate,
.btn-activate,
.btn-action,
.period-btn {
    border-radius: var(--radius-sm) !important;
    font-family: var(--font-b);
    font-weight: 600;
    box-shadow: none !important;
    transform: none !important;
}

.btn-primary,
.btn-refresh,
.btn-activate,
.btn-action.btn-view,
.btn-action.btn-reactivate {
    background: var(--primary) !important;
    border: 1px solid var(--primary) !important;
    color: var(--bg) !important;
}

.btn-primary:hover,
.btn-refresh:hover,
.btn-activate:hover,
.btn-action.btn-view:hover,
.btn-action.btn-reactivate:hover {
    background: var(--primary-dark) !important;
    border-color: var(--primary-dark) !important;
}

.btn-secondary,
.period-btn,
.btn-action {
    background: var(--bg-soft) !important;
    border: 1px solid var(--line) !important;
    color: var(--ink) !important;
}

.btn-secondary:hover,
.period-btn:hover,
.btn-action:hover {
    background: var(--primary-soft) !important;
    border-color: var(--primary) !important;
    color: var(--primary-dark) !important;
}

.btn-danger,
.btn-warning,
.btn-delete,
.btn-deactivate,
.btn-action.btn-delete,
.btn-action.btn-hide {
    background: var(--warn-soft) !important;
    border: 1px solid var(--warn) !important;
    color: var(--warn) !important;
}

.btn-danger:hover,
.btn-warning:hover,
.btn-delete:hover,
.btn-deactivate:hover,
.btn-action.btn-delete:hover,
.btn-action.btn-hide:hover {
    background: var(--warn) !important;
    color: var(--bg) !important;
}

.tab-btn {
    background: var(--surface) !important;
    color: var(--ink-70) !important;
    border: 1px solid var(--line) !important;
    box-shadow: none !important;
    font-family: var(--font-h);
}

.tab-btn:hover,
.tab-btn.active {
    background: var(--primary-soft) !important;
    color: var(--primary-dark) !important;
}

.tab-btn.active::after {
    background: var(--primary-soft) !important;
}

.data-table,
#users-table,
#inactive-users-table,
#org-table,
#org-table-inactive,
#plot-table,
#tenant-table,
#org-tenant-overview-table {
    background: var(--surface);
    color: var(--ink);
}

.data-table thead,
#users-table thead,
#inactive-users-table thead,
#org-table thead,
#org-table-inactive thead,
#plot-table thead,
#tenant-table thead,
#org-tenant-overview-table thead,
#plotsTab #plot-table thead {
    background: var(--primary-soft) !important;
    color: var(--primary-dark) !important;
}

.data-table tbody tr,
#users-table tbody tr,
#inactive-users-table tbody tr,
#org-table tbody tr,
#org-table-inactive tbody tr,
#plot-table tbody tr,
#tenant-table tbody tr,
#org-tenant-overview-table tbody tr {
    border-bottom-color: var(--line) !important;
}

.data-table tbody tr:hover,
#users-table tbody tr:hover,
#inactive-users-table tbody tr:hover,
#org-table tbody tr:hover,
#org-table-inactive tbody tr:hover,
#plot-table tbody tr:hover,
#tenant-table tbody tr:hover,
#org-tenant-overview-table tbody tr:hover {
    background: var(--bg-soft) !important;
}

.data-table td,
#users-table td,
#inactive-users-table td,
#org-table td,
#org-table-inactive td,
#plot-table td,
#tenant-table td,
#org-tenant-overview-table td {
    color: var(--ink) !important;
}

.role-badge,
.role-badge.admin,
.role-badge.client,
.role-badge.super_admin,
.role-badge.org_admin,
.role-badge.user,
.role-badge.viewer,
.status-badge.active,
.status-pill.online,
.badge-good,
.badge-water {
    background: var(--primary-soft) !important;
    color: var(--primary-dark) !important;
}

.status-badge.inactive,
.status-pill.offline,
.badge-soil,
.badge-moderate,
.badge-poor {
    background: var(--warn-soft) !important;
    color: var(--warn) !important;
}

.metric-chip,
.tenant-summary__meta span {
    background: var(--primary-soft) !important;
    border-color: var(--primary-soft) !important;
    color: var(--primary-dark) !important;
}

.metric-chip strong,
.tenant-summary__meta span {
    color: var(--primary-dark) !important;
}

.metric-chip--last-known {
    background: var(--bg-soft) !important;
    border-color: var(--line) !important;
    color: var(--ink-50) !important;
}

.analytics-chart-wrap canvas {
    background: var(--surface);
}

:root[data-theme="dark"] .container,
:root.theme-dark .container,
:root[data-theme="dark"] .main-content,
:root.theme-dark .main-content {
    background: #0f1c18 !important;
    border-color: var(--line) !important;
}

:root[data-theme="dark"] .page-header,
:root.theme-dark .page-header,
:root[data-theme="dark"] .content-header,
:root.theme-dark .content-header,
:root[data-theme="dark"] .table-header,
:root.theme-dark .table-header {
    background: var(--surface) !important;
    border-color: var(--line) !important;
}

/* ════════════════════════════════════════════════
   FORM CONTROLS — unified height
   Every text input, select, and form-row button sits on the same
   --control-h baseline (46px) so toolbars line up regardless of
   which page CSS originally declared them. Textareas use it as
   min-height (they still grow with content).
   !important is used deliberately on sizing so per-page CSS that
   sets its own min-height: 46px / 38px / 32px is overridden — this
   is the design-system invariant the rest of the app rallies around.
   ════════════════════════════════════════════════ */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
input:not([type]),
select,
.filter-select {
    height: var(--control-h) !important;
    min-height: var(--control-h) !important;
    padding: 0 14px !important;
    font-family: var(--font-b);
    font-size: 14px;
    line-height: 1;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    box-sizing: border-box;
    transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
select,
.filter-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 36px !important;
    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='%233a4644' stroke-width='1.8' 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;
    cursor: pointer;
}
:root[data-theme="dark"] select,
:root.theme-dark select,
:root[data-theme="dark"] .filter-select,
:root.theme-dark .filter-select {
    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='%23a5b4ad' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

textarea {
    min-height: var(--control-h);
    padding: 12px 14px;
    font-family: var(--font-b);
    font-size: 14px;
    line-height: 1.5;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    box-sizing: border-box;
    resize: vertical;
    transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

input:focus,
select:focus,
.filter-select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 99, 0.12);
}
:root[data-theme="dark"] input:focus,
:root.theme-dark input:focus,
:root[data-theme="dark"] select:focus,
:root.theme-dark select:focus,
:root[data-theme="dark"] .filter-select:focus,
:root.theme-dark .filter-select:focus,
:root[data-theme="dark"] textarea:focus,
:root.theme-dark textarea:focus {
    box-shadow: 0 0 0 3px rgba(77, 207, 184, 0.18);
}

input::placeholder,
textarea::placeholder { color: var(--ink-50); }
/* Shared state/layout utilities used by static markup and overridden by runtime state. */
.initially-hidden { display: none; }
.section-spacing { margin-top: 2rem; }
.full-width { width: 100%; }
.filter-min-width { min-width: 260px; margin: 0; }
.readonly-preview { background: #f5f5f5; }
.threshold-spacing { margin-top: 0.5rem; }
.moved-page { padding-top: 2rem; }
.button-link { text-decoration: none; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
