/* MENA Risk Monitor - full-screen 3D map as the background (light, ink-wash),
   dark frosted-glass panels floating above it. Colour after Chinese ink-wash painting: grey-white
   paper, ink-black text and outlines, pigment accents (gamboge, ochre, vermilion,
   jade, azurite). Transformer forecasts carry an azurite-indigo marker. */
:root {
  --bg: #ecedeb;
  --panel: rgba(20, 22, 26, 0.84);
  --panel-strong: rgba(26, 28, 33, 0.88);
  --panel-border: rgba(255, 255, 255, 0.1);
  --hair: rgba(255, 255, 255, 0.1);
  --line: #5a5d63;
  --shadow: 0 18px 46px rgba(10, 12, 16, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --ink: #f2f3f4;
  --ink-2: #c9ccd1;
  --muted: #92969d;
  --grid: rgba(255, 255, 255, 0.09);
  --paper-ink: #111214;
  --red: #b8262b;      /* vermilion */
  --orange: #c8692b;   /* ochre */
  --yellow: #e0a52c;   /* gamboge */
  --teal: #2f8f7d;     /* jade */
  --neutral: #8a8b86;  /* ink grey */
  --ok: #2f8f7d;
  --fc-a: #5fd3ff;     /* transformer forecast: bright azurite -> violet, glowing on dark glass */
  --fc-b: #b49bff;
  --radius: 10px;
  --gap: 14px;   /* one gap: top bar -> panels, and between panels */
  --display: "Michroma", "Inter", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 13.5px; line-height: 1.5; overflow-x: hidden; }

/* ---------------- background stage (the map) */
.stage { position: fixed; inset: 0; z-index: 0; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.stage .svgmap { position: absolute; inset: 0; }
.stage .svgmap svg { width: 100%; height: 100%; display: block; }
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, rgba(236,237,235,0) 62%, rgba(236,237,235,0.5) 100%);
}
.stage.dim::after { background: rgba(236, 237, 235, 0.55); }

/* ---------------- floating UI layer */
.app { position: relative; z-index: 1; pointer-events: none; min-height: 100vh; padding: var(--gap) 16px; }
.app > * { pointer-events: auto; }
#view { pointer-events: none; }
#view .float, #view .map-ui, #view .crumbs, #view .page { pointer-events: auto; }

.glass {
  background: var(--panel);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.framed { position: relative; }
.code { position: absolute; right: 14px; top: 12px; font-family: var(--mono); font-size: 9.5px; letter-spacing: 1.2px; color: var(--muted); text-transform: uppercase; pointer-events: none; }

/* ---------------- top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; position: relative; z-index: 50; }  /* menus open above the floating panels */
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand .mark { width: 30px; height: 30px; border-radius: 50%; position: relative; border: 1.5px solid var(--ink); display: grid; place-items: center; }
.brand .mark span { background: #e0443a !important; box-shadow: 0 0 8px rgba(224,68,58,0.8) !important; }
.brand .mark::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; border: 1px solid var(--line); }
.brand .mark span { width: 7px; height: 7px; border-radius: 50%; background: var(--red); box-shadow: 0 0 6px rgba(184,38,43,0.6); z-index: 1; }
.brand h1 { font-family: var(--display); font-size: 14px; margin: 0; letter-spacing: 2.2px; text-transform: uppercase; font-weight: 400; }
.brand .sub { font-size: 11.5px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid var(--hair); font-size: 12px; color: var(--ink-2); white-space: nowrap; }
a.pill, button.pill { font: inherit; font-size: 12px; cursor: pointer; color: var(--ink); text-decoration: none; }
a.pill:hover, button.pill:hover, a.pill.on { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.22); }
.menu { position: relative; }
.menu .drop { position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; padding: 6px; display: none; flex-direction: column; z-index: 70; }
.menu.open .drop { display: flex; }
.menu .drop button { all: unset; cursor: pointer; padding: 8px 10px; border-radius: 6px; font-size: 12.5px; color: var(--ink); }
.menu .drop button:hover { background: rgba(255,255,255,0.1); }
.menu .drop small { display: block; color: var(--muted); font-size: 11px; }
.lang button { all: unset; cursor: pointer; padding: 2px 7px; border-radius: 999px; font-size: 11.5px; color: var(--muted); }
.lang button.on { background: rgba(255,255,255,0.16); color: var(--ink); }
.lamp { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.lamp.ok { background: var(--ok); box-shadow: 0 0 6px rgba(47,143,125,0.55); }
.lamp.red { background: var(--red); box-shadow: 0 0 6px rgba(184,38,43,0.6), 0 0 14px rgba(184,38,43,0.35); }
.lamp.orange { background: var(--orange); box-shadow: 0 0 6px rgba(200,105,43,0.5); }
.lamp.yellow { background: var(--yellow); box-shadow: 0 0 6px rgba(224,165,44,0.5); }
.lamp.off { background: #5a5d63; }
.lamp.b4 { background: #c0272d; box-shadow: 0 0 6px rgba(224,60,60,0.8), 0 0 14px rgba(224,60,60,0.45); }
.lamp.b3 { background: #d9564c; box-shadow: 0 0 6px rgba(217,86,76,0.6); }
.lamp.b2 { background: #e8968d; box-shadow: 0 0 5px rgba(232,150,141,0.45); }
.lamp.b1 { background: #d9d2d0; }
.lamp.pulse { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------------- transformer forecast marking */
.fc {
  background: linear-gradient(90deg, var(--fc-a), var(--fc-b));
  -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 650;
  filter: drop-shadow(0 0 6px rgba(120, 190, 255, 0.55));
}
.fc-tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px;
  font: 600 10px/1.6 var(--mono); letter-spacing: 0.6px; text-transform: uppercase; color: #e6e1ff; cursor: help; white-space: nowrap;
  background: linear-gradient(rgba(22,24,28,0.92), rgba(22,24,28,0.92)) padding-box, linear-gradient(90deg, var(--fc-a), var(--fc-b)) border-box;
  border: 1px solid transparent; box-shadow: 0 0 14px rgba(140, 170, 255, 0.35);
}
.fc-tag::before { content: "◆"; font-size: 9px; color: var(--fc-a); }
.fc-meter i { background: linear-gradient(90deg, var(--fc-a), var(--fc-b)) !important; box-shadow: 0 0 8px rgba(120,190,255,0.55); }

/* ---------------- hint icon */
.i { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; margin-left: 5px; border: 1px solid var(--line); color: var(--muted); font: 600 9px/1 var(--mono); text-transform: none; letter-spacing: 0; vertical-align: 1px; cursor: help; flex: none; }
.i:hover, .i:focus { border-color: var(--ink); color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(255,255,255,0.1); }
.hint-text b { color: var(--ink); }
.hint-text { max-width: 300px; line-height: 1.55; color: var(--ink-2); }

/* ---------------- floating layout */
.float { position: fixed; top: var(--top, 80px); bottom: 16px; width: 340px; display: flex; flex-direction: column; gap: var(--gap); overflow-y: auto; padding: 0 0 4px; scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.15) transparent; }
/* columns reach the screen edge with padding, so card shadows are not clipped by the scroll box */
.float { width: 380px; padding: 0 24px 40px 16px; bottom: 0; }
.float.left { left: 0; }
.float.right { right: 0; padding: 0 16px 40px 24px; }
.map-ui { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px - 2 * 360px); padding: 8px 12px; flex-wrap: wrap; justify-content: center; }
.crumbs { position: fixed; left: 50%; transform: translateX(-50%); top: var(--top, 80px); display: flex; align-items: center; gap: 10px; padding: 8px 12px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px - 2 * 360px); }

.card { padding: 16px 18px; min-width: 0; flex: none; }
.card h2 { font-family: var(--display); font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.6px; color: var(--ink); margin: 0 0 12px; font-weight: 400; display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding-right: 88px; }
.card .sub2 { margin: -4px 0 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

.regional .regional-body { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 14px; align-items: center; }
.mini { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mini b { color: var(--ink); font-family: var(--mono); font-weight: 600; }
.summary-line { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hair); font-size: 12.5px; color: var(--ink-2); display: flex; gap: 14px; flex-wrap: wrap; }
.summary-line b { color: var(--ink); font-family: var(--mono); }

.seg { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; padding: 3px; border-radius: 8px; background: rgba(255,255,255,0.06); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; font: inherit; font-size: 12px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: rgba(255,255,255,0.16); color: var(--ink); }
.seg button:hover:not(.on) { color: var(--ink); }

.legend { display: flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--ink-2); flex-wrap: wrap; justify-content: center; }
.legend .bar { width: 100px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #e4e0df, #e8b5ae, #d6675d, #b8262b, #7c1218); }
.legend .thr { width: 80px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #ffb36b, #ff8a2a, #e8500f, #c23a08); }
.legend .ball { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend .sw { display: inline-flex; align-items: center; gap: 6px; }

/* ---------------- glass info panel */
.tooltip {
  position: fixed; z-index: 60; pointer-events: none; padding: 12px 14px; min-width: 210px; max-width: 320px;
  background: linear-gradient(155deg, rgba(40,43,49,0.78) 0%, rgba(22,24,28,0.7) 50%, rgba(30,32,37,0.76) 100%);
  backdrop-filter: blur(16px) saturate(150%); -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 10px;
  box-shadow: 0 18px 40px rgba(10, 12, 16, 0.3), inset 0 1px 0 rgba(255,255,255,0.12);
  font-size: 12px; opacity: 0; transform: translateY(4px); transition: opacity 0.15s, transform 0.15s; overflow: hidden; isolation: isolate;
}
.tooltip::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: 0.25; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.tooltip.show { opacity: 1; transform: translateY(0); }
.tooltip .t { font-weight: 650; font-size: 13px; margin-bottom: 5px; display: flex; align-items: center; gap: 8px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); }
.tooltip .r b { color: var(--ink); font-weight: 600; font-family: var(--mono); font-size: 11.5px; }
.tooltip .sep { height: 1px; background: var(--hair); margin: 6px 0; }
.tooltip .cap { font: 600 9.5px/1.6 var(--mono); letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted); }
.tooltip .cap.f { color: var(--fc-a); }

/* ---------------- lists */
.list { display: flex; flex-direction: column; gap: 1px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 76px 52px; align-items: center; gap: 10px; padding: 8px 8px; border-radius: 6px; cursor: pointer; transition: background 0.2s; }
.row:hover, .row.hl { background: rgba(255, 255, 255, 0.09); }
.row .nm { display: flex; align-items: center; gap: 9px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.row .val { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.meter { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; }
.delta { font-family: var(--mono); font-size: 10.5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.delta.up { color: #ff6a5c; }
.delta.down { color: #46d1b5; }

.brief { font-size: 13px; color: var(--ink); line-height: 1.65; }
.risks { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
.risks li { margin-bottom: 5px; }
.risks li::marker { color: #ff8a2a; }
.srcs { margin-top: 10px; font-size: 11px; color: var(--muted); line-height: 1.6; }
.srcs a { color: var(--ink-2); text-decoration: underline; text-decoration-color: rgba(255,255,255,0.25); text-underline-offset: 2px; }
.srcs a:hover { color: var(--ink); }
.prov-row { margin-top: 10px; }
.ai-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--muted); cursor: help; }

/* ---------------- country view */
.btn { border: 1px solid var(--hair); background: rgba(255,255,255,0.08); border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 12.5px; color: var(--ink); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; min-height: 34px; }
.btn:hover { background: rgba(255,255,255,0.15); }
.title-big { font-family: var(--display); font-size: 17px; font-weight: 400; letter-spacing: 2px; text-transform: uppercase; margin: 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: rgba(255,255,255,0.08); border: 1px solid var(--hair); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chips button { border: 1px solid var(--hair); background: rgba(255,255,255,0.07); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 11.5px; color: var(--ink-2); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chips button.off { opacity: 0.4; }
.chips .dot { width: 8px; height: 8px; border-radius: 50%; }

.score { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 12px; align-items: center; }
.parts { display: flex; flex-direction: column; gap: 9px; }
.part .lab { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; gap: 8px; }
.part .lab span { display: inline-flex; align-items: center; }
.part .lab b { color: var(--ink); font-family: var(--mono); font-weight: 600; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; padding: 4px 5px; border-bottom: 1px solid var(--grid); }
.tbl td { padding: 6px 5px; border-bottom: 1px solid rgba(255,255,255,0.06); font-variant-numeric: tabular-nums; }
.tbl td.num { font-family: var(--mono); font-size: 11.5px; }
.tbl tr[data-iso]:hover td, .tbl tr[data-lane]:hover td { background: rgba(255,255,255,0.08); cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl th.fch { color: var(--fc-a); }
.lane-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 0; }
.ctx { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ctx .big { font-family: var(--mono); font-size: 20px; font-weight: 600; }
.ctx .note { font-size: 11.5px; color: var(--muted); }

.chart svg { width: 100%; display: block; overflow: visible; }
.axis text { fill: var(--muted); font-size: 10px; font-family: var(--mono); }
.axis line, .axis path { stroke: var(--grid); }
.footer { position: fixed; z-index: 1; left: 50%; transform: translateX(-50%); bottom: 2px; font-size: 10px; color: var(--muted); pointer-events: none; white-space: nowrap; }
.empty { color: var(--muted); font-size: 12.5px; padding: 6px 0; }
.loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--ink-2); font-family: var(--display); letter-spacing: 2px; text-transform: uppercase; font-size: 11px; }

/* ---------------- data & model page */
.page { position: relative; max-width: 1040px; margin: 18px auto 40px; padding: 30px 36px; }
.page h2.pt { font-family: var(--display); font-size: 16px; letter-spacing: 2px; text-transform: uppercase; font-weight: 400; margin: 0 0 6px; }
.page .lede { font-size: 15px; color: var(--ink-2); max-width: 760px; margin: 0 0 22px; line-height: 1.6; }
.page h3 { font-family: var(--display); font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase; font-weight: 400; margin: 26px 0 10px; }
.page p, .page li { font-size: 13.5px; color: var(--ink-2); line-height: 1.65; max-width: 820px; }
.page ul { padding-left: 18px; margin: 0; }
.arch { width: 100%; height: auto; display: block; margin: 6px 0 4px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 4px; }
.stat { padding: 14px 16px; border-radius: 8px; background: rgba(255,255,255,0.05); border: 1px solid var(--hair); }
.concept { margin: 10px 0 4px; }
.stat .big { font-family: var(--mono); font-size: 24px; font-weight: 600; }
.stat .lab { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.stat .vs { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

@media (max-width: 1180px) {
  .float { width: 340px; }
  .map-ui, .crumbs { max-width: calc(100vw - 32px - 2 * 320px); }
}
@media (max-width: 900px) {
  .stage { height: 60vh; inset: 0 0 auto 0; }
  .stage.dim { height: 100vh; }
  .app { padding: 10px 12px; }
  .topbar { flex-wrap: wrap; }
  .float, .map-ui, .crumbs { position: static; transform: none; width: auto; max-width: none; overflow: visible; }
  #view.withmap { display: flex; flex-direction: column; gap: 12px; padding-top: calc(60vh - 70px); }
  #view > * { pointer-events: auto; }
  .footer { position: static; transform: none; text-align: center; margin-top: 12px; white-space: normal; }
  .card h2 { padding-right: 0; margin-top: 16px; }
  .score, .regional .regional-body, .stats, .ctx { grid-template-columns: minmax(0, 1fr); }
  .page { padding: 20px 18px; }
}
@media (prefers-reduced-motion: reduce) { .lamp.pulse { animation: none; } }
