:root {
  --bg: #070a12;
  --bg2: #0a0f1c;
  --panel: #0d1322;
  --line: #1b2338;
  --line2: #26304a;
  --text: #e7eaf3;
  --muted: #7d88a3;
  --amber: #ffb020;
  --red: #ff4d5e;
  --blue: #4da3ff;
  --green: #3ddc97;
  --violet: #a78bfa;
  --cyan: #22d3ee;
  --font: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(255, 176, 32, .07), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(77, 163, 255, .06), transparent 60%),
    var(--bg);
  min-height: 100vh;
}
.mono { font-family: var(--mono); letter-spacing: .02em; }
.muted { color: var(--muted); }
button { font-family: inherit; }

/* ---------------- header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(13, 19, 34, .9), rgba(7, 10, 18, .6));
  position: sticky; top: 0; z-index: 1000; backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 26px; font-weight: 700; line-height: 1; }
.brand h1 small { font-family: var(--mono); font-size: 12px; color: var(--amber); letter-spacing: .3em; margin-inline-start: 6px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.radar {
  width: 42px; height: 42px; border-radius: 50%; position: relative; overflow: hidden;
  border: 1px solid rgba(255, 176, 32, .5);
  background: repeating-radial-gradient(circle, transparent 0 7px, rgba(255, 176, 32, .15) 7px 8px);
}
.radar::after {
  content: ""; position: absolute; inset: 0;
  background: conic-gradient(from 0deg, rgba(255, 176, 32, .55), transparent 25%);
  animation: sweep 3s linear infinite;
}
.radar span { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--red); top: 11px; left: 26px; box-shadow: 0 0 8px var(--red); animation: blip 3s infinite; }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes blip { 0%, 60% { opacity: 0; } 70% { opacity: 1; } 100% { opacity: 0; } }

.status { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line2); background: var(--bg2); font-size: 12px; color: var(--muted);
}
.chip b { color: var(--text); font-weight: 600; }
.chip.small { padding: 2px 8px; font-size: 11px; }
.chip.live { color: var(--green); border-color: rgba(61, 220, 151, .35); }
.chip.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(61, 220, 151, .7); animation: pulse 1.8s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(61, 220, 151, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 151, 0); } }
.stress-chip b { color: var(--amber); }

/* ---------------- ticker */
.ticker { overflow: hidden; border-bottom: 1px solid var(--line); background: var(--bg2); height: 34px; direction: ltr; }
.ticker-track { display: inline-flex; gap: 36px; white-space: nowrap; padding: 8px 0; animation: tick 60s linear infinite; font-family: var(--mono); font-size: 12px; }
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker-track span b { color: var(--text); font-weight: 600; margin: 0 6px; }
.ticker-track .up { color: var(--green); }
.ticker-track .down { color: var(--red); }
.ticker-track .name { color: var(--muted); font-family: var(--font); }
@keyframes tick { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------------- grid */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 16px 24px; }
.panel {
  background: linear-gradient(180deg, var(--panel), rgba(13, 19, 34, .75));
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; min-width: 0;
  position: relative;
}
.panel::before { /* amber corner accent */
  content: ""; position: absolute; top: -1px; right: 18px; width: 40px; height: 2px; background: var(--amber); border-radius: 2px;
}
.span2 { grid-column: span 2; }
.phead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.phead h2 { margin: 0; font-size: 16px; font-weight: 700; }
.phead .sub { color: var(--muted); font-size: 12px; }
.ptools { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.mini-title { font-size: 13px; margin: 6px 0 8px; font-weight: 500; }

.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 4px 10px; cursor: pointer; font-family: var(--mono); font-size: 12px; }
.seg button.on { background: var(--amber); color: #1a1200; font-weight: 600; }

.btn { background: rgba(255, 176, 32, .12); border: 1px solid rgba(255, 176, 32, .4); color: var(--amber); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { background: rgba(255, 176, 32, .22); }

/* ---------------- graph */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.filters button {
  border: 1px solid var(--line2); background: var(--bg2); color: var(--muted); padding: 3px 10px;
  border-radius: 999px; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.filters button i { width: 8px; height: 8px; border-radius: 50%; }
.filters button.on { color: var(--text); border-color: var(--line2); background: #141b2e; }
.filters button:not(.on) { opacity: .45; }

.graph-wrap { position: relative; height: 440px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: radial-gradient(circle at 50% 50%, #0f1730, #070a12 70%); }
#graph { position: absolute; inset: 0; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; pointer-events: none; }
.detail {
  position: absolute; top: 10px; left: 10px; width: 300px; max-height: calc(100% - 20px); overflow: auto;
  background: rgba(10, 15, 28, .95); border: 1px solid var(--line2); border-radius: 12px; padding: 14px; z-index: 5;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.detail h4 { margin: 6px 0 8px; font-size: 15px; line-height: 1.6; }
.detail p { margin: 0 0 10px; color: #c3c9d9; font-size: 13px; line-height: 1.7; }
.detail .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; }
.detail .close { position: absolute; top: 6px; left: 10px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; }
.detail a { color: var(--amber); font-size: 13px; }
.detail ul { padding-inline-start: 18px; margin: 6px 0 10px; font-size: 12px; color: #c3c9d9; }
.detail li { margin-bottom: 4px; cursor: pointer; }
.detail li:hover { color: var(--amber); }
.tag { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line2); color: var(--muted); }

.replay { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.replay input[type=range] { flex: 1; accent-color: var(--amber); direction: ltr; }

/* ---------------- gauge / warnings */
.gauge-wrap { display: grid; place-items: center; }
#gauge { width: 100%; max-width: 260px; }
.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.warnings li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 12px; }
.warnings .bar { grid-column: 1 / -1; height: 6px; background: #151c30; border-radius: 4px; position: relative; overflow: hidden; }
.warnings .bar span { position: absolute; inset-block: 0; right: 0; border-radius: 4px; }
.warnings .val { font-family: var(--mono); }
.warnings .breach .val { color: var(--red); }
.warnings .breach .lbl::before { content: "● "; color: var(--red); }

/* ---------------- map */
#map { height: 380px; border-radius: 10px; border: 1px solid var(--line); background: #0a0f1c; }
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #0d1322; color: var(--text); border: 1px solid var(--line2); }
.leaflet-popup-content { direction: rtl; font-size: 13px; line-height: 1.6; }
.leaflet-popup-content a { color: var(--amber); }
.pin { border-radius: 50%; position: relative; }
.pin.hot::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid currentColor; animation: ring 1.8s infinite; }
@keyframes ring { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }

/* ---------------- log */
.log { list-style: none; margin: 0; padding: 0; height: 380px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.log li { border-inline-start: 3px solid var(--line2); padding: 6px 10px; background: rgba(20, 27, 46, .5); border-radius: 6px; cursor: pointer; animation: slidein .5s ease; }
.log li:hover { background: rgba(30, 40, 66, .7); }
.log .row { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.log .t { font-size: 13px; line-height: 1.55; }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } }

/* ---------------- distribution */
#dist { display: grid; gap: 10px; }
.drow { display: grid; grid-template-columns: 70px 1fr 32px; align-items: center; gap: 8px; font-size: 12px; }
.dbar { display: flex; height: 14px; background: #151c30; border-radius: 4px; overflow: hidden; }
.dbar span { height: 100%; }
.dnum { font-family: var(--mono); color: var(--muted); text-align: left; }
.dlegend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------------- echo */
#echo { width: 100%; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-inline-end: 5px; }

/* ---------------- markets */
.markets { display: grid; gap: 6px; }
.mrow { display: grid; grid-template-columns: 1fr 80px 70px 54px; align-items: center; gap: 8px; font-size: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.mrow:last-child { border-bottom: 0; }
.mrow .v { font-family: var(--mono); text-align: left; direction: ltr; }
.mrow .c { font-family: var(--mono); text-align: left; direction: ltr; }
.up { color: var(--green); }
.down { color: var(--red); }

/* ---------------- footer */
.foot { margin-top: 10px; padding: 26px 24px 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px;
  background: linear-gradient(180deg, transparent, rgba(13, 19, 34, .6)); }
.foot a { color: var(--amber); text-decoration: none; }
.foot a:hover { text-decoration: underline; }
.foot-disclaimer { max-width: 980px; margin: 0 auto 18px; padding: 14px 18px; border: 1px solid var(--line);
  border-inline-start: 3px solid var(--amber); border-radius: 10px; background: rgba(20, 27, 46, .45); }
.foot-disclaimer h3 { margin: 0 0 6px; font-size: 13px; color: var(--text); font-weight: 600; }
.foot-disclaimer p { margin: 0 0 6px; font-size: 12.5px; line-height: 1.95; color: #aeb6c8; }
.foot-disclaimer p:last-child { margin-bottom: 0; }
.foot-sources { text-align: center; margin-bottom: 16px; line-height: 1.9; }
.foot-bottom { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  max-width: 980px; margin: 0 auto; padding-top: 14px; border-top: 1px dashed var(--line2); }
.foot-bottom .credit { color: var(--muted); }
.foot-bottom .credit a { color: var(--text); font-weight: 600; border-bottom: 1px solid var(--amber); padding-bottom: 1px; }
.foot-bottom .credit a:hover { color: var(--amber); text-decoration: none; }
@media (max-width: 720px) { .foot-bottom { justify-content: center; text-align: center; } .foot { padding: 20px 12px; } }

/* ---------------- tabs + KPIs */
.tabs { display: flex; gap: 4px; padding: 10px 24px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a {
  color: var(--muted); text-decoration: none; padding: 9px 14px; border-radius: 10px 10px 0 0; font-size: 14px;
  border: 1px solid transparent; border-bottom: 0; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--text); background: var(--panel); border-color: var(--line); box-shadow: inset 0 2px 0 var(--amber); }

.kpis { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 10px; padding: 14px 24px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi b { font-size: 24px; font-weight: 600; line-height: 1.1; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.crit b { color: var(--red); }
.kpi.ok b { color: var(--green); }
.kpi.warn b { color: var(--amber); }
.live-kpi b { color: var(--green); display: inline-flex; align-items: center; gap: 8px; }
.ldot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: pulse 1.8s infinite; box-shadow: 0 0 0 0 rgba(61, 220, 151, .7); }
.view[hidden] { display: none !important; }
main.view:not(.grid) { padding: 16px 24px; }

/* ---------------- source badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--green); border-color: rgba(61, 220, 151, .4); background: rgba(61, 220, 151, .08); }
.badge.single { color: var(--muted); }
.badge.off { color: var(--amber); border-color: rgba(255, 176, 32, .4); }
.tier { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; border: 1px solid; }
.tier.official { color: var(--amber); border-color: rgba(255, 176, 32, .45); }
.tier.intl { color: var(--blue); border-color: rgba(77, 163, 255, .45); }
.tier.regional { color: var(--violet); border-color: rgba(167, 139, 250, .45); }
.srclist { display: flex; flex-wrap: wrap; gap: 4px; }
.srclist a { text-decoration: none; }
.conf { display: inline-block; width: 46px; height: 5px; border-radius: 3px; background: #151c30; position: relative; overflow: hidden; vertical-align: middle; }
.conf i { position: absolute; inset-block: 0; right: 0; background: var(--green); }

/* ---------------- toolbar + cards */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar input[type=text], .toolbar input[type=date], .toolbar select {
  background: var(--bg2); border: 1px solid var(--line2); color: var(--text); border-radius: 8px; padding: 7px 10px;
  font-family: inherit; font-size: 13px; color-scheme: dark;
}
.toolbar input[type=search] { flex: 1 1 220px; }
.tg { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.tg input[type=checkbox] { accent-color: var(--amber); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 10px; }
.card { background: rgba(20, 27, 46, .55); border: 1px solid var(--line); border-inline-start: 3px solid var(--line2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; }
.card .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.card h4 { margin: 0; font-size: 14px; line-height: 1.6; font-weight: 500; }
.card h4 a { color: var(--text); text-decoration: none; }
.card h4 a:hover { color: var(--amber); }
.card p { margin: 0; font-size: 12px; color: #aeb6c8; line-height: 1.7; }
.card .places { font-size: 11px; color: var(--muted); }
.more { display: flex; justify-content: center; margin-top: 14px; }
.empty-msg { color: var(--muted); padding: 30px; text-align: center; grid-column: 1 / -1; }

/* ---------------- sources page */
.method { background: rgba(20, 27, 46, .5); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin-bottom: 14px; }
.method h3 { margin: 0 0 6px; font-size: 14px; }
.method ul { margin: 0; padding-inline-start: 18px; font-size: 13px; line-height: 2; color: #c3c9d9; }
.srcs { width: 100%; border-collapse: collapse; font-size: 13px; }
.srcs th { text-align: right; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--line2); }
.srcs td { padding: 8px; border-bottom: 1px dashed var(--line); }
.srcs td a { color: var(--text); text-decoration: none; }
.srcs td a:hover { color: var(--amber); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; }

/* ---------------- responsive */
@media (max-width: 1300px) {
  .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: span 2; }
}
@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 12px 0; }
  .tabs { padding: 8px 12px 0; }
  main.view:not(.grid) { padding: 12px; }
  .cards { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; padding: 12px; }
  .span2 { grid-column: span 1; }
  .top { padding: 12px; }
  .graph-wrap { height: 360px; }
  .detail { width: calc(100% - 20px); }
}
