:root {
    font-family: Arial, Helvetica, sans-serif;
    color: #f4f6f8;
    background: #0b0e12;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

.eyebrow {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.18em;
    opacity: 0.55;
}

.topbar {
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: #11151b;
}

.topbar h1 {
    margin: 3px 0 0;
    font-size: 22px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.topbar-actions a {
    color: #f4f6f8;
}

.status-live {
    color: #5ee58a;
}

.status-error {
    color: #ff6969;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 370px;
    min-height: calc(100vh - 74px);
}

#map-shell {
    position: relative;
    overflow: hidden;
    touch-action: none;
    cursor: default;
    background:
        radial-gradient(circle at center, #1c222b, #0c0f13 70%);
}

#map-shell.zoomed {
    cursor: grab;
}

#map-shell.dragging {
    cursor: grabbing;
}

#map-scroll {
    position: absolute;
    inset: 0;
    overflow: auto;
    scrollbar-width: thin;
    overscroll-behavior: contain;
}

#map-scroll.dragging {
    cursor: grabbing;
}

#map-canvas {
    position: relative;
    overflow: visible;
    margin: auto;
    flex: 0 0 auto;
}

#map-tiles {
    display: grid;
    width: 100%;
    height: 100%;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
    pointer-events: none;
    user-select: none;
}

#map-tiles img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    user-select: none;
}

#markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#map-controls {
    position: absolute;
    z-index: 50;
    top: 14px;
    left: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 8px;
    background: rgba(12, 16, 20, 0.88);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

#map-controls button {
    min-width: 34px;
    height: 32px;
    padding: 0 9px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.07);
    color: white;
    cursor: pointer;
    font-weight: 800;
}

#map-controls button:hover {
    background: rgba(255, 255, 255, 0.14);
}

#zoom-level {
    min-width: 46px;
    padding: 0 4px;
    text-align: center;
    font-size: 11px;
    opacity: 0.72;
}

#map-missing {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 30px;
    text-align: center;
    color: rgba(255, 255, 255, 0.65);
}

.map-marker {
    position: absolute;

    /*
     * The map coordinate now represents the center of the triangle,
     * not the center of the triangle + label row.
     *
     * The triangle is 12 px wide and 14 px high.
     */
    transform: translate(-14px, -16px);
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 190px;
    border: 0;
    background: transparent;
    color: white;
    pointer-events: auto;
    cursor: default;
}



.marker-label {
    overflow: hidden;
    padding: 4px 7px;
    border-radius: 5px;
    background: rgba(10, 13, 17, 0.86);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 11px;
    font-weight: 800;
}





.map-marker.emergency {
    animation: emergency-pulse 0.75s infinite;
}

.sidebar {
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    background: #11151b;
}

.sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 13px;
}

#unit-list {
    height: calc(100vh - 125px);
    overflow-y: auto;
    padding: 10px;
}

.unit-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px;
    border-left: 3px solid #69a7ff;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.045);
}

.unit-card + .unit-card {
    margin-top: 7px;
}

.unit-card.job-ambulance {
    border-left-color: #ff6a6a;
}

.unit-card.job-fire {
    border-left-color: #ffb54d;
}

.unit-card.emergency {
    animation: emergency-pulse 0.75s infinite;
}

.unit-main {
    min-width: 0;
}

.unit-main strong,
.unit-main span {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.unit-main strong {
    font-size: 13px;
}

.unit-main span {
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.55;
}

.job-pill {
    padding: 4px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 9px;
    text-transform: uppercase;
}

.empty {
    padding: 30px 10px;
    text-align: center;
    opacity: 0.5;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(390px, 100%);
    padding: 26px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: #11151b;
    box-shadow: 0 20px 65px rgba(0, 0, 0, 0.5);
}

.login-card h1 {
    margin: 5px 0 22px;
}

.login-card label {
    display: block;
    margin-top: 14px;
    font-size: 12px;
}

.login-card input {
    width: 100%;
    margin-top: 6px;
    padding: 11px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    outline: none;
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.login-card button {
    width: 100%;
    margin-top: 20px;
    padding: 11px;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 800;
}

.error {
    margin-bottom: 12px;
    color: #ff6969;
    font-size: 12px;
}

@keyframes emergency-pulse {
    0%, 100% {
        filter: none;
    }

    50% {
        filter: drop-shadow(0 0 11px rgba(255, 35, 35, 0.95));
    }
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }
}


/* Keep marker labels readable without becoming enormous at high zoom. */
.map-marker {
    transform-origin: center center;
}

#map-shell[data-zoom-level="high"] .marker-label {
    font-size: 9px;
}


#map-scroll.calibrating {
    cursor: crosshair;
}

#map-scroll.calibrating .map-marker {
    pointer-events: none;
}

.calibration-toast {
    position: fixed;
    z-index: 1000;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    max-width: 680px;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 7px;
    background: rgba(12, 16, 20, 0.96);
    color: white;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
    font-size: 12px;
}


/*
 * Marker anchor correction:
 * left/top is the actual unit coordinate and the triangle is centered there.
 * The label extends to the right without influencing the coordinate anchor.
 */
.map-marker .marker-arrow {
    flex: 0 0 auto;
}

.map-marker .marker-label {
    position: relative;
    margin-left: 6px;
}


.marker-direction {
    position: relative;
    width: 28px;
    height: 32px;
    flex: 0 0 28px;
    transform-origin: 50% 50%;
    filter:
        drop-shadow(0 2px 1px rgba(0, 0, 0, 0.95))
        drop-shadow(0 0 5px rgba(0, 0, 0, 0.85));
}

.marker-direction::before {
    content: '';
    position: absolute;
    inset: 0;
    background: #ffffff;
    clip-path: polygon(
        50% 0%,
        100% 78%,
        64% 68%,
        50% 100%,
        36% 68%,
        0% 78%
    );
}

.marker-direction-core {
    position: absolute;
    inset: 4px;
    background: #45a2ff;
    clip-path: polygon(
        50% 0%,
        100% 78%,
        64% 68%,
        50% 100%,
        36% 68%,
        0% 78%
    );
}

.map-marker.job-ambulance .marker-direction-core {
    background: #ff5151;
}

.map-marker.job-fire .marker-direction-core {
    background: #ff9d1f;
}

.map-marker.emergency .marker-direction-core {
    background: #ff2020;
}

.map-marker .marker-label {
    margin-left: 7px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow:
        0 3px 12px rgba(0, 0, 0, 0.65),
        0 0 0 1px rgba(0, 0, 0, 0.45);
}


.call-marker {
    position: absolute;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    transform: translate(-15px, -15px);
    pointer-events: auto;
}

.call-marker-icon {
    display: grid;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    place-items: center;
    border: 3px solid #fff;
    border-radius: 50%;
    background: #777;
    color: white;
    box-shadow:
        0 2px 2px rgba(0, 0, 0, 0.9),
        0 0 8px rgba(0, 0, 0, 0.75);
    font-weight: 900;
}

.call-marker.priority-P1 .call-marker-icon {
    background: #d80000;
    animation: emergency-pulse 0.75s infinite;
}

.call-marker.priority-P2 .call-marker-icon {
    background: #d7ad00;
}

.call-marker.priority-P3 .call-marker-icon {
    background: #777;
}

.call-marker-label {
    padding: 5px 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 5px;
    background: rgba(10, 13, 17, 0.92);
    color: white;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 900;
}


/* ============================================================
   Leaflet tile map
   ============================================================ */

#map-shell {
    position: relative;
    overflow: hidden;
}

#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(
            circle at center,
            #1c222b,
            #0c0f13 70%
        );
}

#map.calibrating,
#map.calibrating .leaflet-grab {
    cursor: crosshair;
}

.leaflet-container {
    font-family: Arial, Helvetica, sans-serif;
    background: #0c0f13;
}

.leaflet-tile {
    image-rendering: auto;
}

.leaflet-control-container {
    display: none;
}

.unit-leaflet-icon,
.call-leaflet-icon {
    width: 0 !important;
    height: 0 !important;
    border: 0;
    background: transparent;
}

.unit-leaflet-icon .map-marker,
.call-leaflet-icon .call-marker {
    position: absolute;
    left: 0;
    top: 0;
}

.unit-leaflet-icon .map-marker {
    transform: translate(-14px, -16px);
}

.call-leaflet-icon .call-marker {
    transform: translate(-15px, -15px);
}

.leaflet-tooltip {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 5px;
    background: rgba(10, 13, 17, 0.94);
    color: #fff;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.65);
    font-size: 11px;
    font-weight: 700;
}

.leaflet-tooltip-top::before {
    border-top-color: rgba(10, 13, 17, 0.94);
}

#map-controls {
    pointer-events: auto;
}

#map-missing {
    z-index: 60;
    pointer-events: none;
    background: rgba(10, 13, 17, 0.82);
}


/* ============================================================
   Calibration topbar button and modal
   ============================================================ */

.topbar-button {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 6px;
    background: rgba(255, 255, 255, .07);
    color: #f4f6f8;
    cursor: pointer;
    font-weight: 800;
}

.topbar-button:hover {
    background: rgba(255, 255, 255, .14);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, .72);
}

.calibration-modal {
    width: min(430px, 100%);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 9px;
    background: #11151b;
    color: #f4f6f8;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .65);
}

.calibration-modal header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.calibration-modal header strong {
    display: block;
    margin-top: 3px;
    font-size: 18px;
}

#close-calibration {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 5px;
    background: rgba(255, 255, 255, .06);
    color: #fff;
    cursor: pointer;
    font-size: 20px;
}

#calibration-login-view,
#calibration-tools-view {
    padding: 16px;
}

#calibration-login-view label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 800;
}

#calibration-password {
    width: 100%;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 6px;
    outline: none;
    background: rgba(255, 255, 255, .05);
    color: #fff;
}

#calibration-login-submit,
.calibration-actions button {
    width: 100%;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 6px;
    background: rgba(255, 255, 255, .08);
    color: #fff;
    cursor: pointer;
    font-weight: 800;
}

#calibration-login-submit:hover,
.calibration-actions button:hover {
    background: rgba(255, 255, 255, .15);
}

.calibration-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
}

.calibration-hint {
    margin: 12px 0 0;
    font-size: 12px;
    opacity: .65;
}


/* ============================================================
   Legend and callsign visibility
   ============================================================ */

.legend-content {
    padding: 16px;
}

.legend-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 7px;
    background: rgba(255, 255, 255, .04);
    cursor: pointer;
}

.legend-toggle span {
    min-width: 0;
}

.legend-toggle strong,
.legend-toggle small {
    display: block;
}

.legend-toggle small {
    margin-top: 5px;
    opacity: .62;
    line-height: 1.35;
}

.legend-toggle input {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    cursor: pointer;
}

#close-legend {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 5px;
    background: rgba(255, 255, 255, .06);
    color: #fff;
    cursor: pointer;
    font-size: 20px;
}

/*
 * When callsigns are disabled, only the arrow remains visible.
 * Hovering the unit marker reveals its label again.
 */
body.callsigns-hidden .unit-leaflet-icon .marker-label {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-4px);
    transition:
        opacity .14s ease,
        transform .14s ease,
        visibility 0s linear .14s;
}

/*
 * Keep the compact callsign label hidden while the toggle is off.
 * Leaflet's hover tooltip remains the only hover UI and shows:
 * callsign, unit type, name and radio channel.
 */
body.callsigns-hidden
.unit-leaflet-icon
.map-marker:hover
.marker-label {
    visibility: hidden;
    opacity: 0;
    transform: translateX(-4px);
}

/* Keep the arrow itself easy to hover. */
body.callsigns-hidden .unit-leaflet-icon .map-marker {
    min-width: 34px;
    min-height: 38px;
}


/* ============================================================
   Website MKGMS shell
   ============================================================ */

.mkgms-web-modal {
    position: fixed;
    inset: 0;
    z-index: 7000;
    background: rgba(0, 0, 0, .82);
}

.mkgms-login-shell {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    padding: 20px;
}

#mkgms-web-login-form {
    width: min(410px, 94vw);
    padding: 24px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 9px;
    background: #11151b;
    box-shadow: 0 24px 80px rgba(0,0,0,.7);
}

#mkgms-web-login-form label {
    display: block;
    margin-top: 13px;
    font-size: 12px;
}

#mkgms-web-login-form input {
    width: 100%;
    margin-top: 6px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 5px;
    background: rgba(255,255,255,.05);
    color: #fff;
}

#mkgms-web-login-form button {
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 5px;
    background: rgba(255,255,255,.08);
    color: #fff;
    cursor: pointer;
    font-weight: 800;
}

#mkgms-web-login-form small {
    display: block;
    margin-top: 12px;
    opacity: .6;
}

.mkgms-iframe-shell {
    position: absolute;
    inset: 0;
}

#mkgms-web-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
}


.calibration-actions-grid {
    grid-template-columns: 1fr 1fr;
}


.calibration-progress {
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, .11);
    border-radius: 6px;
    background: rgba(255, 255, 255, .04);
}

.calibration-progress strong,
.calibration-progress small {
    display: block;
}

.calibration-progress small {
    margin-top: 5px;
    opacity: .65;
}
