/* ==========================================================================
   Forced Migration Viewer — restyled to the pigeon-effect.com design language.
   White surface (like the homepage showcase), Space Mono throughout — the site
   uses a single typewriter face; hairline borders and soft shadows in
   place of the original heavy drop-shadows. Selectors and layout behavior
   (flex ratios, positions, z-order, display toggling) stay compatible with
   the viewer JS from github.com/Pigeon-Effect/Forced-Migration-Visualization —
   only the skin changed. Event-type colors are data colors and are kept.
   ========================================================================== */

:root {
  --bg: #ffffff;
  --card: #ffffff;                         /* panel / tooltip surface          */
  --frost: rgba(231, 229, 228, 0.8);       /* footer bar (stone-200/80)        */
  --line: rgba(0, 0, 0, 0.07);             /* hairline borders                 */
  --line-strong: rgba(0, 0, 0, 0.12);
  --ink-head: #0f172a;                     /* slate-900 — headings, hover      */
  --ink: #1e293b;                          /* slate-800 — body text            */
  --ink-2: #64748b;                        /* slate-500 — secondary            */
  --ink-3: #94a3b8;                        /* slate-400 — muted                */
  --accent: #8b5cf6;                       /* forced-migration project accent  */
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -20px rgba(15, 23, 42, 0.25);
  --shadow-pop: 0 12px 32px -12px rgba(15, 23, 42, 0.25);
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Space Mono', 'Courier New', monospace;
    font-weight: 300;
    background-color: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    padding: 12px;
    box-sizing: border-box;
}

/* Standalone mode (not iframed): leave room for the fixed site-style footer. */
body.standalone {
    padding-bottom: 54px;
}

/* Slim scrollbars for the overflow panels */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); border-radius: 4px; }

#main-container {
    display: flex;
    flex-direction: row;
    gap: 16px;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

#left-panel {
    flex: 3;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#right-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    height: 100%;
    overflow-y: auto;
}

#chart, #sankey-chart-container {
     width: 100%;
     height: 100%;
     background-color: var(--card);
     border: 1px solid var(--line);
     border-radius: 16px;
     box-shadow: var(--shadow-card);
     box-sizing: border-box;
     padding: 10px; /* Inner padding for the panel */
}

#chart {
     display: flex;
     justify-content: center;
     align-items: center;
}

#sankey-chart-container {
    display: none;
    position: relative;
}

#controls-container,
#line-chart-container-wrapper,
#bibliography-container,
#country-search-container {
     width: 100%;
     background-color: var(--card);
     border: 1px solid var(--line);
     border-radius: 16px;
     box-shadow: var(--shadow-card);
     padding: 15px;
     box-sizing: border-box;
}

#controls-container {
     flex-shrink: 0;
}
#country-search-container {
    margin-bottom: 0;
}

/* The trend line and the sources box share whatever height the controls leave.
   flex-basis: 0 makes the grow factors the whole story — roughly 55 / 45. */
#line-chart-container-wrapper {
     flex-grow: 11;
     flex-basis: 0;
     min-height: 150px;
     display: flex;
}

#bibliography-container {
    flex-grow: 9;
    flex-basis: 0;
    min-height: 130px;
    overflow-y: auto;
    font-size: 11px;
}

#bibliography-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
}

#bibliography-content th, #bibliography-content td {
    border: 1px solid var(--line);
    padding: 5px;
    text-align: left;
    vertical-align: top;
}

#bibliography-content th {
    background-color: rgba(0, 0, 0, 0.025);
    font-family: 'Space Mono', 'Courier New', monospace;
    font-weight: 400;
    font-size: 8.5px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ink-2);
}

#bibliography-content a { color: var(--accent); }

#bibliography-content .source-id-cell {
    width: auto;
    min-width: 30px;
    text-align: left;
    font-weight: bold;
    word-break: break-all;
}

.bibliography-placeholder { color: var(--ink-3) !important; }

#event-type-filters {
     display: flex;
     justify-content: center;
     flex-wrap: wrap;
     gap: 10px;
     padding-bottom: 15px;
}

#slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 25px 5px 25px;
}

/* Uppercase mono chips; the four fills are data colors (they match the
   ribbons in the charts) and deliberately survive the restyle. */
.filter-button {
    padding: 7px 14px;
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 9px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    border-width: 1px;
    border-style: solid;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s, opacity 0.2s;
    color: var(--ink);
}
#btn-expulsion { background-color: #FADBC5; border-color: #F6CFAF; }
#btn-deportation { background-color: #C8F0D9; border-color: #B8E8C9; }
#btn-repatriation { background-color: #C6EAE5; border-color: #B5E2DC; }
#btn-escape { background-color: #E1D2ED; border-color: #D5C5E3; }
#btn-expulsion.active { background-color: #E67E22; color: white; border-color: #D35400; }
#btn-deportation.active { background-color: #2ECC71; color: white; border-color: #27AE60; }
#btn-repatriation.active { background-color: #1ABC9C; color: white; border-color: #16A085; }
#btn-escape.active { background-color: #9B59B6; color: white; border-color: #8E44AD; }
.filter-button:hover:not(.active) { opacity: 0.75; }
.filter-button.active:hover { opacity: 0.85; }

#year-slider {
     width: 100%;
     margin-bottom: 8px;
}
#slider-values {
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 10px;
    letter-spacing: 0.2em;
    color: var(--ink-2);
    text-align: center;
    width: 100%;
    margin-top: 3px;
}

.noUi-target {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    box-shadow: none;
}
.noUi-connect { background: var(--accent); }
.noUi-horizontal .noUi-handle {
    width: 10px; height: 22px; border-radius: 3px; background: #fff;
    border: 1px solid var(--line-strong); box-shadow: var(--shadow-card);
    right: -5px; top: -5px; cursor: default !important;
}
.noUi-handle:active { cursor: default !important; border-color: var(--ink-3); }
.noUi-handle:focus { outline: none; }
.noUi-handle::before, .noUi-handle::after { display: none; }

.chord path { fill-opacity: 0.7; stroke: #fff; stroke-width: 0.5px; transition: opacity 0.2s ease-in-out; }
.group path { stroke: #fff; stroke-width: 1px; transition: opacity 0.2s ease-in-out; cursor: pointer; }
.group path:hover { stroke-width: 2px; stroke: var(--ink-2); }
.group text {
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 10px;
    fill: var(--ink);
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}
.faded { opacity: 0.1 !important; }

#tooltip {
    position: absolute;
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-pop);
    padding: 12px;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    max-width: 300px;
    max-height: 70vh;
    overflow-y: auto;
    transform: translate(20px, 25px); /* Position below cursor */
    transition: opacity 0.2s;
}
/* Tooltip HTML is assembled in JS; keep every nested element on the site face. */
#tooltip, #tooltip * {
    font-family: 'Space Mono', 'Courier New', monospace !important;
}

#line-chart-svg {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}
.line-chart-axis-label { font-family: 'Space Mono', 'Courier New', monospace; font-size: 10px; fill: var(--ink-2); }
.line-chart-title {
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 15px;
    font-weight: 600;
    fill: var(--ink-head);
    text-anchor: middle;
}
.line-chart-placeholder { font-family: 'Space Mono', 'Courier New', monospace; font-size: 12px; fill: var(--ink-3); text-anchor: middle; }
.line { stroke-width: 1.5px; }
.axis path, .axis line { fill: none; stroke: var(--line-strong); shape-rendering: crispEdges; }
.axis text { font-family: 'Space Mono', 'Courier New', monospace; font-size: 9px; fill: var(--ink-2); }

.legend { font-family: 'Space Mono', 'Courier New', monospace; font-size: 10px; }
.legend rect { stroke-width: 0.5px; stroke: var(--line-strong); }
.legend text { fill: var(--ink); dominant-baseline: middle; }

.citation-marker circle.mask { fill: white; }
.citation-marker circle.data-circle { stroke: none; opacity: 0.9; cursor: help; }
.citation-marker text { font-size: 7px; font-weight: bold; text-anchor: middle; dominant-baseline: central; pointer-events: none;}
.citation-marker:hover circle.data-circle { opacity: 1; }

#country-search-input {
    width: 100%; padding: 9px 14px; font-size: 12px;
    font-family: 'Space Mono', 'Courier New', monospace; font-weight: 300;
    color: var(--ink);
    border: 1px solid var(--line-strong); border-radius: 999px; box-sizing: border-box;
    background: var(--card);
    outline: none;
    transition: border-color 0.2s;
}
#country-search-input:focus { border-color: var(--accent); }
#country-search-input::placeholder { color: var(--ink-3); }
#country-search-results {
    max-height: 200px; overflow-y: auto; margin-top: 8px;
    border: 1px solid var(--line); border-radius: 10px; display: none;
}
.country-search-item {
    padding: 8px 12px; cursor: pointer; font-size: 12px;
    border-bottom: 1px solid var(--line);
}
.country-search-item:hover { background-color: rgba(0, 0, 0, 0.03); }
.country-search-item:last-child { border-bottom: none; }

#back-to-chord-button {
    position: absolute;
    top: 15px;
    right: 15px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    font-family: 'Space Mono', 'Courier New', monospace;
    background-color: rgba(255, 255, 255, 0.9);
    color: var(--ink-2);
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    cursor: pointer;
    transition: color 0.2s ease-in-out, border-color 0.2s ease-in-out;
    z-index: 10;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-card);
}
#back-to-chord-button:hover {
    color: var(--ink-head);
    border-color: var(--ink-3);
}

#sankey-svg .node rect { shape-rendering: crispEdges; }
#sankey-svg .node:hover rect { opacity: 0.8; }
#sankey-svg .link:hover path { stroke-opacity: 0.8; }
#sankey-svg .node text,
#sankey-svg .sankey-node-label-text,
.sankey-node-name,
.sankey-node-value {
    pointer-events: none;
    user-select: none;
    font-family: 'Space Mono', 'Courier New', monospace;
}

/* "Immigration to X" / "Emigration from X" heads above the Sankey columns */
#sankey-svg .sankey-direction-label {
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    fill: var(--ink-2);
}

/* --------------------------------------------------------------------------
   JS-injected popups: the chord-ribbon click menu (pick source or target
   country for the Sankey) and the line chart's bubble tooltip. Same card
   surface as #tooltip.
   -------------------------------------------------------------------------- */
#chord-click-menu {
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-pop);
    padding: 10px;
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 12px;
}
.chord-click-menu-title {
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 9px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ink-2);
    margin-bottom: 8px;
}
.chord-click-menu-item {
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background-color 0.15s;
}
.chord-click-menu-item + .chord-click-menu-item { margin-top: 4px; }
.chord-click-menu-item:hover { background-color: rgba(0, 0, 0, 0.05); }
.chord-click-menu-item strong { color: var(--ink-head); }

#bubble-tooltip {
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-pop);
    padding: 10px 12px;
}
#bubble-tooltip, #bubble-tooltip * {
    font-family: 'Space Mono', 'Courier New', monospace !important;
}
#bubble-tooltip th {
    font-family: 'Space Mono', 'Courier New', monospace !important;
    font-weight: 400;
    font-size: 9px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-2);
    background: rgba(0, 0, 0, 0.025);
    text-align: left;
}
#bubble-tooltip td { border-top: 1px solid var(--line); }

/* --------------------------------------------------------------------------
   Footer bar (standalone mode only) — mirrors the site footer in light mode,
   same chrome as the UNGA viewer.
   -------------------------------------------------------------------------- */
.viewer-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  box-sizing: border-box;
  background: var(--frost);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 1300;
}

.viewer-footer-brand {
  font-family: 'Space Mono', 'Courier New', monospace;
  font-weight: 300;
  font-size: 1rem;
  letter-spacing: 0.05em;
  color: #334155;
  text-decoration: none;
}

.viewer-footer-label {
  font-family: 'Space Mono', 'Courier New', monospace;
  font-size: 8px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-3);
}

#exitViewerBtn {
  font-family: 'Space Mono', 'Courier New', monospace;
  font-weight: 300;
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-decoration: none;
  transition: color 0.3s ease;
}
#exitViewerBtn:hover { color: var(--ink-head); }
