:root {
    --ink: #132029;
    --muted: #5a6a75;
    --line: #d5dee5;
    --panel: #f5f8fa;
    --panel-strong: #ffffff;
    --accent: #0f766e;
    --accent-soft: #ccfbf1;
    --accent-deep: #0f5f59;
    --danger: #b42318;
    --danger-soft: #fee4e2;
    --shadow: 0 12px 28px rgba(19, 32, 41, 0.1);
    --map-wash: #e7eef3;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: "Source Sans 3", system-ui, sans-serif;
    color: var(--ink);
    background: var(--panel);
}

.app {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(360px, 420px) 1fr;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
    background: var(--panel-strong);
    border-right: 1px solid var(--line);
    z-index: 500;
}

.map-pane {
    position: relative;
    min-width: 0;
    background: var(--map-wash);
    z-index: 1;
    isolation: isolate;
    overflow: hidden;
}

#map {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(160deg, #14b8a6, var(--accent-deep));
    color: #fff;
    box-shadow: 0 8px 18px rgba(15, 118, 110, 0.28);
}

.sidebar-brand strong {
    display: block;
    font-family: "Libre Franklin", sans-serif;
    font-size: 17px;
    letter-spacing: -0.02em;
}

.sidebar-brand small {
    color: var(--muted);
    font-size: 12px;
}

.sidebar-tools {
    padding: 0 20px 14px;
    border-bottom: 1px solid var(--line);
}

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--muted);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.search:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.search input {
    width: 100%;
    border: 0;
    outline: none;
    background: transparent;
    font: inherit;
    color: var(--ink);
}

.tool-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.map-distance {
    position: absolute;
    top: 16px;
    right: 56px;
    z-index: 450;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    max-width: min(320px, calc(100% - 72px));
    pointer-events: none;
}

.map-distance > * {
    pointer-events: auto;
}

.map-distance__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 14px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.map-distance__toggle:hover,
.map-distance__toggle[aria-expanded="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.map-distance__panel {
    width: min(300px, calc(100vw - 88px));
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
}

.map-distance__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.map-distance__close {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    flex: 0 0 auto;
}

.map-distance__close:hover {
    color: var(--ink);
}

.distance-box__label {
    margin: 0 0 8px;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

.distance-field {
    display: grid;
    gap: 4px;
    margin-bottom: 8px;
    font-size: .85rem;
    color: var(--muted);
}

.distance-field select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

.distance-result {
    margin: 10px 0 0;
    display: grid;
    gap: 2px;
    font-size: .92rem;
}

.distance-result strong {
    font-size: 1.25rem;
    color: var(--accent-deep, #0f6b4c);
}

.distance-tooltip {
    background: #0f6b4c;
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 4px 10px;
    font-weight: 700;
    box-shadow: none;
}

.distance-tooltip::before {
    border-top-color: #0f6b4c;
}

.btn, .icon-btn {
    border: 0;
    cursor: pointer;
    font: inherit;
}

.btn {
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 600;
    transition: transform .12s ease, background .12s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover { background: var(--accent-deep); }

.btn-ghost {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--ink);
}

.btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.metric-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.metric {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 8px;
    text-align: center;
}

.metric strong {
    display: block;
    font-family: "Libre Franklin", sans-serif;
    font-size: 18px;
    color: var(--accent-deep);
}

.metric span {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 16px 20px 20px;
}

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

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1, h2, h3, p { margin: 0; }

#sidebar-title {
    font-family: "Libre Franklin", sans-serif;
    font-size: 21px;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

.lede {
    margin: 8px 0 16px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--ink);
}

.center-list, .person-list {
    display: grid;
    gap: 8px;
}

.center-card, .person-card, .info-block {
    width: 100%;
    text-align: left;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    color: inherit;
}

.center-card__icon,
.center-card__icon .hospital-glyph,
.center-card__code,
.asm-pin,
.asm-pin * {
    pointer-events: none;
}

.center-card {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, transform .15s ease, box-shadow .15s ease;
}

.center-card__icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-deep);
}

.center-card__icon .hospital-glyph {
    width: 18px;
    height: 18px;
}

.center-card__body {
    min-width: 0;
}

.center-card__code {
    min-width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid var(--line);
    font-family: "Libre Franklin", sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-deep);
}

.center-card:hover,
.center-card.active {
    border-color: var(--accent);
    background: #f0fdfa;
    box-shadow: 0 6px 16px rgba(15, 118, 110, 0.08);
}

.center-card.active {
    border-color: var(--danger);
    background: #fff7f6;
}

.center-card.active .center-card__icon {
    background: var(--danger-soft);
    color: var(--danger);
}

.center-card.active .center-card__code {
    border-color: #fecdca;
    color: var(--danger);
}

.center-card:hover { transform: translateY(-1px); }

.center-card b {
    display: block;
    margin-bottom: 3px;
    font-size: 14px;
    line-height: 1.3;
}

.center-card span,
.muted {
    color: var(--muted);
    font-size: 13px;
}

.selected-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 9px 12px;
    border-radius: 12px;
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 12px;
    font-weight: 700;
}

.selected-banner__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.18);
    animation: pulse-dot 1.6s ease-out infinite;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-deep);
    font-size: 12px;
    font-weight: 600;
}

.badge-muted {
    background: #eef2f5;
    color: var(--muted);
}

.info-block {
    padding: 12px 14px;
    margin-bottom: 10px;
}

.info-row {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 10px;
    align-items: flex-start;
    margin: 10px 0;
    font-size: 14px;
    color: var(--muted);
}

.info-ico {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--accent-deep);
}

.info-ico svg {
    width: 14px;
    height: 14px;
}

.info-copy {
    padding-top: 4px;
    line-height: 1.45;
}

.info-row a {
    color: var(--accent-deep);
    text-decoration: none;
    font-weight: 600;
}

.action-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 4px;
}

.action-links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.action-links a.action-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 12px 0 4px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
}

.stat strong {
    display: block;
    font-family: "Libre Franklin", sans-serif;
    font-size: 20px;
    color: var(--accent-deep);
}

.stat span {
    font-size: 11px;
    color: var(--muted);
}

.section-title {
    margin: 18px 0 8px;
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}

.person-card {
    padding: 12px;
}

.person-card b { display: block; margin-bottom: 2px; }

.empty, .loading, .error {
    padding: 14px;
    border-radius: 12px;
    background: var(--panel);
    border: 1px dashed var(--line);
    color: var(--muted);
    font-size: 14px;
}

.error {
    border-color: #fecdca;
    background: #fef3f2;
    color: var(--danger);
}

.sidebar-foot {
    padding: 12px 20px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 11px;
    line-height: 1.45;
}

.map-legend {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    min-width: 160px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-pin {
    width: 24px;
    height: 28px;
    position: relative;
    flex: 0 0 auto;
    color: #fff;
}

.legend-pin::before {
    content: "";
    position: absolute;
    inset: 0 2px 6px;
    border-radius: 8px 8px 4px 4px;
    background: var(--accent);
    box-shadow: 0 4px 10px rgba(15, 118, 110, 0.28);
}

.legend-pin svg {
    position: absolute;
    left: 50%;
    top: 5px;
    transform: translateX(-50%);
    z-index: 1;
}

.legend-pin.is-selected::before {
    background: var(--danger);
    box-shadow: 0 4px 10px rgba(180, 35, 24, 0.3);
}

/* Markers */
.asm-marker {
    background: transparent !important;
    border: 0 !important;
}

.asm-pin {
    position: relative;
    width: 40px;
    height: 50px;
    display: grid;
    place-items: start center;
}

.asm-pin__shadow {
    position: absolute;
    left: 50%;
    bottom: 2px;
    width: 18px;
    height: 6px;
    transform: translateX(-50%);
    background: rgba(19, 32, 41, 0.22);
    border-radius: 50%;
    filter: blur(1px);
}

.asm-pin__body {
    position: relative;
    z-index: 2;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: linear-gradient(165deg, #14b8a6 0%, #0f766e 70%);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 10px 18px rgba(15, 118, 110, 0.35);
    display: grid;
    place-items: center;
    gap: 0;
}

.asm-pin__body .hospital-glyph {
    width: 15px;
    height: 15px;
    margin-top: 1px;
}

.asm-pin__code {
    font-family: "Libre Franklin", sans-serif;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    opacity: 0.95;
    margin-top: -1px;
}

.asm-pin__pointer {
    position: absolute;
    left: 50%;
    top: 30px;
    width: 12px;
    height: 12px;
    transform: translateX(-50%) rotate(45deg);
    background: #0f766e;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    z-index: 1;
}

.asm-pin.active {
    width: 52px;
    height: 64px;
}

.asm-pin.active .asm-pin__body {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: linear-gradient(165deg, #f04438 0%, #b42318 75%);
    box-shadow: 0 14px 24px rgba(180, 35, 24, 0.4);
}

.asm-pin.active .asm-pin__pointer {
    top: 38px;
    background: #b42318;
}

.asm-pin.active .asm-pin__body .hospital-glyph {
    width: 18px;
    height: 18px;
}

.asm-pin.active .asm-pin__code {
    font-size: 10px;
}

.asm-pin__pulse {
    position: absolute;
    left: 50%;
    top: 23px;
    width: 46px;
    height: 46px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid rgba(180, 35, 24, 0.55);
    animation: pulse-ring 1.5s ease-out infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes pulse-ring {
    0% { transform: translate(-50%, -50%) scale(0.7); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(1.55); opacity: 0; }
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.18); }
    50% { box-shadow: 0 0 0 6px rgba(180, 35, 24, 0.08); }
}

.map-popup {
    display: grid;
    gap: 2px;
    min-width: 140px;
}

.map-popup__tag {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
}

.map-popup strong {
    font-family: "Libre Franklin", sans-serif;
    font-size: 13px;
    color: var(--ink);
}

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

.leaflet-popup-content-wrapper {
    border-radius: 14px;
    font-family: "Source Sans 3", sans-serif;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

.leaflet-popup-content {
    margin: 10px 12px;
    font-size: 13px;
}

.leaflet-popup-tip {
    box-shadow: none;
}

.asm-cluster-wrap {
    background: transparent !important;
    border: 0 !important;
}

.asm-cluster {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(160deg, #14b8a6, #0f5f59);
    color: #fff;
    border: 3px solid #fff;
    box-shadow: 0 10px 20px rgba(15, 118, 110, 0.32);
    display: grid;
    place-content: center;
    text-align: center;
    line-height: 1.05;
    font-family: "Libre Franklin", sans-serif;
}

.asm-cluster span {
    font-size: 15px;
    font-weight: 700;
}

.asm-cluster small {
    font-size: 8px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.9;
}

.asm-cluster--md span { font-size: 16px; }
.asm-cluster--lg span { font-size: 17px; }

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background: transparent;
}

.selection-ring {
    pointer-events: none;
}

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 42vh minmax(0, 58vh);
    }

    .map-pane { order: 1; }
    .sidebar { order: 2; border-right: 0; border-top: 1px solid var(--line); }

    .sidebar-brand { padding: 12px 16px 8px; }
    .sidebar-tools { padding: 0 16px 10px; }
    .sidebar-body { padding: 12px 16px 16px; }
    .panel-head { position: sticky; top: 0; background: var(--panel-strong); z-index: 2; padding-bottom: 4px; }

    body.detail-open .app {
        grid-template-rows: 32vh minmax(0, 68vh);
    }

    body.detail-open .map-legend { display: none; }

    .map-distance {
        top: 10px;
        right: 52px;
        max-width: calc(100% - 64px);
    }

    .map-distance__panel {
        width: min(280px, calc(100vw - 72px));
    }
}
