:root {
    --bg: #07090c;
    --bar: #121417;
    --panel: rgba(14, 18, 24, 0.88);
    --line: rgba(140, 200, 230, 0.16);
    --text: #e8edf2;
    --muted: #8a96a3;
    --lane: #2bd0ee;
    --friend: #80e0ff;
    --hostile: #ff3b3b;
    --amber: #ffb020;
    --hub: #1fae4b;
    --top-h: 44px;
    --side-w: 44px;
    --status-h: 26px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 13px;
}

.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }

/* ---------- Structure ---------- */
#map {
    position: absolute;
    top: var(--top-h);
    left: var(--side-w);
    right: 0;
    bottom: var(--status-h);
    background: #04070b;
}

body.no-chrome .chrome { display: none !important; }
body.no-chrome #map { top: 0; left: 0; bottom: 0; }
body.no-chrome #scenario-pill { top: 0; }
body.no-chrome #compass { top: 14px; }
body.no-chrome #event-log { top: 150px; bottom: 16px; }

/* ---------- Top bar ---------- */
#topbar {
    position: absolute;
    inset: 0 0 auto 0;
    height: var(--top-h);
    background: var(--bar);
    border-bottom: 1px solid #000;
    display: flex;
    align-items: center;
    padding: 0 14px;
    gap: 16px;
    z-index: 1200;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    font-size: 12px;
    min-width: 180px;
}
.brand-mark { width: 22px; height: 22px; color: #ff7a1a; }

.search {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(260px, 40vw);
    height: 28px;
    padding: 0 12px;
    border-radius: 14px;
    background: #000;
    border: 1px solid #2a2f36;
}
.search svg { width: 14px; height: 14px; color: var(--muted); flex: none; }
.search input {
    flex: 1;
    min-width: 0;
    background: none;
    border: 0;
    outline: 0;
    color: var(--text);
    font: inherit;
    font-size: 12px;
    font-style: italic;
}

.top-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
}
.alert-count {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 700;
    background: #2a2f36;
    color: var(--muted);
    transition: background .3s, color .3s;
}
.alert-count.on { background: var(--hostile); color: #fff; animation: blink 1s infinite; }
.clock { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.clock small { margin-left: 4px; color: var(--muted); font-size: 10px; }
.clock .ts { margin-left: 8px; padding: 1px 5px; border-radius: 3px; background: #2a2f36; color: var(--lane); font-size: 10px; }

/* ---------- Scenario pill ---------- */
#scenario-pill {
    position: absolute;
    top: var(--top-h);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    padding: 10px 44px 12px;
    background: rgba(40, 44, 50, 0.92);
    border: 1px solid rgba(255,255,255,0.08);
    border-top: 0;
    border-radius: 0 0 18px 18px;
    font-size: 14px;
    font-weight: 500;
    color: #f2f4f6;
    white-space: nowrap;
    box-shadow: 0 6px 18px rgba(0,0,0,0.5);
    pointer-events: none;
}

/* ---------- Toolbar ---------- */
#toolbar {
    position: absolute;
    top: var(--top-h);
    left: 0;
    bottom: var(--status-h);
    width: var(--side-w);
    background: var(--bar);
    border-right: 1px solid #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
    gap: 4px;
    z-index: 1200;
}
#toolbar button {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: #6f7a86;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: color .15s, background .15s;
}
#toolbar button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
#toolbar button[data-action="tracks"] svg { fill: currentColor; stroke: none; }
#toolbar button:hover { background: #1d2126; color: #fff; }
#toolbar button.active { color: #e8edf2; }
#toolbar .sep { width: 22px; height: 1px; background: #2a2f36; margin: 6px 0; }

/* ---------- Status bar ---------- */
#statusbar {
    position: absolute;
    inset: auto 0 0 0;
    height: var(--status-h);
    background: var(--bar);
    border-top: 1px solid #000;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 14px;
    font-size: 11px;
    color: #c3cad2;
    z-index: 1200;
    white-space: nowrap;
    overflow: hidden;
}
#statusbar b { font-weight: 500; color: #e8edf2; }
#statusbar .spacer { flex: 1; }

/* ---------- Basemap ---------- */
.basemap { filter: brightness(0.62) saturate(0.7) contrast(1.12) hue-rotate(-6deg); }
.leaflet-container { background: #04070b; font-family: 'Inter', system-ui, sans-serif; }

/* ---------- Lanes ---------- */
.lane {
    stroke: var(--lane);
    filter: drop-shadow(0 0 2px rgba(43, 208, 238, 0.65));
}
.lane-air { stroke-dasharray: 2 5; }
.lane-sea { stroke-dasharray: 6 4; }

.route-done {
    stroke: #5ee8ff;
    stroke-dasharray: 10 6;
    animation: flow 0.9s linear infinite;
    filter: drop-shadow(0 0 4px rgba(94, 232, 255, 0.9));
}
.route-todo { stroke: #bfeaf5; stroke-dasharray: 3 7; opacity: 0.55; }
.route-reroute {
    stroke: var(--amber);
    stroke-dasharray: 10 6;
    animation: flow 0.9s linear infinite;
    filter: drop-shadow(0 0 4px rgba(255, 176, 32, 0.9));
}
.route-blocked { stroke: var(--hostile); stroke-dasharray: 4 6; opacity: 0.85; }
@keyframes flow { to { stroke-dashoffset: -16; } }

/* ---------- Labels & markers ---------- */
.no-bg { background: none !important; border: 0 !important; }

.map-label {
    position: absolute;
    white-space: nowrap;
    font-family: Arial, 'Inter', sans-serif;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.02em;
    color: #fff;
    text-shadow: 0 0 3px #000, 0 0 6px #000, 1px 1px 2px #000;
    pointer-events: none;
    text-transform: uppercase;
}
.map-label.sm { font-size: 11px; font-weight: 600; color: #e6edf3; }
.hide-labels .map-label { display: none; }
.zoom-low .map-label.minor { display: none; }
.zoom-theatre .unit-icon.small, .zoom-theatre .depot-icon { display: none; }

.hub-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 0 3px rgba(0,0,0,0.9)); }
.port-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 0 2px #000); }

.track-icon .glyph {
    width: 16px;
    height: 16px;
    color: #9fe6ff;
    filter: drop-shadow(0 0 2px #000);
    will-change: transform;
}
.track-icon .glyph svg { width: 100%; height: 100%; fill: currentColor; display: block; }
.track-icon .map-label { left: 22px; top: -2px; }

.unit-icon { overflow: visible; }
.unit-icon .sym { width: 100%; height: 100%; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8)); }
.unit-icon .map-label { left: 42px; top: 4px; font-size: 13px; }
.unit-icon .map-label.left { left: auto; right: calc(100% + 8px); }
.unit-icon.attacked .sym { animation: hostileGlow 0.9s ease-in-out infinite; }
.unit-icon.small .sym { width: 26px; height: 18px; margin: 3px 5px; }
.unit-icon.small .map-label { left: 34px; top: 3px; }

.threat-icon .sym { filter: drop-shadow(0 0 6px rgba(255, 59, 59, 0.9)); }
.threat-icon .map-label { top: 7px; color: #ffd0d0; }
.threat-icon.unknown .sym { filter: drop-shadow(0 0 6px rgba(255, 255, 128, 0.8)); animation: blink 1s infinite; }
.threat-icon.unknown .map-label { color: #ffffb0; }

.ripple {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 2px solid var(--hostile);
    border-radius: 50%;
    animation: ripple 2s ease-out infinite;
    pointer-events: none;
}
.ripple.r2 { animation-delay: 1s; }

@keyframes ripple {
    from { transform: scale(0.6); opacity: 0.9; }
    to { transform: scale(4); opacity: 0; }
}
@keyframes hostileGlow {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(255,59,59,0.7)); }
    50% { filter: drop-shadow(0 0 14px rgba(255,59,59,1)); }
}
@keyframes blink { 50% { opacity: 0.45; } }

.threat-zone { animation: zonePulse 2.4s ease-in-out infinite; }
@keyframes zonePulse { 50% { fill-opacity: 0.05; stroke-opacity: 0.4; } }

/* ---------- Compass & controls ---------- */
#compass {
    position: absolute;
    top: calc(var(--top-h) + 50px);
    right: 18px;
    width: 64px;
    height: 64px;
    z-index: 1000;
    pointer-events: none;
}
#compass span {
    position: absolute;
    top: -14px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: #cfd6dd;
}
#compass svg { width: 100%; height: 100%; fill: rgba(30,34,40,0.55); stroke: #cfd6dd; stroke-width: 1.4; }
#compass .dot { fill: #cfd6dd; }

.leaflet-top.leaflet-right { top: 132px; right: 6px; }
body.no-chrome .leaflet-top.leaflet-right { top: 86px; }
.leaflet-bar { border: 0 !important; box-shadow: none !important; }
.leaflet-bar a, .leaflet-bar a:hover {
    width: 26px !important;
    height: 26px !important;
    line-height: 24px !important;
    background: rgba(40, 44, 50, 0.85) !important;
    color: #dfe5ea !important;
    border: 0 !important;
    border-bottom: 1px solid #000 !important;
}
.leaflet-bar a:hover { background: rgba(60, 66, 74, 0.95) !important; }

.leaflet-control-scale-line {
    background: transparent;
    border: 1px solid #dfe5ea;
    border-top: 0;
    color: #dfe5ea;
    font-size: 10px;
    text-shadow: 0 0 3px #000;
}
.leaflet-control-scale-line:not(:first-child) { border-top: 1px solid #dfe5ea; border-bottom: 0; }
.leaflet-control-attribution {
    background: rgba(0,0,0,0.45) !important;
    color: #7d8792 !important;
    font-size: 9px !important;
}
.leaflet-control-attribution a { color: #9aa5b1 !important; }

/* ---------- Popups ---------- */
.leaflet-popup-content-wrapper {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
}
.leaflet-popup-tip { background: var(--panel); }
.leaflet-popup-content { margin: 12px 14px; font-size: 12px; line-height: 1.5; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.pop-title { font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px; }
.pop-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.pop-grid dt { color: var(--muted); }
.pop-grid dd { margin: 0; font-family: 'JetBrains Mono', monospace; font-size: 11px; }

/* ---------- Alert card ---------- */
#alert-card {
    position: absolute;
    top: calc(var(--top-h) + 14px);
    left: calc(var(--side-w) + 14px);
    width: min(400px, calc(100% - var(--side-w) - 28px));
    max-height: calc(100% - var(--top-h) - var(--status-h) - 90px);
    overflow-y: auto;
    transform: translateX(-16px);
    opacity: 0;
    pointer-events: none;
    z-index: 1150;
    background: var(--panel);
    border: 1px solid rgba(255, 59, 59, 0.45);
    border-left: 4px solid var(--hostile);
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6), 0 0 30px rgba(255, 59, 59, 0.15);
    backdrop-filter: blur(8px);
    transition: transform .5s cubic-bezier(.16,1,.3,1), opacity .4s;
    scrollbar-width: thin;
    scrollbar-color: #2a2f36 transparent;
}
#alert-card.visible { opacity: 1; transform: none; pointer-events: auto; }
#alert-card.warn { border-color: rgba(255, 176, 32, 0.45); border-left-color: var(--amber); box-shadow: 0 12px 40px rgba(0,0,0,0.6); }
#alert-card.warn .alert-dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
#alert-card.warn #alert-title { color: var(--amber); }
body.no-chrome #alert-card { top: 14px; left: 14px; max-height: calc(100% - 80px); }

.alert-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px 6px;
}
.alert-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--hostile);
    box-shadow: 0 0 8px var(--hostile);
    animation: blink .8s infinite;
}
#alert-title { color: #ff6b6b; letter-spacing: 0.1em; font-size: 12px; }
.alert-time { margin-left: auto; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }
.alert-body { padding: 0 14px 12px 33px; font-size: 12px; line-height: 1.55; color: #cfd6dd; }
.alert-body p { margin: 0; }
.alert-body .mono { color: #fff; font-size: 11px; }

.reco-head {
    margin: 12px 0 6px -19px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--amber);
}
.reco-list { list-style: none; margin: 0 0 0 -19px; padding: 0; display: grid; gap: 6px; }
.reco {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: rgba(255,255,255,0.025);
    cursor: pointer;
    transition: border-color .2s, background .2s;
}
.reco:hover { border-color: rgba(255, 176, 32, 0.5); }
.reco.selected { border-color: var(--amber); background: rgba(255, 176, 32, 0.08); }
.reco-title { display: flex; align-items: center; gap: 8px; font-weight: 600; color: #fff; font-size: 12px; }
.reco-num {
    flex: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 10px;
    background: var(--amber);
    color: #111;
}
.reco-detail { margin: 3px 0 6px 26px; font-size: 11.5px; color: #b6c0ca; line-height: 1.45; }
.reco-metrics { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-left: 26px; font-size: 11px; color: var(--muted); }
.reco-metrics b { color: #e8edf2; font-weight: 600; }
.reco-metrics .late { color: #ffb020; }
.reco-metrics .early { color: #34d399; }

/* ---------- Event log ---------- */
#event-log {
    position: absolute;
    top: calc(var(--top-h) + 214px);
    right: 14px;
    bottom: calc(var(--status-h) + 40px);
    width: 290px;
    max-height: 340px;
    z-index: 1000;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(8px);
    transition: opacity .3s, transform .3s;
}
#event-log.hidden { opacity: 0; transform: translateX(20px); pointer-events: none; }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    color: #cfd6dd;
}
.live { font-size: 9px; color: #34d399; letter-spacing: 0.1em; }
.live::before { content: '●'; margin-right: 4px; animation: blink 1.4s infinite; }

#log-list {
    list-style: none;
    margin: 0;
    padding: 6px 0;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: #2a2f36 transparent;
}
#log-list li {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 8px;
    padding: 5px 12px;
    font-size: 11.5px;
    line-height: 1.4;
    color: #c3cad2;
    border-left: 2px solid transparent;
    animation: logIn .35s ease-out;
}
#log-list li time { font-family: 'JetBrains Mono', monospace; font-size: 10.5px; color: var(--muted); padding-top: 1px; }
#log-list li.info { border-left-color: var(--lane); }
#log-list li.warn { border-left-color: var(--amber); color: #ffe0a3; }
#log-list li.crit { border-left-color: var(--hostile); color: #ffc4c4; background: rgba(255, 59, 59, 0.07); }
#log-list li.ok { border-left-color: #34d399; }
@keyframes logIn { from { opacity: 0; transform: translateX(10px); } }

/* ---------- Play button ---------- */
#play-btn {
    position: absolute;
    left: calc(var(--side-w) + 14px);
    bottom: calc(var(--status-h) + 46px);
    z-index: 1150;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 8px 10px;
    border-radius: 18px;
    border: 1px solid rgba(43, 208, 238, 0.5);
    background: var(--panel);
    color: var(--text);
    font: 600 12px 'Inter', sans-serif;
    letter-spacing: 0.04em;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: opacity .3s, background .2s;
}
#play-btn:hover { background: rgba(43, 208, 238, 0.18); }
#play-btn svg { width: 16px; height: 16px; fill: var(--lane); }
#play-btn.hidden { opacity: 0; pointer-events: none; }
body.no-chrome #play-btn { left: 14px; bottom: 46px; }

/* ---------- Responsive (iframe étroit) ---------- */
@media (max-width: 760px) {
    .search, #event-log, #compass { display: none; }
    #scenario-pill { padding: 8px 18px 10px; font-size: 12px; }
    #alert-card { left: calc(var(--side-w) + 8px); width: calc(100% - var(--side-w) - 16px); max-height: 55%; }
    body.no-chrome #alert-card { left: 8px; width: calc(100% - 16px); }
    #statusbar span:nth-child(2), #cursor-ll { display: none; }
    .leaflet-top.leaflet-right { top: 56px; }
}
