:root {
    --bg: #111827;
    --panel: #172033;
    --panel2: #1f2937;
    --text: #eef2ff;
    --muted: #9ca3af;
    --line: #334155;
    --accent: #38bdf8;
    --accent2: #22c55e;
    --danger: #ef4444;
}

* { box-sizing: border-box; }
html,
body {
    width: 100%;
    height: 100%;
}
body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #162033, #111827);
}
.headerActions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}
.headerLinks {
    display: flex;
    align-items: center;
    gap: 11px;
    font-size: 13px;
    white-space: nowrap;
}
.headerLinks a {
    color: #bae6fd;
    text-decoration: none;
    border-bottom: 1px solid rgba(186, 230, 253, 0.38);
    padding-bottom: 1px;
}
.headerLinks a:hover {
    color: #f0f9ff;
    border-bottom-color: #f0f9ff;
}
.headerLinks .downloadAppLink {
    color: #7dd3fc;
    font-weight: 650;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 16px; margin-bottom: 14px; }
p { color: var(--muted); margin-top: 4px; }

.layout {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    overflow: hidden;
}

.mapPanel {
    position: relative;
    min-height: 0;
}
#map { height: 100%; width: 100%; background: #0f172a; }
.helpPopup {
    position: absolute;
    right: 14px;
    top: 14px;
    z-index: 700;
    max-width: 390px;
    background: rgba(15, 23, 42, 0.94);
    border: 1px solid rgba(56, 189, 248, 0.45);
    border-radius: 14px;
    padding: 13px 15px;
    font-size: 13px;
    line-height: 1.42;
    color: var(--text);
    box-shadow: 0 16px 45px rgba(0,0,0,0.35);
    cursor: pointer;
    opacity: 1;
    transition: opacity 650ms ease;
}
.helpPopup.fadeOut { opacity: 0; }
.helpPopup > strong { display: block; font-size: 14px; margin-bottom: 8px; color: #e0f2fe; }
.helpPopup p { margin: 0 0 8px; color: #cbd5e1; }
.helpPopup .helpStepTitle { display: block; margin-bottom: 1px; color: #f8fafc; font-weight: 700; }
.helpPopup b { color: #f8fafc; font-weight: 700; }
.helpPopup code { display: inline; margin: 0; color: #f8fafc; font-size: inherit; }
.helpPopup small { color: #f8fafc; font-weight: 600; opacity: 0.9; }
.mapPlacementHint {
    position: absolute;
    left: 50%;
    top: 18px;
    z-index: 900;
    max-width: min(500px, calc(100% - 32px));
    padding: 11px 15px;
    border-radius: 13px;
    background: rgba(8, 47, 73, 0.94);
    border: 1px solid rgba(56, 189, 248, 0.92);
    color: #f0f9ff;
    box-shadow: 0 14px 34px rgba(0,0,0,0.32);
    font-size: 13px;
    line-height: 1.35;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -10px);
    transition: opacity 160ms ease, transform 160ms ease;
}
.mapPlacementHint.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}
.mapPlacementHint strong { display: block; font-size: 13px; margin-bottom: 2px; }
.mapPlacementHint span { color: #dbeafe; }
.leaflet-container.mapPlacementActive { cursor: crosshair; }
.leaflet-container.mapPlacementActive .leaflet-interactive { cursor: crosshair; }
.newZonePreviewMarker {
    background: transparent;
    border: 0;
    pointer-events: none;
}
.newZonePreviewVisual {
    position: relative;
    width: 190px;
    height: 52px;
    pointer-events: none;
}
.newZonePreviewCross {
    position: absolute;
    left: 0;
    top: 0;
    width: 52px;
    height: 52px;
    border: 3px solid #ffffff;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.26);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.90), 0 0 0 7px rgba(255,255,255,0.20), 0 0 18px rgba(0,0,0,0.55);
    animation: newZonePulse 1.1s ease-in-out infinite;
}
.newZonePreviewCross::before,
.newZonePreviewCross::after {
    content: '';
    position: absolute;
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.88);
}
.newZonePreviewCross::before {
    left: 50%;
    top: 7px;
    width: 3px;
    height: 32px;
    transform: translateX(-50%);
}
.newZonePreviewCross::after {
    left: 7px;
    top: 50%;
    width: 32px;
    height: 3px;
    transform: translateY(-50%);
}
.newZonePreviewLabel {
    position: absolute;
    left: 62px;
    top: 10px;
    display: inline-block;
    white-space: nowrap;
    padding: 7px 10px;
    border-radius: 9px;
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid rgba(255,255,255,0.92);
    box-shadow: 0 3px 12px rgba(0,0,0,0.45);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
}
@keyframes newZonePulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.90), 0 0 0 7px rgba(255,255,255,0.20), 0 0 18px rgba(0,0,0,0.55); }
    50% { transform: scale(1.08); box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.90), 0 0 0 12px rgba(255,255,255,0.12), 0 0 22px rgba(0,0,0,0.60); }
}

.editorPanel {
    min-height: 0;
    overflow: auto;
    border-left: 1px solid var(--line);
    background: var(--panel);
    padding: 14px;
}

.card {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 14px;
}

label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 10px;
}

input, select {
    width: 100%;
    margin-top: 5px;
    padding: 8px 9px;
    color: var(--text);
    background: #0f172a;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
}

input:focus, select:focus { border-color: var(--accent); }
.flagBox {
    margin-bottom: 10px;
    padding: 8px 9px;
    background: #0f172a;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.flagTitle {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 7px;
}
.checkLabel {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 5px 0;
    color: var(--text);
    font-size: 13px;
}
.checkLabel input {
    width: auto;
    margin: 0;
    padding: 0;
}
.checkLabel span { color: var(--text); }

.row { display: grid; gap: 10px; }
.row.two { grid-template-columns: 1fr 1fr; }
.row.three { grid-template-columns: 0.8fr 1fr 1fr; }
/* Radius fields have intentionally fixed label heights so all number inputs
   sit on one clean baseline even when Hardy's labels wrap differently. */
.radiusRow {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    align-items: end;
}
.radiusRow > label {
    min-width: 0;
    min-height: 76px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    line-height: 1.22;
}
.radiusRow > label input {
    margin-top: 9px;
    flex: 0 0 auto;
}
.radiusRow[data-visible-fields="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.radiusRow[data-visible-fields="1"] { grid-template-columns: minmax(0, 1fr); }
.radiusHidden { display: none !important; }
.radiusRow input:disabled {
    opacity: 0.48;
    cursor: not-allowed;
}
button {
    border: 1px solid var(--line);
    background: #0f172a;
    color: var(--text);
    border-radius: 9px;
    padding: 9px 11px;
    cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: #075985; border-color: #0ea5e9; }
button.danger { background: #7f1d1d; border-color: var(--danger); }
.actions, .buttonRow { display: flex; gap: 8px; flex-wrap: wrap; }
.buttonRow { margin-top: 4px; }

.editorHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.editorHeader h2 { margin: 0; }
.compactDelete {
    flex: 0 0 auto;
    padding: 7px 10px;
    font-size: 12px;
    line-height: 1.1;
}
.zoneListCard { padding-bottom: 8px; }
.zoneList { display: grid; gap: 8px; }
code {
    display: block;
    word-break: break-all;
    color: #bae6fd;
    margin-top: 6px;
    font-size: 12px;
}
.zoneItem {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px;
    cursor: pointer;
    background: #111827;
}
.zoneItem:hover, .zoneItem.active { border-color: var(--accent); }
.zoneItem strong { font-size: 13px; }
.zoneItem span { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }
.badge { color: #111827; background: var(--accent); border-radius: 999px; padding: 1px 7px; font-size: 11px; margin-left: 6px; }
.badge.JAM { background: #2563eb; color: #eff6ff; }
.badge.SPOOF { background: #fb923c; }
.badge.MIXED { background: #c084fc; }

@media (max-width: 980px) {
    .layout { grid-template-columns: 1fr; height: auto; }
    #map { height: 58vh; }
    .editorPanel { border-left: 0; border-top: 1px solid var(--line); }
    .topbar { flex-direction: column; align-items: flex-start; }
    .headerActions { width: 100%; justify-content: flex-start; }
}

@media (max-width: 620px) {
    .headerActions { gap: 10px; }
    .headerLinks { width: 100%; }
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal.open { display: flex; }
.modalBackdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.72);
    backdrop-filter: blur(2px);
}
.modalCard {
    position: relative;
    width: min(460px, calc(100vw - 32px));
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.45);
}
.modalCard h2 { margin-bottom: 8px; }
.modalCard p { margin-bottom: 14px; line-height: 1.4; }
.modalButtons { margin-top: 14px; justify-content: flex-end; }
.uploadMessage {
    min-height: 20px;
    margin-top: 10px;
    color: #fbbf24;
    font-size: 13px;
}

.spoofToPin span {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fee2e2;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.30), 0 1px 5px rgba(0,0,0,0.35);
}


.mapLegend {
    position: absolute;
    right: 14px;
    bottom: 36px;
    z-index: 500;
    background: rgba(15, 23, 42, 0.90);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    min-width: 205px;
    font-size: 13px;
    color: var(--text);
    box-shadow: 0 12px 35px rgba(0,0,0,0.30);
}
.mapLegend strong {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
}
.mapLegend div {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 5px 0;
    color: var(--muted);
}
.mapLegend hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 8px 0;
}
.legendDot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid rgba(255,255,255,0.60);
}
.legendDot.jam { background: #2563eb; }
.legendDot.spoof { background: #f97316; }
.legendDot.mixed { background: #7c3aed; }
.legendPin {
    width: 13px;
    height: 21px;
    display: inline-block;
    flex: 0 0 13px;
    background: url('https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png') center / 13px 21px no-repeat;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.28));
}
.legendSpoofPin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    background: #ef4444;
    border: 2px solid #fee2e2;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.30), 0 1px 5px rgba(0,0,0,0.35);
}
.legendLine {
    width: 28px;
    border-top: 3px dashed #ef4444;
    display: inline-block;
}

.legendSpoofDirection {
    width: 28px;
    height: 0;
    display: inline-block;
    flex: 0 0 28px;
    border-top: 3px dashed #ef4444;
}


.mapToolbar {
    position: absolute;
    right: 14px;
    top: 14px;
    z-index: 800;
    display: flex;
    gap: 9px;
    align-items: center;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.62);
    border-radius: 18px;
    box-shadow: 0 16px 45px rgba(0,0,0,0.35);
    user-select: none;
    transition: top 220ms ease, left 220ms ease, right 220ms ease;
}
.mapToolbar button {
    padding: 10px 14px;
    font-size: 13px;
    background: rgba(2, 6, 23, 0.68);
    border-color: rgba(148, 163, 184, 0.38);
    border-radius: 13px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.035);
}
.mapToolbar button:hover { border-color: rgba(56, 189, 248, 0.85); }
.mapToolbar button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    border-color: rgba(100, 116, 139, 0.34);
    color: #a3adbd;
}
.toolbarHandle {
    color: #cbd5e1;
    cursor: move;
    padding: 6px 4px;
    line-height: 0.85;
    letter-spacing: -2px;
    font-size: 18px;
}
.radiusHandle span {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f8fafc;
    border: 3px solid #0f172a;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.85), 0 2px 8px rgba(0,0,0,0.45);
}

.aircraftMarker {
    background: transparent;
    border: 0;
}
.aircraftMarker .planeBadge {
    display: flex;
    width: 46px;
    height: 46px;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 3px 8px rgba(0,0,0,0.38));
}
.aircraftMarker .planeBadge img {
    display: block;
    width: 46px;
    height: 46px;
    object-fit: contain;
    transform: rotate(-90deg);
    filter: brightness(0) saturate(100%);
    user-select: none;
    pointer-events: none;
}
.aircraftInfoMarker {
    background: transparent;
    border: 0;
    overflow: visible !important;
}
.aircraftInfoCard {
    position: absolute;
    left: 0;
    bottom: 36px;
    width: 265px;
    min-height: 0;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.68);
    color: var(--text);
    border: 1px solid rgba(56, 189, 248, 0.22);
    border-radius: 12px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
    font-size: 11.5px;
    line-height: 1.42;
    pointer-events: none;
    backdrop-filter: blur(2px);
}
.aircraftInfoCard::before,
.aircraftInfoCard::after {
    content: '';
    position: absolute;
    left: 18px;
    bottom: -10px;
    width: 0;
    height: 0;
    border-style: solid;
}
.aircraftInfoCard::before {
    border-width: 10px 10px 0 0;
    border-color: rgba(56, 189, 248, 0.22) transparent transparent transparent;
    bottom: -11px;
}
.aircraftInfoCard::after {
    border-width: 9px 9px 0 0;
    border-color: rgba(15, 23, 42, 0.68) transparent transparent transparent;
    bottom: -9px;
    left: 19px;
}
.aircraftInfoCard strong {
    display: block;
    margin-bottom: 5px;
    color: #e0f2fe;
}
.popupMuted {
    color: #cbd5e1;
}
.popupHint {
    display: block;
    margin-top: 8px;
    color: #e0f2fe;
    font-size: 10.5px;
    font-weight: 600;
}

.psxSection {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.psxSection h3 {
    margin: 0 0 9px;
    font-size: 13px;
    color: #8ccfff;
}
.inlineCheck {
    display: inline-flex;
    margin: 0 0 10px;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0f172a;
}
