/* ── Reset & Custom Properties ──────────────────────────────────────────── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
  --bg: #f2f4f7;
  --card: #fff;
  --hdr: #0d1b2a;
  --border: #dde2ea;
  --text: #0d1b2a;
  --muted: #536070;
  --hint: #96a1ae;
  --info-bg: #eaf2fb;   --info-txt: #1655a2;
  --warn-bg: #fef8ec;   --warn-txt: #8a5a0a;
  --succ-bg: #eaf7ef;   --succ-txt: #1a6b3c;
  --dang-bg: #fdeced;   --dang-txt: #9b1f22;
  --plan-bg: #f5f3ff;   --plan-txt: #5b21b6;
  --font-d: 'Libre Baskerville', Georgia, serif;
  --font-b: 'IBM Plex Sans', system-ui, sans-serif;
  --font-m: 'IBM Plex Mono', 'Courier New', monospace;
  --r: 6px;
  --rs: 4px;
  --navy: #0d1b2a;
}

html {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  font-family: var(--font-b);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.hdr {
  background: var(--hdr);
  padding: 0 24px;
  height: 58px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.hdr-brand h1 { font-family: var(--font-d); font-size: 19px; color: #fff; letter-spacing: -.2px; }
.hdr-brand p  { font-size: 11px; color: #7a9ec4; letter-spacing: .07em; text-transform: uppercase; margin-top: 1px; }
.hdr-r        { display: flex; align-items: center; gap: 12px; }
.hdr-user     { font-size: 11px; color: #c0cdd9; }

/* ── Filter Bar ─────────────────────────────────────────────────────────── */
.fbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.pills { display: flex; gap: 5px; overflow-x: auto; flex: 1; scrollbar-width: none; padding: 4px 0; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex-shrink: 0;
  height: 25px;
  padding: 0 11px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: transparent;
  font-family: var(--font-b);
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: all .13s;
}
.pill:hover  { border-color: var(--pc); color: var(--pc); }
.pill.on     { background: var(--pc); border-color: var(--pc); color: #fff; }
.pdot        { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.fbar-sep    { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; }
.rlbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--hint);
  padding-right: 8px;
  border-right: 1px solid var(--border);
  margin-right: 3px;
  align-self: center;
  flex-shrink: 0;
}
.rbtn {
  flex-shrink: 0;
  height: 25px;
  padding: 0 11px;
  border-radius: var(--rs);
  border: 1px solid var(--border);
  background: transparent;
  font-family: var(--font-b);
  font-size: 11px;
  color: var(--hint);
  cursor: pointer;
  white-space: nowrap;
  transition: all .13s;
}
.rbtn:hover, .rbtn.on { border-color: #1655a2; color: #1655a2; background: var(--info-bg); }

/* ── Stats Bar ──────────────────────────────────────────────────────────── */
.sbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 72px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
}
.sbar::-webkit-scrollbar { display: none; }

.hstat-section {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.hstat-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding-right: 14px;
  border-right: 1px solid var(--border);
  margin-right: 0;
  min-width: 46px;
  align-self: center;
}

.hstat-trade { color: #1655a2; }
.hstat-fdi   { color: #8a5a0a; }

.hstat-div {
  width: 1px;
  height: 36px;
  background: #c8d3de;
  margin: 0 20px;
  flex-shrink: 0;
}

.hstat-item {
  padding: 0 18px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  text-align: center;
}

.hstat-item-last {
  border-right: none;
}

.headline-stat-value {
  display: block;
  font-family: var(--font-m);
  font-size: 21px;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.15;
}

.headline-stat-label {
  display: block;
  font-size: 11px;
  color: var(--hint);
  margin-top: 1px;
}

.headline-stat-sublabel {
  display: block;
  font-size: 10px;
  color: var(--hint);
  margin-top: 1px;
}

/* ── Main Content Grid ──────────────────────────────────────────────────── */
/* Two columns: left (sbar + charts) and right panel.
   Right panel spans from filter bar down — full height of mc.
   clamp() keeps rp readable at any viewport width. */
.mc {
  display: grid;
  grid-template-columns: 1fr clamp(200px, 18vw, 340px);
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* Left column: sbar flush to top, then padded chart area below */
.mc-left {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* sbar stretches edge-to-edge within the left column */
.mc-left > .sbar {
  flex-shrink: 0;
  /* inherit border-bottom from .sbar; add right border to meet rp */
  border-right: none;
}

/* Chart/commodity panel — padded independently from sbar */
.mc-left > .lp {
  flex: 1;
  min-height: 0;
  padding: 16px 16px 16px 32px;
  gap: 8px;
  /* lp is already display:flex flex-direction:column — padding applied here
     instead of on .mc so sbar can be flush */
}

/* ── Loading / Error Overlay ─────────────────────────────────────────────── */
#mcOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 20;
  gap: 10px;
}
.ov-spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: #1655a2;
  border-radius: 50%;
  animation: ov-spin .7s linear infinite;
}
@keyframes ov-spin { to { transform: rotate(360deg); } }
.ov-txt { font-family: var(--font-b); font-size: 11px; color: var(--hint); }
.ov-error { text-align: center; max-width: 320px; }
.ov-error-icon { font-size: 20px; margin-bottom: 8px; color: var(--warn-txt); }
.ov-error-title { font-family: var(--font-d); font-size: 15px; color: var(--text); margin-bottom: 6px; }
.ov-error-msg { font-size: 11px; color: var(--muted); line-height: 1.55; margin-bottom: 14px; }
.ov-retry {
  height: 30px;
  padding: 0 16px;
  border-radius: var(--rs);
  border: 1px solid #1655a2;
  background: var(--info-bg);
  font-family: var(--font-b);
  font-size: 11px;
  color: #1655a2;
  cursor: pointer;
  transition: background .13s;
}
.ov-retry:hover { background: #d6e8f8; }

/* ── Left Panel ─────────────────────────────────────────────────────────── */
.lp {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  padding: 0;
  gap: 8px;
}
.ph  { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 0; flex-shrink: 0; }
.pt  { font-family: var(--font-d); font-size: 15px; color: var(--text); }
.psub { font-size: 10px; color: var(--hint); margin-top: 2px; }
.chart-note { font-size: 10px; color: var(--hint); margin-top: 2px; font-style: italic; }
.yr-reset {
  background: none; border: none; padding: 0 0 0 4px;
  font-family: var(--font-b); font-size: 10px; color: #1655a2;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.yr-reset:hover { color: #0d3d7a; }
.cmpr-wrap { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--hint); flex-shrink: 0; margin-top: 3px; cursor: pointer; }
.cmpr-wrap input { cursor: pointer; accent-color: #1655a2; }

/* Trade chart container — fixed height
   padding-left reserves room for the vertical year-range slider;
   the slider is position:absolute so canvas width: 100% = content width only */
.tc { flex-shrink: 0; height: 240px; position: relative; padding-left: 20px; }
.tc canvas { width: 100% !important; height: 100% !important; }

/* ── Year-range slider ───────────────────────────────────────────────────── */
.yr-range-slider {
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 14px;
  display: flex;
  align-items: stretch;
  touch-action: none;
}
.yr-track {
  width: 3px;
  background: var(--border);
  border-radius: 2px;
  position: relative;
  flex: 1;
  margin: 0 auto;
}
.yr-range-fill {
  position: absolute;
  left: 0;
  right: 0;
  background: #1655a2;
  border-radius: 2px;
}
.yr-handle {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: white;
  border: 2px solid #1655a2;
  left: 50%;
  transform: translate(-50%, -50%);
  cursor: ns-resize;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
  transition: box-shadow .12s;
  user-select: none;
}
.yr-handle:hover,
.yr-handle:active { box-shadow: 0 0 0 4px rgba(22,85,162,0.18); }

/* Investment marker strip — padding-left aligns with chart canvas */
.ms        { flex-shrink: 0; margin-top: 0; margin-bottom: 0; height: 86px; padding-left: 20px; }
.ms-inner  { position: relative; height: 70px; overflow: visible; }
.ms-detail { height: 16px; display: flex; align-items: center; margin-top: 0; }
.ms-dt     { font-size: 11px; color: var(--hint); font-family: var(--font-m); }

/* New bar-based marker elements (inline styles used in buildMarkers) */
.ms-bar  { position: absolute; border-radius: 1px 1px 0 0; }
.ms-dot  { position: absolute; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: transform .12s; }
.ms-dot:hover { transform: translate(-50%, -50%) scale(1.35) !important; }
.ms-inline { position: absolute; overflow: hidden; pointer-events: none; }

/* Commodity section — fills remaining left panel space */
.comsec  { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sec-hdr { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 8px; padding-bottom: 7px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.comc {
  flex: 1;
  min-height: 0;
  position: relative;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.comc canvas {
  position: absolute;
  top: 16px; left: 16px;
  width: calc(100% - 32px) !important;
  height: calc(100% - 32px) !important;
}

/* ── Right Panel ────────────────────────────────────────────────────────── */
/* .rp spans full height of .mc — from top of sbar row to bottom of content.
   Padding on .mc handles spacing on the right; rp itself has no outer margin. */
.rp {
  background: white;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  margin: 0;
  /* Small right breathing room matching body padding */
  margin-right: 0;
}
.rp-hdr  { padding: 0; flex-shrink: 0; }
.rpt     { font-family: var(--font-d); font-size: 13px; color: var(--text); padding: 11px 11px 0; margin: 0; flex-shrink: 0; line-height: 1.3; }
.rpst    { font-size: 10px; color: var(--hint); padding: 3px 11px 0; margin-bottom: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Cards scrollable area */
.cards-wrap { flex: 1; min-height: 0; overflow-y: auto; padding: 0 11px 12px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.cards-wrap::-webkit-scrollbar       { width: 3px; }
.cards-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Year groups */
.yg   { margin-bottom: 11px; }
.ylbl { font-family: var(--font-m); font-size: 11px; font-weight: 600; color: var(--hint); letter-spacing: .04em; padding-bottom: 5px; border-bottom: 1.5px solid var(--border); margin-bottom: 5px; }

/* Investment cards */
.icard {
  background: var(--card);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 0 var(--r) var(--r) 0;
  padding: 8px 10px;
  margin-bottom: 5px;
  transition: box-shadow .13s;
  animation: fu .2s both;
}
@keyframes fu { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.icard:hover { box-shadow: 0 2px 8px rgba(13,27,42,.07); }
.ic-name { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 1px; line-height: 1.3; }
.ic-name-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--hint); }
.ic-name-link:hover { border-bottom-color: var(--text); }
.ic-loc  { font-size: 10px; color: var(--hint); margin-bottom: 2px; }
.ic-sec  { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.ic-meta { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.ic-type { font-size: 10px; color: var(--hint); }
.ic-val  { font-family: var(--font-m); font-size: 11px; font-weight: 600; color: var(--text); }
.ic-jobs { font-size: 10px; color: var(--hint); }

/* Status badges */
.sbadge  { display: inline-flex; align-items: center; height: 18px; padding: 0 8px; border-radius: 9px; font-size: 10px; font-weight: 600; margin-top: 4px; }
.s-a { background: var(--succ-bg); color: var(--succ-txt); }
.s-b { background: var(--info-bg); color: var(--info-txt); }
.s-n { background: var(--warn-bg); color: var(--warn-txt); }
.s-p { background: var(--plan-bg); color: var(--plan-txt); }
.s-c { background: var(--dang-bg); color: var(--dang-txt); }

/* Flag note */
.ic-flag { font-size: 10px; color: var(--warn-txt); background: var(--warn-bg); border: 1px solid #f0d090; border-radius: var(--rs); padding: 3px 7px; margin-top: 4px; line-height: 1.4; }

/* Empty state */
.empty     { text-align: center; padding: 24px 10px; }
.empty p   { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.empty-sub { font-size: 10px; line-height: 1.55; color: var(--hint); margin-top: 4px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Country Chart Component (country-chart.js)
   All classes prefixed cc- to avoid collisions.
   ═══════════════════════════════════════════════════════════════════════════ */
#country-charts-section {
  display: none;
}
.cc-wrap        { background: var(--card); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; }
.cc-header      { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.cc-header-name { font-size: 15px; font-weight: 600; color: var(--text); }
.cc-header-hint { font-size: 10px; color: var(--hint); }
.cc-body        { display: flex; gap: 8px; align-items: flex-start; }
.cc-vslider     { width: 46px; flex-shrink: 0; position: relative; }
.cc-chart-col   { flex: 1; min-width: 0; }
.cc-strip       { position: relative; height: 72px; overflow: visible; margin-top: 2px; }
.cc-evt-row     { min-height: 34px; display: flex; align-items: flex-start; padding: 6px 0 4px; border-top: 1px solid var(--border); margin-top: 4px; }
.cc-evt-hint    { font-size: 11px; color: var(--hint); align-self: center; }
.cc-evt-single  { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; width: 100%; font-size: 11px; }
.cc-evt-co      { font-weight: 600; color: var(--text); }
.cc-evt-det     { color: var(--muted); }
.cc-evt-val     { color: #BA7517; font-weight: 600; }
.cc-evt-jobs    { color: var(--muted); }
.cc-evt-multi   { width: 100%; font-size: 11px; }
.cc-evt-mhdr    { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.cc-evt-div     { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.cc-evt-tbl     { width: 100%; border-collapse: collapse; font-size: 11px; }
.cc-evt-tbl td  { padding: 3px 8px 3px 0; vertical-align: top; color: var(--muted); }
.cc-et-co       { color: var(--text) !important; font-weight: 500; max-width: 180px; }
.cc-et-val      { color: #BA7517 !important; font-weight: 500; white-space: nowrap; }
.cc-evt-close   { background: none; border: none; font-size: 15px; color: var(--muted); cursor: pointer; padding: 0 2px; line-height: 1; flex-shrink: 0; }
.cc-evt-close:hover { color: var(--text); }
.cc-bd-panel    { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.cc-bd-hdr      { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.cc-bd-title    { font-size: 11px; font-weight: 600; color: var(--text); }
.cc-bd-back     { background: none; border: 1px solid var(--border); border-radius: 999px; font-size: 10px; color: var(--muted); cursor: pointer; padding: 2px 10px; white-space: nowrap; transition: border-color .12s, color .12s; }
.cc-bd-back:hover { border-color: #1655a2; color: #1655a2; }
.cc-bd-bars     { display: flex; flex-direction: column; gap: 5px; }
.cc-bd-row      { display: grid; grid-template-columns: 120px 1fr 64px; align-items: center; gap: 8px; }
.cc-bd-lbl      { font-size: 11px; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-bd-bar-wrap { background: var(--bg); border-radius: 3px; height: 10px; overflow: hidden; }
.cc-bd-bar      { height: 100%; border-radius: 3px; transition: width .25s; }
.cc-bd-val      { font-size: 10px; color: var(--text); text-align: right; white-space: nowrap; }

@media (max-width: 768px) {
  .cc-bd-row { grid-template-columns: 90px 1fr 56px; }
}

/* ── Phase 1: hidden components ─────────────────────────────────────────── */
.site-footer { display: none; }

/* ── Keyboard focus indicators ──────────────────────────────────────────── */
.pill:focus-visible,
.rbtn:focus-visible,
.ov-retry:focus-visible,
.yr-reset:focus-visible,
.cc-bd-back:focus-visible,
.cc-evt-close:focus-visible {
  outline: 2px solid #1655a2;
  outline-offset: 2px;
}
.cmpr-wrap input:focus-visible {
  outline: 2px solid #1655a2;
  outline-offset: 1px;
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .pill, .rbtn, .ov-retry, .yr-handle, .ms-dot,
  .cc-bd-back, .cc-bd-bar, .icard {
    transition: none !important;
    animation: none !important;
  }
  .ov-spinner {
    animation: none !important;
    border-top-color: var(--border);
  }
}

/* ── Link Preview Popup ──────────────────────────────────────────────────── */
#lp-popup {
  display: none;
  position: fixed;
  z-index: 9999;
  align-items: center;
  gap: 9px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 4px 16px rgba(13,27,42,.12), 0 1px 4px rgba(13,27,42,.06);
  padding: 8px 11px 8px 10px;
  max-width: 320px;
  min-width: 160px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
}
#lp-popup.lp-visible {
  opacity: 1;
  transform: translateY(0);
}
#lp-favicon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: contain;
}
.lp-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}
.lp-domain {
  font-family: var(--font-b);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lp-url {
  font-family: var(--font-m);
  font-size: 10px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lp-ext-icon {
  width: 10px;
  height: 10px;
  color: var(--hint);
  flex-shrink: 0;
}
@media (prefers-reduced-motion: reduce) {
  #lp-popup { transition: none !important; }
}
