:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-2: #182338;
  --border: #243049;
  --text: #e8eef9;
  --muted: #8b9bb8;
  --live: #22c55e;
  --paused: #1e3a5f;
  --off: #3f4555;
  --accent: #0ea5e9;
  --accent-2: #0284c7;
  --warn-bg: #422006;
  --warn-text: #fde68a;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input { font: inherit; }
.hidden { display: none !important; }

.app { max-width: 1280px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.brand { display: flex; gap: 0.85rem; align-items: center; }
.logo {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #0369a1);
  display: grid; place-items: center; font-weight: 800; letter-spacing: 0.04em;
}
.brand h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.subtitle { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.85rem; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 8px; padding: 0.45rem 0.85rem; cursor: pointer;
}
.btn:hover { border-color: #3b4d6e; }
.btn.primary { background: var(--accent); border-color: var(--accent-2); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.banner {
  padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 0.65rem; font-size: 0.9rem;
}
.banner.warning { background: var(--warn-bg); color: var(--warn-text); border: 1px solid #a16207; }
.banner.danger { background: #450a0a; color: #fecaca; border: 1px solid #b91c1c; }
.banner.info { background: #0c1a2e; color: #93c5fd; border: 1px solid #1e3a5f; }
.banner code { font-size: 0.85em; background: rgba(0,0,0,0.25); padding: 0.1rem 0.35rem; border-radius: 4px; }

.hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; margin-bottom: 1.5rem;
}
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }

.map-panel, .slider-panel, .markets {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.map-panel { overflow: hidden; position: relative; }
#map {
  height: 400px; width: 100%; min-height: 320px;
  background: #dbe4f0; /* visible even before tiles load */
  z-index: 0;
}
/* Leaflet panes must sit above the empty background */
#map .leaflet-pane { z-index: auto; }
#map .leaflet-overlay-pane { z-index: 400; }
#map .leaflet-marker-pane { z-index: 500; }
#map .leaflet-tooltip-pane { z-index: 650; }
#map .leaflet-popup-pane { z-index: 700; }
.map-legend {
  display: flex; gap: 1rem; flex-wrap: wrap; padding: 0.65rem 1rem; font-size: 0.8rem; color: var(--muted);
  border-top: 1px solid var(--border);
}
.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.35rem;
}
.dot.live { background: var(--live); box-shadow: 0 0 8px var(--live); }
.dot.paused { background: #2563eb; }
.dot.waiting { background: #a78bfa; }
.live-label { color: var(--live); font-weight: 700; }
.hist-label { color: #fbbf24; font-weight: 700; }
.status-chip.waiting { background: #2e1065; color: #ddd6fe; border-color: #6d28d9; }
.dot.off { background: #6b7280; }

.slider-panel { padding: 1rem 1.1rem; }
.slider-head { display: flex; justify-content: space-between; align-items: center; min-height: 2rem; }
.slider-head h2 { margin: 0; font-size: 1rem; }
#timeSlider { width: 100%; margin: 1rem 0 0.5rem; accent-color: var(--accent); }
.slider-meta {
  display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; color: var(--muted);
}
.stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-top: 1rem;
}
@media (max-width: 600px) { .stats-row { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--panel-2); border-radius: 8px; padding: 0.55rem 0.65rem; border: 1px solid var(--border);
}
.stat label { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat strong { font-size: 1.05rem; }

.markets { padding: 1rem 1.1rem 1.25rem; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 1.05rem; }
.tl-legend {
  display: flex; gap: 0.85rem; align-items: center; flex-wrap: wrap;
  font-size: 0.78rem; color: var(--muted);
}
.muted { color: var(--muted); font-size: 0.88rem; margin: 0; }
.market-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.65rem; }

.market-card {
  border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); overflow: hidden;
}
.market-card summary {
  list-style: none; cursor: pointer; padding: 0.85rem 1rem 0.75rem;
  display: block;
}
.market-card summary::-webkit-details-marker { display: none; }
.market-summary-row {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.55rem;
}
.status-chip {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem; border-radius: 6px;
}
.status-chip.live { background: rgba(34,197,94,0.15); color: var(--live); }
.status-chip.paused { background: rgba(37,99,235,0.15); color: #60a5fa; }
.status-chip.not_monitored { background: rgba(107,114,128,0.2); color: #9ca3af; }
.market-title { font-weight: 600; }
.market-body { padding: 0 1rem 1rem; border-top: 1px solid var(--border); }

.cluster {
  margin-top: 0.85rem; padding: 0.85rem 0.75rem 0.75rem; border-top: 1px dashed var(--border);
  border-radius: 10px;
}
.cluster:first-child { border-top: 0; padding-top: 0.65rem; margin-top: 0.35rem; }
.cluster.is-live {
  border-top: 0;
  margin-top: 0.65rem;
  background: linear-gradient(120deg, rgba(34, 197, 94, 0.28) 0%, rgba(22, 163, 74, 0.12) 45%, rgba(15, 40, 28, 0.35) 100%);
  border: 1px solid rgba(34, 197, 94, 0.35);
  box-shadow: inset 0 1px 0 rgba(187, 247, 208, 0.12);
}
.cluster-head {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.45rem;
}
.cluster-name { font-weight: 600; flex: 1; min-width: 8rem; }
.cluster-wx { font-size: 0.85rem; color: var(--muted); margin-left: auto; }
.rule-line { font-size: 0.82rem; color: var(--muted); margin: 0.45rem 0 0.75rem; }

/* 3-day live/paused timeline bars */
.tl-wrap { position: relative; }
.tl-bar {
  display: flex;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: #1a2233;
  border: 1px solid var(--border);
  gap: 1px;
}
.tl-seg {
  display: block;
  min-width: 3px;
  height: 100%;
  cursor: pointer;
  position: relative;
  transition: filter 0.12s ease, transform 0.12s ease;
}
.tl-seg:hover,
.tl-seg:focus-visible {
  filter: brightness(1.25);
  outline: none;
  z-index: 1;
  box-shadow: 0 0 0 2px rgba(232, 238, 249, 0.35);
}
.tl-seg.live {
  background: linear-gradient(90deg, #15803d, #22c55e 55%, #4ade80);
  box-shadow: inset 0 0 0 1px rgba(34,197,94,0.25);
}
.tl-seg.paused { background: linear-gradient(90deg, #1e3a8a, #2563eb 55%, #60a5fa); }
.tl-seg.waiting { background: #7c3aed; }
.tl-seg.empty { background: #2a3348; cursor: default; }
.tl-axis {
  display: flex; justify-content: space-between;
  font-size: 0.68rem; color: var(--muted); margin-top: 0.25rem;
  letter-spacing: 0.02em;
  pointer-events: none;
}
.tl-tooltip {
  position: fixed;
  z-index: 2000;
  max-width: min(320px, calc(100vw - 16px));
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: #0a101c;
  color: var(--text);
  border: 1px solid #3b4d6e;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: pre-line;
  pointer-events: none;
}

/* ——— X feed carousel ad (matches in-app promoted carousel layout) ——— */
.x-ad {
  margin-top: 0.5rem;
  max-width: 420px;
  background: #fff;
  color: #0f1419;
  border: 1px solid #eff3f4;
  border-radius: 16px;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  box-shadow: 0 2px 12px rgba(15, 20, 25, 0.08);
}
.x-ad-header {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem 0.35rem;
}
.x-avatar {
  width: 40px; height: 40px; border-radius: 999px;
  background: #b8e0f5;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
  border: 1px solid #d0e8f5;
}
.x-ad-identity { flex: 1; min-width: 0; }
.x-ad-name-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.35rem;
  font-size: 0.92rem; line-height: 1.25;
}
.x-ad-name { font-weight: 700; color: #0f1419; }
.x-verified {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px; border-radius: 999px;
  background: #1d9bf0; color: #fff; font-size: 0.55rem; font-weight: 800;
}
.x-ad-handle, .x-ad-dot, .x-ad-label { color: #536471; font-weight: 400; font-size: 0.9rem; }
.x-ad-label { font-weight: 400; }
.x-ad-more {
  border: 0; background: transparent; color: #536471;
  font-size: 1rem; letter-spacing: 0.05em; cursor: default; padding: 0 0.15rem;
  line-height: 1;
}
.x-ad-body { padding: 0 0.9rem 0.55rem 3.55rem; }
.x-ad-copy {
  margin: 0 0 0.4rem; font-size: 0.95rem; line-height: 1.35; color: #0f1419;
}
.x-ad-tags { margin: 0; font-size: 0.95rem; line-height: 1.35; }
.x-hashtag { color: #1d9bf0; margin-right: 0.25rem; }

.x-media-block {
  margin: 0 0 0 3.55rem;
  padding-right: 0;
  position: relative;
}
.x-carousel {
  position: relative;
  padding-right: 0;
}
.x-track-wrap {
  overflow: hidden;
  border-radius: 16px 0 0 0;
  cursor: grab;
  touch-action: pan-y;
  /* clip right edge like X so next card peeks past the post column */
  margin-right: -1px;
}
.x-track-wrap:active { cursor: grabbing; }
.x-track {
  display: flex;
  gap: 2px;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  padding-right: 14%;
}
.x-slide {
  flex: 0 0 86%;
  min-width: 86%;
  max-width: 86%;
}
.x-card {
  display: block;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  background: #eff3f4;
}
.x-card-media {
  aspect-ratio: 1 / 1;
  background: #cfd9de;
  overflow: hidden;
  border: 1px solid #cfd9de;
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
}
.x-slide:not(.is-active) .x-card-media {
  border-radius: 16px;
  border-bottom: 1px solid #cfd9de;
}
.x-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
  background: linear-gradient(145deg, #e8eef5, #f3d5d8);
}
.x-card-media img.is-broken { opacity: 0.35; }
/* Per-slide meta is used as data source; website card under carousel is the X UI */
.x-card-meta { display: none; }

.x-nav {
  position: absolute;
  top: 42%;
  transform: translateY(-50%);
  z-index: 3;
  width: 34px; height: 34px; border-radius: 999px;
  border: 0;
  background: rgba(15, 20, 25, 0.72);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.x-nav:disabled { opacity: 0; pointer-events: none; }
.x-nav-prev { left: 10px; }
.x-nav-next { right: calc(14% + 10px); }
.x-nav:not(:disabled):hover { background: rgba(15, 20, 25, 0.9); }

.x-website-card {
  display: block;
  width: 86%;
  box-sizing: border-box;
  padding: 0.65rem 0.8rem 0.7rem;
  border: 1px solid #cfd9de;
  border-top: 1px solid #eff3f4;
  border-radius: 0 0 16px 16px;
  text-decoration: none;
  color: inherit;
  background: #f7f9f9;
}
.x-website-domain {
  font-size: 0.82rem;
  color: #536471;
  margin-bottom: 0.15rem;
  text-transform: lowercase;
}
.x-website-headline {
  font-size: 0.95rem;
  font-weight: 700;
  color: #0f1419;
  line-height: 1.25;
  margin-bottom: 0.1rem;
}
.x-website-desc {
  font-size: 0.88rem;
  color: #536471;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.x-ad-engage {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1.1rem 0.9rem 3.55rem;
  color: #536471;
  max-width: 100%;
  border-top: 0;
}
.x-eng {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
}
.x-eng svg { opacity: 0.9; }

@media (max-width: 520px) {
  .x-ad { max-width: 100%; }
  .x-ad-body,
  .x-media-block,
  .x-ad-engage {
    margin-left: 0.9rem;
  }
  .x-ad-body { padding: 0 0.9rem 0.55rem 0; }
  .x-ad-engage { padding: 0.65rem 0.9rem 0.85rem 0; }
  .x-nav-next { right: calc(14% + 6px); }
}

/* AIsle-style site footer */
.site-footer {
  margin-top: 3rem;
  border-top: 1px solid var(--border);
  background: transparent;
}
.site-footer-inner {
  max-width: 56rem;
  margin: 0 auto;
  padding: 2.5rem 0.25rem 1.5rem;
}
.site-footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.25rem;
}
@media (min-width: 768px) {
  .site-footer-grid { grid-template-columns: repeat(3, 1fr); gap: 2.5rem; }
}
.site-footer-heading {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}
.site-footer-x {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}
.site-footer-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  opacity: 0.9;
}
.site-footer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.site-footer-list a,
.site-footer-bottom a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.15s ease;
}
.site-footer-list a:hover,
.site-footer-bottom a:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.site-footer-copy {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--muted);
}
.site-footer-bottom {
  margin-top: 2.25rem;
  padding-top: 1.35rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.site-footer-bottom p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Settings drawer */
.drawer { position: fixed; inset: 0; z-index: 1000; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(400px, 100%);
  background: var(--panel); border-left: 1px solid var(--border); padding: 1.25rem;
  box-shadow: -12px 0 40px rgba(0,0,0,0.35); overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0; font-size: 1.1rem; }
#settingsForm label {
  display: block; margin: 1.1rem 0 0.35rem; font-size: 0.9rem; font-weight: 600;
}
#settingsForm input[type="range"] { width: 100%; accent-color: var(--accent); }
#settingsForm input[type="number"] {
  width: 100%; margin-top: 0.35rem; padding: 0.5rem 0.65rem;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.hint { font-size: 0.8rem; color: var(--muted); margin: 0.75rem 0 0; }
.drawer-actions { margin-top: 1.25rem; }
.msg { font-size: 0.85rem; margin-top: 0.75rem; min-height: 1.2em; }
.msg.ok { color: var(--live); }
.msg.err { color: #f87171; }

/* Leaflet dark tweaks */
.leaflet-container { background: #0a101c; font: inherit; }
.leaflet-control-attribution { font-size: 10px !important; }