:root {
    --esri-blue: #0079c1;
    --esri-blue-dark: #005e95;
    --surface: #fff;
    --surface-soft: #f8f8f8;
    --border: #d6d6d6;
    --text: #2b2b2b;
    --muted: #6e6e6e;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    --topbar: 56px;
    --rail: 48px;
}

html,
body,
#app {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: "Avenir Next", Avenir, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

#viewDiv {
    position: absolute;
    inset: var(--topbar) 0 28px var(--rail);
}

.topbar {
    position: absolute;
    inset: 0 0 auto 0;
    height: var(--topbar);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 100%;
    padding: 0 18px;
    border-right: 1px solid var(--border);
}

.brand-mark {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--esri-blue);
    border-radius: 2px;
}

.brand-title {
    display: block;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.1;
}

.brand-subtitle {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    color: var(--muted);
}

.topbar-center {
    display: flex;
    align-items: center;
    min-width: 0;
}

.search-shell {
    width: min(560px, 100%);
    min-width: 280px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 12px;
}

.command-btn {
    min-width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    border-radius: 2px;
    cursor: pointer;
}

.command-btn:hover {
    background: #f0f0f0;
    border-color: #cfcfcf;
}

.command-btn.primary {
    background: var(--esri-blue);
    color: #fff;
}

.command-btn.primary:hover {
    background: var(--esri-blue-dark);
    border-color: var(--esri-blue-dark);
}

.tool-rail {
    position: absolute;
    inset: var(--topbar) auto 28px 0;
    width: var(--rail);
    z-index: 18;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.02);
}

.rail-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 6px 0;
    border-bottom: 1px solid #ececec;
}

.rail-btn {
    width: 48px;
    height: 42px;
    border: 0;
    background: transparent;
    color: #3f3f3f;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.rail-btn:hover {
    background: #f2f7fb;
    color: var(--esri-blue);
}

.rail-btn.active {
    color: var(--esri-blue);
    background: #eaf4fb;
    border-left-color: var(--esri-blue);
}

.side-panel {
    position: absolute;
    top: calc(var(--topbar) + 12px);
    left: calc(var(--rail) + 12px);
    width: 360px;
    max-width: calc(100vw - var(--rail) - 28px);
    max-height: calc(100vh - var(--topbar) - 56px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 19;
}

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

.active-layer-card {
    position: absolute;
    left: calc(var(--rail) + 18px);
    bottom: 48px;
    width: 340px;
    max-width: calc(100vw - var(--rail) - 36px);
    padding: 16px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 19;
}

.active-layer-card.hidden {
    display: none;
}

.active-layer-eyebrow {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 8px;
    color: var(--esri-blue);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.active-layer-card h2 {
    margin: 0;
    color: var(--text);
    font-size: 17px;
    line-height: 1.3;
    font-weight: 700;
}

.active-layer-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.active-layer-card p {
    max-height: 66px;
    margin: 10px 0 14px;
    overflow: auto;
    color: #3f3f3f;
    font-size: 13px;
    line-height: 1.55;
}

.active-layer-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.panel-header {
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--border);
}

.panel-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.panel-close {
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.panel-close:hover {
    color: var(--text);
    background: #f3f3f3;
}

.panel-body {
    min-height: 120px;
    overflow: auto;
    padding: 14px;
}

.field {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
}

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

.field select,
.field input {
    min-height: 34px;
    border: 1px solid #bcbcbc;
    border-radius: 2px;
    padding: 6px 8px;
    background: #fff;
}

.add-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.add-row .field {
    margin-bottom: 0;
    min-width: 0;
}

.add-row .field select {
    width: 100%;
}

.kml-summary {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: #f5f7fa;
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--text);
    font-size: 13px;
}

.kml-summary strong {
    color: var(--esri-blue);
    font-size: 18px;
}

.kml-summary span {
    color: var(--muted);
    font-size: 12px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 14px;
    color: var(--text);
    font-size: 12px;
}

.filter-row label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.filter-row input {
    margin: 0;
}

.kml-legend-empty {
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 12px;
}

.kml-legend-group {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}

.kml-legend-group:last-child {
    margin-bottom: 0;
}

.kml-legend-group h3 {
    margin: 0;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.kml-legend-layer {
    display: grid;
    gap: 7px;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
}

.kml-legend-layer-title {
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
}

.kml-legend-item {
    display: grid;
    grid-template-columns: 22px 1fr auto;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 12px;
}

.kml-legend-item small {
    color: var(--muted);
    font-size: 11px;
}

.kml-legend-symbol {
    width: 18px;
    height: 18px;
    display: inline-block;
    justify-self: center;
}

.kml-legend-symbol.point {
    border: 3px solid #fff;
    border-radius: 50%;
    background: rgb(220, 38, 38);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22);
}

.kml-legend-symbol.polyline {
    height: 0;
    border-top: 3px solid rgba(22, 101, 216, 0.9);
}

.kml-legend-symbol.polygon {
    border: 2px solid rgba(4, 120, 87, 0.95);
    background: rgba(16, 185, 129, 0.28);
}

.panel-note {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.measure-modes,
.map-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.measure-modes {
    position: relative;
    z-index: 1;
}

.action-card {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--text);
    border-radius: 2px;
    cursor: pointer;
}

.action-card:hover,
.action-card.active {
    border-color: var(--esri-blue);
    color: var(--esri-blue);
    background: #eef7fc;
}

.bottom-status {
    position: absolute;
    inset: auto 0 0 var(--rail);
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 12px;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--border);
    z-index: 17;
    color: #444;
    font-size: 12px;
}

.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.status-chip {
    white-space: nowrap;
}

.loader {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.92);
    z-index: 1000;
}

.loader.hidden {
    display: none;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #e6e6e6;
    border-top-color: var(--esri-blue);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.toast {
    position: absolute;
    right: 16px;
    bottom: 44px;
    max-width: 320px;
    padding: 11px 14px;
    background: #2b2b2b;
    color: #fff;
    font-size: 13px;
    box-shadow: var(--shadow);
    z-index: 30;
    transform: translateY(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.esri-ui-corner .esri-component {
    box-shadow: var(--shadow);
}

.esri-widget,
.esri-widget--button,
.esri-menu,
.esri-popup__main-container {
    font-family: "Avenir Next", Avenir, "Helvetica Neue", Arial, sans-serif;
}

#basemapGallery,
#layerList,
#legend,
#sketchWidget,
#measurementWidget {
    min-height: 120px;
}

#layerList.hidden {
    display: none;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 760px) {
    :root {
        --topbar: 92px;
    }

    .topbar {
        grid-template-columns: 1fr auto;
        grid-template-rows: 46px 46px;
        gap: 0;
    }

    .brand {
        padding-left: 12px;
    }

    .topbar-center {
        grid-column: 1 / -1;
        grid-row: 2;
        padding: 0 10px 8px;
    }

    .topbar-actions {
        grid-column: 2;
        grid-row: 1;
    }

    .command-label,
    .brand-subtitle,
    .status-right {
        display: none;
    }

    .search-shell {
        width: 100%;
        min-width: 0;
    }

    .side-panel {
        left: calc(var(--rail) + 8px);
        right: 8px;
        width: auto;
    }

    .active-layer-card {
        left: calc(var(--rail) + 8px);
        right: 8px;
        width: auto;
    }
}
