:root {
    --navy: #0b398a;
    --royal: #1fb1ff;
    --gold: #d6b11e;

    --bg: #ffffff;
    --ink: #0b1220;
    --muted: #5a6475;

    /* Core surfaces */
    --surface: #ffffff;
    --surface-2: #f4f7ff;
    --surface-3: #eef4ff;

    /* Typography */
    --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;

    /* Radii: less heavy */
    --r-xl: 16px;
    --r-lg: 14px;
    --r-md: 12px;
    --r-sm: 10px;

    /* Shadows: flat colours, structure via elevation not outlines */
    --sh-xs: 0 1px 0 rgba(11, 18, 32, 0.05), 0 10px 18px rgba(11, 18, 32, 0.08);
    --sh-sm: 0 1px 0 rgba(11, 18, 32, 0.06), 0 16px 30px rgba(11, 18, 32, 0.10);
    --sh-md: 0 2px 0 rgba(11, 18, 32, 0.07), 0 26px 54px rgba(11, 18, 32, 0.14);

    /* Layout */
    --gutter: 18px;
    --nav-w: 360px;

    /* Focus */
    --focus: rgba(31, 177, 255, 0.45);

    /* Accents */
    --tint: rgba(11, 57, 138, 0.06);
    --tint-2: rgba(31, 177, 255, 0.10);

    /* Gold: very sparing hairline */
    --gold-hair: rgba(214, 177, 30, 0.22);
}

* {
    box-sizing: border-box;
}

html, body, #app, .app-root {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
}

a, button, select, input, textarea {
    font: inherit;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    border: 0;
    padding: 0;
    background: transparent;
}

select {
    border: 0;
    background: rgba(255, 255, 255, 0.92);
    border-radius: var(--r-md);
    padding: 10px 12px;
    color: var(--ink);
    box-shadow: var(--sh-xs);
}

select:focus {
    outline: none;
    box-shadow: 0 0 0 4px var(--focus), var(--sh-xs);
}

button:focus, a:focus, input:focus, textarea:focus {
    outline: none;
}

.app-root {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ---------------------------------------------------------------------
   Compatibility mapping for the old structure (topbar/content/sidebar/main)
   This keeps other pages/components stable without needing markup changes.
--------------------------------------------------------------------- */
.topbar {
    display: none;
}

.content {
    display: flex;
    gap: var(--gutter);
    padding: var(--gutter);
    min-height: 0;
    flex: 1;
}

.sidebar {
    width: var(--nav-w);
    min-width: 300px;
    max-width: 420px;
    display: flex;
    min-height: 0;
}

.main {
    flex: 1;
    min-width: 0;
    min-height: 0;
}

/* ---------------------------------------------------------------------
   New shell layout
--------------------------------------------------------------------- */
.app-shell {
    height: 100%;
}

.shell {
    height: 100%;
    min-height: 0;
    display: flex;
    gap: var(--gutter);
    padding: var(--gutter);
    background: radial-gradient(1200px 700px at 18% 0%, #f0f6ff 0%, #ffffff 56%);
}

.nav {
    width: var(--nav-w);
    min-width: 300px;
    max-width: 420px;
    min-height: 0;
    display: flex;
}

.nav-inner {
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: var(--r-xl);
    overflow: hidden;
    background: linear-gradient(180deg, var(--surface-3) 0%, var(--surface-2) 56%, var(--surface) 100%);
    box-shadow: var(--sh-sm);
}

.nav-header {
    padding: 16px 16px 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stage {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
}

.stage-inner {
    width: 100%;
    min-height: 0;
    border-radius: var(--r-xl);
    background: var(--surface);
    box-shadow: var(--sh-sm);
    padding: 18px;
    overflow: auto;
}

/* ---------------------------------------------------------------------
   Brand
--------------------------------------------------------------------- */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    background: var(--navy);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.brand-mark::before {
    content: "";
    position: absolute;
    inset: -55% -65%;
    background: linear-gradient(
            135deg,
            rgba(31, 177, 255, 0.0) 0%,
            rgba(31, 177, 255, 0.35) 42%,
            rgba(31, 177, 255, 0.0) 74%
    );
    transform: rotate(18deg);
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-weight: 950;
    letter-spacing: 0.2px;
}

.brand-subtitle {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    font-weight: 750;
}

.nav-status-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* ---------------------------------------------------------------------
   Connection pill / status styling
--------------------------------------------------------------------- */
.pill {
    padding: 8px 12px;
    border-radius: 999px;
    font-weight: 950;
    letter-spacing: 0.1px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--navy);
    box-shadow: var(--sh-xs);
}

.pill-on {
    background: #e7f0ff;
    color: var(--royal);
}

.pill-off {
    background: rgba(255, 255, 255, 0.92);
    color: var(--muted);
}

.pill-warn {
    background: #fff2cc;
    color: #5b4700;
}

/* ---------------------------------------------------------------------
   Controls + identity
--------------------------------------------------------------------- */
.nav-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-label {
    font-size: 12px;
    font-weight: 950;
    color: rgba(11, 18, 32, 0.55);
    letter-spacing: 0.2px;
}

.tenant-switch {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tenant-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 850;
}

.tenant-select {
    max-width: none;
}

/* Identity card (also maps older profile styles) */
.identity,
.profile-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--r-xl);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--sh-xs);
}

.identity:focus,
.profile-btn:focus {
    box-shadow: 0 0 0 4px var(--focus), var(--sh-xs);
}

.avatar {
    width: 34px;
    height: 34px;
    background: var(--royal);
    border-radius: 12px;
}

.identity-text,
.profile-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.identity-name,
.profile-name {
    font-weight: 975;
    font-size: 13px;
    line-height: 1.1;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.identity-meta,
.profile-meta {
    font-size: 12px;
    color: var(--muted);
    font-weight: 850;
    line-height: 1.1;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Legacy containers still present in other pages */
.profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ---------------------------------------------------------------------
   Devices section (assumes SidebarDevices renders a list of .device-item)
--------------------------------------------------------------------- */
.nav-section {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 12px 12px 12px;
}

.nav-section-head {
    padding: 10px 4px 0 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section-title {
    font-weight: 975;
    letter-spacing: 0.2px;
    color: var(--navy);
}

.nav-section-sub {
    font-size: 12px;
    color: var(--muted);
    font-weight: 750;
}

.nav-section-body {
    min-height: 0;
    padding: 6px 4px 0 4px;
    overflow: auto;
}

/* Device list items */
.device-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--r-md);
    padding: 12px 12px;
    background: rgba(255, 255, 255, 0.92);
    margin-bottom: 10px;
    box-shadow: var(--sh-xs);
    transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.device-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--sh-sm);
    background: rgba(255, 255, 255, 0.98);
}

.device-name {
    font-weight: 975;
}

.device-site {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
    font-weight: 750;
}

.device-status {
    font-size: 12px;
    font-weight: 975;
}

/* Status chips/tints */
.st-on {
    background: #e7f0ff;
}

.st-busy {
    background: #fff2cc;
}

.st-off {
    background: #f2f4f8;
}

.st-err {
    background: #ffe2e2;
}

.st-anim {
    animation: statusPop 800ms ease;
}

@keyframes statusPop {
    0% {
        transform: scale(1.00);
    }
    40% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1.00);
    }
}

/* ---------------------------------------------------------------------
   Panels: assume most content is composed from .panel blocks
   No outlines; hierarchy by header tint + elevation
--------------------------------------------------------------------- */
.panel {
    background: var(--surface);
    border: 0;
    border-radius: var(--r-xl);
    box-shadow: var(--sh-sm);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-sidebar {
    height: 100%;
}

.panel-header {
    padding: 16px 16px 12px 16px;
    border-bottom: 0;
}

.panel-title {
    font-weight: 975;
    letter-spacing: 0.2px;
    color: var(--navy);
}

.panel-subtitle {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
    font-weight: 750;
}

.panel-body {
    padding: 14px 14px 16px 14px;
    min-height: 0;
}

.scroll {
    overflow: auto;
}

/* Grid layout (dashboard) */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    min-height: 0;
}

@media (min-width: 1100px) {
    .grid {
        grid-template-columns: 1.2fr 0.8fr;
    }

    .grid > .panel:nth-child(3) {
        grid-column: 1 / -1;
    }
}

/* ---------------------------------------------------------------------
   Results + lines: assumes stacked cards with internal pills and chips
--------------------------------------------------------------------- */
.results {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result,
.line {
    display: block;
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.94);
    border-radius: var(--r-xl);
    padding: 14px;
    box-shadow: var(--sh-xs);
    transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.result:hover,
.line:hover {
    transform: translateY(-1px);
    box-shadow: var(--sh-sm);
    background: rgba(255, 255, 255, 0.98);
}

.result-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.result-title {
    font-weight: 975;
}

.result-meta {
    font-size: 12px;
    color: var(--muted);
    font-weight: 900;
}

.result-standard {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.std-pill {
    background: var(--navy);
    color: #fff;
    font-weight: 975;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
}

.std-name {
    font-weight: 975;
    color: var(--navy);
}

.result-measures {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Measures: small cards, no outlines */
.measure {
    background: rgba(255, 255, 255, 0.94);
    border: 0;
    border-radius: var(--r-md);
    padding: 10px 12px;
    min-width: 140px;
    box-shadow: var(--sh-xs);
}

.measure-k {
    font-size: 12px;
    color: var(--muted);
    font-weight: 900;
}

.measure-v {
    font-weight: 975;
    margin-top: 2px;
}

/* Key/value rows */
.kv {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kv-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    background: rgba(255, 255, 255, 0.94);
    border-radius: var(--r-md);
    padding: 12px;
    box-shadow: var(--sh-xs);
}

.k {
    color: var(--muted);
    font-weight: 975;
    font-size: 12px;
    min-width: 120px;
}

.v {
    font-weight: 975;
    min-width: 0;
    overflow-wrap: anywhere;
}

.empty {
    color: var(--muted);
    font-weight: 900;
}

/* Lines */
.lines {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.line {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.line-title {
    font-weight: 975;
}

.line-sub {
    color: var(--muted);
    font-weight: 900;
    font-size: 12px;
    margin-top: 4px;
}

/* Thumbs (image strip) */
.thumbs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.thumb {
    border-radius: var(--r-sm);
    border: 0;
    box-shadow: var(--sh-xs);
    width: 56px;
    height: 56px;
    object-fit: cover;
}

/* ---------------------------------------------------------------------
   Charts / maps / skeletons
--------------------------------------------------------------------- */
.chart-wrap,
.map-wrap {
    padding: 0;
}

.chart {
    height: 340px;
    min-height: 260px;
    width: 100%;
    padding: 12px 12px 14px 12px;
}

.chart-inner {
    width: 100%;
    height: 100%;
}

.map {
    height: 360px;
    min-height: 280px;
    width: 100%;
    padding: 12px;
}

.leaflet-map {
    height: 100%;
    width: 100%;
    border-radius: var(--r-xl);
    border: 0;
    box-shadow: var(--sh-xs);
}

.skeleton {
    background: rgba(255, 255, 255, 0.94);
    border: 0;
    border-radius: var(--r-xl);
    padding: 16px;
    color: var(--muted);
    font-weight: 900;
    box-shadow: var(--sh-xs);
}

.chart-skel {
    height: 320px;
}

.map-skel {
    height: 320px;
}

.not-found {
    padding: 24px;
    font-weight: 975;
}

/* ---------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------- */
@media (max-width: 980px) {
    :root {
        --nav-w: 100%;
        --gutter: 14px;
    }

    .shell {
        flex-direction: column;
        padding: var(--gutter);
        gap: var(--gutter);
    }

    .nav {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    .stage-inner {
        padding: 14px;
    }

    .nav-section-body {
        max-height: 340px;
    }
}

.leaflet-control-attribution {
    display: none !important;
}