* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    overflow: hidden;
}

/* LOGIN */
.login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: radial-gradient(1200px 800px at 30% 20%, rgba(78, 161, 255, 0.18), transparent 60%),
        radial-gradient(900px 600px at 75% 80%, rgba(255, 181, 71, 0.12), transparent 60%), var(--bg-deep);
    z-index: 1000;
}

.login-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 22px 36px;
}

.logo-mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, #4ea1ff, #7d6cff 60%, #ffb547);
    display: grid;
    place-items: center;
    font-weight: 800;
    color: var(--bg-deep);
    font-size: 18px;
    box-shadow: 0 4px 16px rgba(78, 161, 255, 0.4);
}

.logo-mark svg {
    width: 26px;
    height: 26px;
}

.brand {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand .name {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand .tag {
    font-size: 12px;
    color: var(--text-dim);
}

.login-body {
    flex: 1;
    display: grid;
    place-items: center;
}

.login-card {
    width: 380px;
    background: rgba(24, 34, 58, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 0 0 4px 0;
    font-size: 22px;
}

.login-card p.lead {
    margin: 0 0 22px 0;
    color: var(--text-dim);
    font-size: 13px;
}

.field {
    display: flex;
    flex-direction: column;
    margin-bottom: 14px;
}

.field label {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.field input {
    background: #0e1729;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0 16px 0;
    font-size: 12px;
    color: var(--text-dim);
}

.toggle-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(180deg, #5aa9ff, #2a78d8);
    color: white;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(78, 161, 255, 0.35);
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.demo-hint {
    margin-top: 14px;
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
}

.login-footer {
    text-align: center;
    padding: 14px;
    color: var(--text-dim);
    font-size: 11px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* APP SHELL */
.app {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "top top" "side main";
}

.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    z-index: 5;
}

.topbar .brand {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.topbar .brand .name {
    font-size: 16px;
}

.topbar .brand .tag {
    font-size: 10px;
}

.topbar-spacer {
    flex: 1;
}

.top-stat {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    padding: 0 12px;
    border-left: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
}

.top-stat .v {
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

.kp-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 11px;
}

.kp-active {
    background: rgba(255, 181, 71, 0.18);
    color: var(--accent-warm);
}

.user-menu {
    position: relative;
    padding: 0 12px 0 16px;
    border-left: 1px solid var(--border);
    cursor: pointer;
}

.user-menu .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4ea1ff, #7d6cff);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 12px;
    color: var(--bg-deep);
}

.user-menu .who {
    margin-left: 10px;
    font-size: 12px;
    color: var(--text);
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
}

.user-menu .who .role {
    color: var(--text-dim);
    font-size: 10px;
}

.user-menu-dropdown {
    position: absolute;
    right: 0;
    top: 48px;
    width: 240px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    display: none;
    padding: 6px;
    z-index: 50;
}

.user-menu.open .user-menu-dropdown {
    display: block;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: 6px;
    text-decoration: none;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.menu-section-title {
    font-size: 10px;
    color: var(--text-dim);
    padding: 8px 12px 4px 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 0;
}

/* SIDEBAR */
.sidebar {
    grid-area: side;
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar h2 {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 12px 14px 8px 14px;
    margin: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar h2 .pt-icon {
    color: var(--accent);
}

.sidebar .section {
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

#regionList {
    padding: 4px 0;
}

.region-block {
    padding: 4px 0;
    border-bottom: 1px solid rgba(42, 54, 86, 0.4);
}

.region-block:last-child {
    border-bottom: none;
}

.region-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 12px;
}

.region-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.region-header .chev {
    color: var(--text-dim);
    font-size: 10px;
    transition: transform 0.15s;
    width: 10px;
}

.region-block.collapsed .chev {
    transform: rotate(-90deg);
}

.region-block.collapsed .region-children {
    display: none;
}

.region-name {
    flex: 1;
    font-weight: 600;
    font-size: 13px;
}

.region-active-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 8px var(--good);
}

.region-children {
    padding: 0 0 6px 0;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px 7px 30px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
}

.layer-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.layer-row.active {
    background: rgba(78, 161, 255, 0.10);
}

.layer-row .swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.layer-row .layer-name {
    flex: 1;
}

.layer-row .visibility {
    width: 28px;
    text-align: center;
    color: var(--text-dim);
    font-size: 10px;
}

.layer-row.active .visibility {
    color: var(--accent);
}

.basemap-section {
    padding: 8px 12px;
}

.basemap-section .toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text);
}

.basemap-section .toggle input {
    accent-color: var(--accent);
}

/* MAIN */
.main {
    grid-area: main;
    position: relative;
    background: var(--bg-deep);
}

#mapCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#mapCanvas.dragging {
    cursor: grabbing;
}

/* zoom controls */
.zoom-controls {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    gap: 1px;
    box-shadow: var(--shadow);
    border-radius: 6px;
    overflow: hidden;
}

.zoom-controls button {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 16px;
}

.zoom-controls button:hover {
    background: rgba(78, 161, 255, 0.20);
}

/* altitude slider */
.panel-altitude {
    position: absolute;
    left: 14px;
    bottom: 14px;
    background: var(--panel);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
    z-index: 4;
    width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.panel-altitude.hidden {
    display: none;
}

.alt-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.alt-value {
    font-size: 13px;
    font-weight: 600;
}

.alt-slider-vert {
    -webkit-appearance: slider-vertical;
    writing-mode: bt-lr;
    width: 24px;
    height: 220px;
    accent-color: var(--accent);
}

/* time slider */
.panel-time {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 14px;
    margin: 0 100px 0 100px;
    background: var(--panel);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 16px;
    box-shadow: var(--shadow);
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 14px;
}

.panel-time.hidden {
    display: none;
}

.time-btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    width: 34px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.time-btn:hover {
    background: rgba(78, 161, 255, 0.15);
}

.time-stamp {
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    min-width: 165px;
    color: var(--text);
}

.time-stamp .lbl {
    color: var(--text-dim);
    margin-right: 6px;
}

.time-slider {
    flex: 1;
    accent-color: var(--accent);
}

/* colorbar */
.panel-colorbar {
    position: absolute;
    right: 14px;
    top: 14px;
    background: var(--panel);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
    z-index: 4;
    width: 92px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.panel-colorbar .cb-title {
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    margin-bottom: 8px;
    line-height: 1.2;
}

.panel-colorbar .cb-units {
    font-size: 11px;
    color: var(--text);
    margin-bottom: 8px;
}

.cb-strip {
    width: 22px;
    height: 220px;
    border-radius: 4px;
    background: linear-gradient(to top, #313695, #4575b4, #74add1, #abd9e9, #e0f3f8, #fee090, #fdae61, #f46d43, #d73027, #a50026);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.cb-ticks {
    height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-left: 8px;
    font-size: 10px;
    color: var(--text-dim);
}

.cb-row {
    display: flex;
    align-items: stretch;
}

.cb-hint {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 8px;
    text-align: center;
}

/* hover readout */
.hover-readout {
    position: absolute;
    pointer-events: none;
    z-index: 6;
    background: rgba(11, 18, 32, 0.92);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    color: var(--text);
    box-shadow: var(--shadow);
    line-height: 1.4;
    transform: translate(12px, 12px);
    display: none;
    font-variant-numeric: tabular-nums;
}

.hover-readout .row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    min-width: 170px;
}

.hover-readout .row .k {
    color: var(--text-dim);
}

.hover-readout .row .v {
    color: var(--text);
    font-weight: 600;
}

.hover-readout .val-big {
    color: var(--accent);
    font-weight: 700;
}

.ts-panel {
    position: absolute;
    top: 14px;
    right: 120px;
    width: 420px;
    max-height: calc(100% - 28px);
    height: auto;
    background: rgba(24, 34, 58, 0.96);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 7;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.ts-panel.visible {
    display: flex;
}

.ts-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.ts-header .ts-title {
    font-weight: 600;
    flex: 1;
    font-size: 14px;
}

.ts-header .x {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 18px;
}

.ts-meta {
    font-size: 11px;
    color: var(--text-dim);
    padding: 8px 14px 0 14px;
}

.ts-meta .row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.ts-charts {
    padding: 8px 12px 12px 12px;
    flex-shrink: 0;
}

.ts-charts .chart-wrap {
    position: relative;
    height: 160px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    margin-bottom: 8px;
    padding: 4px;
}

.ts-charts .chart-wrap.small {
    height: 110px;
}

.ts-charts .chart-wrap canvas {
    position: absolute !important;
    inset: 4px;
    width: calc(100% - 8px) !important;
    height: calc(100% - 8px) !important;
    display: block;
}

.modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, 0.6);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-bg.visible {
    display: flex;
}

.modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 420px;
    padding: 22px;
    box-shadow: var(--shadow);
}

.modal h2 {
    margin: 0 0 14px 0;
    font-size: 16px;
}

.modal .field input,
.modal .field select {
    background: #0e1729;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    width: 100%;
    outline: none;
}

.modal .row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
}

.btn-secondary {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

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

.license-table td {
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
}

.license-table td:first-child {
    color: var(--text-dim);
    width: 40%;
}

.tag-pill {
    background: rgba(78, 161, 255, 0.18);
    color: var(--accent);
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.attribution {
    position: absolute;
    right: 14px;
    bottom: 50px;
    font-size: 9px;
    color: rgba(160, 180, 220, 0.55);
    z-index: 3;
}