/* =============================================================================
   Forced Migration — what only this app uses
   -----------------------------------------------------------------------------
   Tokens and the shared components are in projects/static/projects/tools/tool.css
   (linked first by projects/_tool_base.html); the design direction is
   docs/unga-design.md. Plain CSS, linked with {% static_v %}.

   Event-type colours: the owner's red, blue, green and amber, the last three
   tuned to pass the dataviz palette validator (chroma floor, lightness band) on
   both surfaces, each mode with its own steps. Light: #f94144 #1d74b7 #2fa37f
   #d9a521; dark: #f94144 #3b82c4 #2fa37f #b8860b. Re-validated on the token
   surfaces (2026-10-02: light --pe-surface, dark --pe-surface): all checks
   pass; the amber's sub-3:1 contrast in light mode (2.2:1) is relieved by the
   labels on every chip and the Cases table. They mark the same type in every
   view, and nothing else is drawn in them.
   ============================================================================= */

.u-page {
    --t1: #f94144; --t2: #1d74b7; --t3: #2fa37f; --t4: #d9a521;
    --land: color-mix(in srgb, rgb(var(--pe-ink)) 7%, rgb(var(--pe-paper)));
    --land-on: color-mix(in srgb, rgb(var(--pe-ink)) 14%, rgb(var(--pe-paper)));
    --shade-hi: rgb(var(--pe-ink-3)); --warn: rgb(var(--pe-accent-text));
}
html.dark .u-page {
    --t2: #3b82c4; --t4: #b8860b;
}

.fm-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; flex: none; }

/* 1. Top bar: the focus country, a search box or a chip ---------------------- */
.fm-focus { position: relative; display: flex; align-items: center; }
.fm-combo { width: clamp(180px, 16vw, 240px); margin-left: 0; }
.fm-combo .u-combo-list { left: 0; right: auto; width: max(100%, 260px); }
.fm-chip { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 4px 0 6px; border-radius: 999px;
           background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
           font-size: var(--fs-sm); font-weight: 700; color: var(--text); white-space: nowrap; }
.fm-chip[hidden] { display: none; }
.fm-chip .flag { width: 20px; height: 20px; border-radius: 999px; }
.fm-chip button { width: 24px; height: 24px; border: 0; border-radius: 999px; background: none; color: var(--text-3); cursor: pointer; }
.fm-chip button:hover { background: var(--surface-2); color: var(--text); }

/* 2. Filter bar: event types and the years ----------------------------------- */
.fm-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; padding: 10px 24px 8px;
              background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.fm-types { display: flex; flex-wrap: wrap; gap: 6px; }
.fm-type { display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border: 1px solid var(--border);
           border-radius: 999px; background: var(--surface); color: var(--text-3); font-size: var(--fs-sm); cursor: pointer;
           transition: border-color .15s, background-color .15s, color .15s; }
.fm-type .fm-dot { opacity: .35; }
.fm-type:hover { border-color: var(--text-3); color: var(--text); }
.fm-type[aria-pressed="true"] { color: var(--text); border-color: var(--text-3); background: var(--surface-2); font-weight: 700; }
.fm-type[aria-pressed="true"] .fm-dot { opacity: 1; }
.fm-type .u-count { font-weight: 400; color: var(--text-3); font-size: var(--fs-xs); }
.fm-time { flex: 1; min-width: 280px; display: flex; align-items: center; gap: 20px; }
.fm-years { display: flex; flex-direction: column; align-items: flex-start; gap: 0; min-width: 116px; }
.fm-years output { white-space: nowrap; font-variant-numeric: tabular-nums; }
.fm-range-box { position: relative; flex: 1; min-width: 200px; padding-top: 20px; }
.fm-strip { position: absolute; left: 8px; right: 8px; top: 0; width: calc(100% - 16px); height: 26px; display: block; overflow: visible; }
.fm-strip rect { fill: var(--border); }
.fm-strip rect.on { fill: var(--text-3); }
.fm-range { margin-top: -2px; }
.fm-range-box .u-range-scale { margin-top: -4px; }

/* 3. Main: the stage and the side panel -------------------------------------- */
.fm-main { flex: 1; min-height: 0; display: grid; gap: 16px; padding: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) {
    .fm-main { padding: 16px 24px 24px; grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 380px); }
}
.fm-stage { position: relative; min-height: 70vh; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
@media (min-width: 1024px) { .fm-stage { min-height: 0; } }
.fm-side { min-height: 0; padding: 16px; gap: 14px; overflow: hidden; }
@media (max-width: 1023px) {
    .fm-side { overflow: visible; }
    .fm-filters { padding: 10px 16px; }
}

/* Side panel contents */
.fm-side-head { flex: none; display: flex; flex-direction: column; gap: 4px; }
.fm-side-head h2 { display: flex; align-items: center; gap: 10px; font-size: var(--fs-lg); line-height: 22px; font-weight: 700; color: var(--text); }
.fm-side-head h2 .flag { width: 24px; height: 24px; border-radius: 999px; flex: none; }
.fm-side-head h2.fm-pair { font-size: var(--fs-md); line-height: 20px; }
.fm-pair .who { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.fm-pair .flag, .fm-pair .fm-unknown { width: 20px; height: 20px; border-radius: 999px; }
.fm-pair .arrow { color: var(--text-3); }
.fm-side-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; }
.fm-side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; margin-right: -8px; padding-right: 8px; }
.fm-figs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; flex: none; }
.fm-fig .v { font-size: var(--fs-xl); line-height: 28px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.fm-fig .v.big { font-size: var(--fs-2xl); line-height: 36px; }
.fm-fig .u-xs { margin-top: 2px; }
.fm-fig-wide { grid-column: 1 / -1; }
.fm-sub { font-size: var(--fs-sm); line-height: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.fm-sub small { font-weight: 400; color: var(--text-3); font-size: var(--fs-xs); }
.fm-mix { display: flex; height: 8px; border-radius: 999px; overflow: hidden; gap: 2px; background: var(--surface); }
.fm-mix i { display: block; height: 100%; min-width: 2px; }
.fm-mix-keys { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; font-size: var(--fs-xs); color: var(--text-2); }
.fm-mix-keys span { display: inline-flex; align-items: center; gap: 5px; }
.fm-list { list-style: none; margin: 0; padding: 0; }
.fm-list li { display: grid; grid-template-columns: minmax(0, 1fr) 40px 44px; align-items: center; gap: 8px; height: 26px;
              padding: 0 6px; border-radius: 6px; font-size: var(--fs-sm); color: var(--text); }
.fm-list li[data-go] { cursor: pointer; }
.fm-list li[data-go]:hover, .fm-list li.is-on { background: var(--surface-2); }
.fm-list li[data-go]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fm-list .who { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.fm-list .who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-list .who .arrow { color: var(--text-3); flex: none; }
.fm-list .flag, .fm-recs .flag, .fm-cases-table .flag { width: 16px; height: 16px; border-radius: 999px; flex: none; }
.fm-list .bar { position: relative; height: 6px; border-radius: 999px; background: var(--surface-2); }
.fm-list .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--bar); }
.fm-list .v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.fm-unknown { display: inline-block; width: 16px; height: 16px; border-radius: 999px; border: 1.5px dashed var(--text-3); flex: none; }
.fm-spark { display: block; width: 100%; height: 56px; overflow: visible; }
.fm-spark .a-out { fill: none; stroke: var(--text); stroke-width: 1.5; }
.fm-spark .a-in { fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 3 2; }
.fm-spark .axis text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.fm-recs { list-style: none; margin: 0; padding: 0; }
.fm-recs li { padding: 8px 4px; border-top: 1px solid var(--border); font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); cursor: pointer; border-radius: 4px; }
.fm-recs li:hover { background: var(--surface-2); }
.fm-recs li .h { display: flex; align-items: baseline; gap: 6px; color: var(--text); font-size: var(--fs-sm); }
.fm-recs li .h .v { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.fm-note { font-size: var(--fs-xs); line-height: 16px; color: var(--text-3); }
.fm-note b { color: var(--text-2); }
.fm-src { list-style: none; margin: 0; padding: 0; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.fm-src li + li { margin-top: 6px; }
.fm-src a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px; }
.fm-src a:hover { text-decoration-color: var(--text-3); }
.fm-kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; font-size: var(--fs-xs); line-height: 16px; }
.fm-kv dt { color: var(--text-3); }
.fm-kv dd { color: var(--text); overflow-wrap: anywhere; }

/* Status badges (Cases, the record panel) */
.fm-badge { display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 7px; border-radius: 999px;
            font-size: 11px; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
            border: 1px solid var(--border); color: var(--text-2); background: var(--surface); }
.fm-badge[data-s="merged"] { border-style: dashed; }
.fm-badge[data-s="flagged"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, var(--border));
                              background: color-mix(in srgb, var(--warn) 9%, var(--surface)); font-weight: 700; }

/* 4. Map ---------------------------------------------------------------------- */
#fm-map svg, #fm-chord svg { display: block; }
#fm-map path.country { fill: var(--land); stroke: var(--surface); stroke-width: .6px; vector-effect: non-scaling-stroke; stroke-linejoin: round; cursor: pointer; }
#fm-map path.country.on { fill: var(--land-on); }
#fm-map path.hover { fill: none; stroke: var(--text); stroke-width: 1.5px; vector-effect: non-scaling-stroke; pointer-events: none; }
#fm-map path.focus-outline { fill: none; stroke: var(--accent); stroke-width: 2px; vector-effect: non-scaling-stroke; pointer-events: none; }
#fm-map .flow { stroke: var(--surface); stroke-width: .75px; vector-effect: non-scaling-stroke; fill-opacity: .78; cursor: pointer;
                transition: fill-opacity .15s; }
#fm-map .flows.is-dim .flow { fill-opacity: .12; }
#fm-map .flows.is-dim .flow.is-on { fill-opacity: .95; }
#fm-map .ring { fill: none; stroke-width: 1.5px; vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer; }
#fm-map .ring.to { stroke-dasharray: 4 3; }
#fm-map .ring.from { stroke-dasharray: 1 3; stroke-linecap: round; }
#fm-map .flows.is-dim .ring { opacity: .15; }
#fm-map .flows.is-dim .ring.is-on { opacity: 1; }
.fm-shade { position: absolute; left: 16px; top: 16px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: 999px; }
.fm-legend { width: 300px; }
.fm-legend .w-keys { display: flex; align-items: flex-end; gap: 14px; margin-top: 6px; color: var(--text-2); }
.fm-legend .w-keys span { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.fm-legend .w-keys svg { display: block; overflow: visible; }
.fm-legend .w-keys path { fill: var(--text-2); }
.fm-legend .rings { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; }
.fm-legend .rings span { display: inline-flex; align-items: center; gap: 6px; }
.fm-legend .rings i { display: inline-block; width: 12px; height: 12px; border-radius: 999px; border: 1.5px dashed var(--text-2); }
.fm-legend .rings i.from { border-style: dotted; }
.fm-legend .shade { display: block; height: 8px; border-radius: 999px; margin-top: 6px; width: 200px; }

/* 5. Corridors: the chord, and a country's two-sided flow -------------------- */
.fm-chord-ctrl { position: absolute; left: 16px; top: 16px; z-index: 5; padding: 4px; border-radius: 999px; }
.fm-chord-note { position: absolute; left: 16px; bottom: 16px; z-index: 5; max-width: min(420px, calc(100% - 32px)); padding: 10px 14px; }
.fm-chord-note:empty { display: none; }
#fm-chord .arc { stroke: var(--surface); stroke-width: 1px; cursor: pointer; }
#fm-chord .arc.country { fill: var(--text-2); }
#fm-chord .arc.other { fill: var(--text-3); }
#fm-chord .arc:hover { fill: var(--text); }
#fm-chord .ribbon { fill-opacity: .72; stroke: var(--surface); stroke-width: .5px; cursor: pointer; transition: fill-opacity .15s; }
#fm-chord .ribbons.is-dim .ribbon { fill-opacity: .07; }
#fm-chord .ribbons.is-dim .ribbon.is-on { fill-opacity: .9; }
#fm-chord .label { fill: var(--text); font-family: var(--font); font-size: 11px; cursor: pointer; }
#fm-chord .label.other { fill: var(--text-2); font-style: italic; }
#fm-chord .label.dim { fill: var(--text-3); }
#fm-chord .region { fill: var(--text-3); font-family: var(--font); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
#fm-chord .region-band { fill: var(--border); }
#fm-chord .bf-bar { fill: var(--text-2); cursor: pointer; }
#fm-chord .bf-bar.other { fill: var(--text-3); }
#fm-chord .bf-bar.unknown { fill: none; stroke: var(--text-3); stroke-dasharray: 3 2; }
#fm-chord .bf-center { fill: var(--text); }
#fm-chord .bf-link { fill-opacity: .55; stroke: var(--surface); stroke-width: .5px; cursor: pointer; transition: fill-opacity .15s; }
#fm-chord .bf-links.is-dim .bf-link { fill-opacity: .08; }
#fm-chord .bf-links.is-dim .bf-link.is-on { fill-opacity: .85; }
#fm-chord .bf-name { fill: var(--text); font-family: var(--font); font-size: 12px; cursor: pointer; }
#fm-chord .bf-name.other { fill: var(--text-2); font-style: italic; cursor: default; }
#fm-chord .bf-val { fill: var(--text-3); font-family: var(--font); font-size: 11px; }
#fm-chord .bf-head { fill: var(--text-3); font-family: var(--font); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
#fm-chord .bf-title { fill: var(--text); font-family: var(--font); font-size: 14px; font-weight: 700; }
#fm-chord .bf-empty { fill: var(--text-3); font-family: var(--font); font-size: 12px; }
#fm-chord .bf-leader { fill: none; stroke: var(--text-3); stroke-width: 1px; opacity: .6; }
#fm-chord .bf-flag-edge { fill: none; stroke: var(--accent); stroke-width: 2px; }

/* 6. Time series -------------------------------------------------------------- */
.fm-ts { position: absolute; inset: 0; display: flex; flex-direction: column; }
.fm-ts-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex: none; }
.fm-ts-bar .u-seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.fm-ts-bar .u-combo { width: min(240px, 100%); }
.fm-ts-bar [hidden] { display: none !important; }
.fm-ts-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.u-chart .ts-band { stroke: none; opacity: .14; pointer-events: none; }
@media (max-width: 1023px) {
    .u-view[data-panel="series"], .u-view[data-panel="cases"] { position: absolute; }
}

/* 7. Cases --------------------------------------------------------------------- */
.fm-cases { position: absolute; inset: 0; display: flex; flex-direction: column; }
.fm-cases-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex: none; }
.fm-cases-search { margin-left: 0; width: min(340px, 100%); }
.fm-cases-search .u-input { -webkit-appearance: none; appearance: none; }
#fm-cases-count { margin-left: auto; }
.fm-cases-scroll { flex: 1; min-height: 0; overflow: auto; }
.fm-cases-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.fm-cases-table thead th { position: sticky; top: 0; z-index: 1; height: 36px; padding: 0 10px; background: var(--surface);
                           border-bottom: 1px solid var(--border); text-align: left; font-weight: 400; font-size: var(--fs-xs);
                           color: var(--text-3); white-space: nowrap; }
.fm-cases-table th button { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0; border: 0; background: none;
                            color: inherit; font-size: var(--fs-xs); cursor: pointer; white-space: nowrap; }
.fm-cases-table th button:hover { color: var(--text); }
.fm-cases-table th[aria-sort] button { color: var(--text); font-weight: 700; }
.fm-cases-table td { padding: 7px 10px; border-top: 1px solid var(--border); color: var(--text); vertical-align: top; }
.fm-cases-table tbody tr:first-child td { border-top: 0; }
.fm-cases-table tbody tr { cursor: pointer; }
.fm-cases-table tbody tr:hover td { background: var(--surface-2); }
.fm-cases-table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fm-cases-table tr.is-on td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.fm-cases-table tr.is-on td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.fm-cases-table .fm-warn { color: var(--warn); }
.fm-cases-table tr.is-flagged td { background: color-mix(in srgb, var(--warn) 6%, var(--surface)); }
.fm-cases-table .c-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fm-cases-table .c-num small { display: block; color: var(--text-3); font-size: var(--fs-xs); }
.fm-cases-table .c-yrs { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-2); }
.fm-cases-table .route { display: flex; flex-direction: column; gap: 2px; min-width: 180px; }
.fm-cases-table .route span { display: inline-flex; align-items: center; gap: 6px; }
.fm-cases-table .grp { color: var(--text-2); max-width: 220px; }
.fm-cases-table .typ { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.fm-cases-table .src { color: var(--text-3); font-size: var(--fs-xs); max-width: 220px; }
.fm-cases-empty { padding: 32px 16px; }
@media (max-width: 767px) { .fm-cases-table .c-grp, .fm-cases-table .c-src { display: none; } }
.fm-cases-table .m-only { display: none; }
.fm-cases-table .fm-dot.m-only { margin-right: 6px; vertical-align: 1px; }
@media (max-width: 639px) {
    .fm-cases-table .c-type { display: none; }
    .fm-cases-table .m-only { display: inline-block; }
    .fm-cases-table .d-only { display: none; }
    .fm-cases-table .route { min-width: 0; }
    .fm-cases-table td, .fm-cases-table thead th { padding-left: 8px; padding-right: 8px; }
}

/* 8. Drawer ------------------------------------------------------------------ */
.fm-drawer-sec h2 { margin: 0; }
.fm-defs { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 14px; margin-top: 10px; font-size: var(--fs-sm); line-height: 18px; }
.fm-defs dt { align-self: start; display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.fm-defs dd { color: var(--text-2); }
.fm-events { margin: -16px 0 0; padding: 0 0 0 20px; list-style: decimal; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.fm-events li + li { margin-top: 8px; }
.fm-events b { color: var(--text); }
.fm-flagged, .fm-fixes { margin: 8px 0 0; padding: 0; list-style: none; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.fm-flagged li { padding: 10px 12px; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
                 background: color-mix(in srgb, var(--warn) 6%, var(--surface)); }
.fm-flagged b { color: var(--text); }
.fm-fixes li + li { margin-top: 6px; }

/* 9. Phones and narrow windows ---------------------------------------------- */
/* Stacked below 1024 px: the stage takes the height its view needs, the side
   panel follows it, and the page scrolls. The map needs about half its width
   plus the strips for the shade control and the legend; the chord a square. */
@media (max-width: 1023px) {
    .fm-stage { min-height: 0; height: clamp(460px, 75vh, 760px); }
    .fm-stage[data-view="map"] { height: calc(50vw + 170px); }
    .fm-stage[data-view="corridors"] { height: min(calc(100vw + 40px), 85vh); }
}
@media (max-width: 639px) {
    .fm-shade { left: 8px; right: 8px; top: 8px; justify-content: space-between; padding-left: 10px; }
    .fm-shade .u-seg button { padding: 0 9px; }
    #fm-panel-map .u-zoom { display: none; }               /* two fingers zoom on touch */
    .fm-legend { left: 8px; right: 8px; bottom: 8px; width: auto; max-width: none; padding: 8px 10px; }
    .fm-legend .scale-note, .fm-legend .rings { display: none; }
    .fm-legend .w-keys { margin-top: 4px; }
    .fm-chord-ctrl { left: 8px; top: 8px; }
    .fm-chord-note { display: none; }
    .fm-ts-bar { padding: 10px 12px; gap: 6px 10px; }
    .fm-cases-bar { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
    #fm-map .flow, #fm-chord .ribbon, #fm-chord .bf-link { transition: none; }
}
