:root {
  --bg: #050d16;
  --bg-deep: #030911;
  --panel: #091725;
  --panel-elevated: #0c1d2d;
  --panel2: #102536;
  --panel3: #132a3d;

  --text: #eef7ff;
  --text-soft: #c7d9e6;
  --muted: #829caf;
  --muted-2: #60798b;

  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.14);

  --cyan: #42d7ff;
  --blue: #4f9fff;
  --green: #43d487;
  --yellow: #ffd458;
  --orange: #ff9b52;
  --red: #ff5f66;
  --purple: #c786ff;

  --normal: #43d487;
  --watch: #ffd458;
  --warning: #ff9b52;
  --severe: #ff5f66;
  --critical: #cf6cff;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 17px;
  --radius-xl: 22px;

  --shadow-panel:
    0 16px 40px rgba(0, 0, 0, 0.18);

  --transition:
    160ms ease;
}

/* =========================================================
   BASE
   ========================================================= */

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color-scheme: dark;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(
      circle at 60% -20%,
      rgba(41, 111, 155, 0.12),
      transparent 42%
    ),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid rgba(66, 215, 255, 0.7);
  outline-offset: 2px;
}

/* =========================================================
   HEADER
   ========================================================= */

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding:
    13px
    clamp(16px, 4vw, 56px);

  border-bottom: 1px solid var(--line);

  background:
    linear-gradient(
      180deg,
      rgba(7, 20, 32, 0.97),
      rgba(5, 14, 24, 0.96)
    );

  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  position: relative;
  z-index: 1200;
}

.brand {
  color: inherit;
  text-decoration: none;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;

  display: grid;
  place-items: center;

  width: 42px;
  height: 42px;

  border: 1px solid rgba(66, 215, 255, 0.38);
  border-radius: 11px;

  background:
    linear-gradient(
      145deg,
      rgba(66, 215, 255, 0.11),
      rgba(79, 159, 255, 0.03)
    );

  color: var(--cyan);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.05em;
}

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.live-pill {
  flex: 0 0 auto;

  display: flex;
  align-items: center;
  gap: 8px;

  min-height: 34px;
  padding: 0 12px;

  border: 1px solid rgba(67, 212, 135, 0.16);
  border-radius: 999px;

  background: rgba(67, 212, 135, 0.055);

  color: #cfe8da;
  font-size: 11px;
  font-weight: 650;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);

  box-shadow:
    0 0 0 0 rgba(67, 212, 135, 0.5);

  animation: pulse 2s infinite;
}

@keyframes pulse {
  70% {
    box-shadow:
      0 0 0 8px rgba(67, 212, 135, 0);
  }

  100% {
    box-shadow:
      0 0 0 0 rgba(67, 212, 135, 0);
  }
}

/* =========================================================
   MAIN / HERO
   ========================================================= */

main {
  padding:
    0
    clamp(14px, 3vw, 42px)
    42px;
}

.hero {
  display: grid;
  grid-template-columns:
    minmax(0, 1.35fr)
    minmax(320px, 0.65fr);

  gap: clamp(26px, 4vw, 56px);
  align-items: end;

  padding: 42px 0 30px;
}

.eyebrow {
  margin: 0;

  font-size: 10px;
  letter-spacing: 0.17em;
  color: var(--cyan);
  font-weight: 800;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 900px;

  font-size: clamp(34px, 4.5vw, 62px);
  font-weight: 780;
  letter-spacing: -0.045em;
  line-height: 0.99;

  margin: 9px 0 16px;
}

.hero h1 span {
  color: #a9c9db;
  font-weight: 650;
}

.hero p {
  max-width: 790px;

  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;

  margin: 0;
}

/* =========================================================
   SEARCH
   ========================================================= */

.search-box {
  position: relative;

  background:
    linear-gradient(
      180deg,
      rgba(13, 31, 47, 0.94),
      rgba(8, 23, 37, 0.96)
    );

  border: 1px solid var(--line);
  border-radius: var(--radius-lg);

  padding: 15px;

  box-shadow: var(--shadow-panel);
}

.search-box label {
  display: block;

  color: var(--muted);

  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;

  margin-bottom: 8px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  min-width: 0;
  flex: 1;

  min-height: 46px;

  background: #06131f;
  border: 1px solid var(--line-strong);
  border-radius: 10px;

  color: var(--text);

  padding: 0 13px;
  font-size: 15px;

  transition:
    border-color var(--transition),
    background var(--transition);
}

.search-row input:hover {
  border-color: rgba(66, 215, 255, 0.25);
}

.search-row input:focus {
  border-color: rgba(66, 215, 255, 0.55);
  background: #081723;
}

.search-row input::placeholder {
  color: #647e90;
}

.search-row button,
.timeline-card button {
  border: 0;
  border-radius: 10px;

  background:
    linear-gradient(
      135deg,
      #41d7ff,
      #62bfff
    );

  color: #04111a;

  font-size: 12px;
  font-weight: 850;

  padding: 0 18px;
  cursor: pointer;

  transition:
    transform var(--transition),
    filter var(--transition);
}

.search-row button:hover,
.timeline-card button:hover {
  filter: brightness(1.05);
}

.search-row button:active,
.timeline-card button:active {
  transform: translateY(1px);
}

.search-results {
  position: absolute;
  left: 15px;
  right: 15px;
  top: calc(100% - 2px);

  z-index: 2200;

  background: #091927;
  border: 1px solid var(--line-strong);
  border-radius: 12px;

  overflow: hidden;

  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.35);
}

.search-results button {
  display: block;

  width: 100%;
  min-height: 43px;

  border: 0;
  border-bottom: 1px solid var(--line);

  background: transparent;

  color: var(--text-soft);

  text-align: left;

  padding: 10px 13px;

  cursor: pointer;
}

.search-results button:last-child {
  border-bottom: 0;
}

.search-results button:hover {
  background: #102538;
  color: #ffffff;
}

/* =========================================================
   MAIN WORKSPACE
   ========================================================= */

/* =========================================================
   WORKSPACE — FIXED PROFESSIONAL DESKTOP VIEWPORT
   ========================================================= */

.workspace {
  display: grid;
  grid-template-columns:
    minmax(320px, 370px)
    minmax(0, 1fr);

  width: 100%;

  /*
   * Critical:
   * Both the intelligence panel and map now share one
   * controlled viewport height.
   */
  height: min(76vh, 820px);
  min-height: 650px;
  max-height: 820px;

  border: 1px solid var(--line);
  border-radius: var(--radius-xl);

  overflow: hidden;

  background: var(--panel);

  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.22);
}


/* =========================================================
   SIDE PANEL
   ========================================================= */

.side-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;

  padding: 22px;

  border-right: 1px solid var(--line);

  background:
    linear-gradient(
      180deg,
      rgba(10, 26, 40, 0.98),
      rgba(7, 20, 32, 0.99)
    );

  /*
   * Important:
   * Risk information scrolls independently instead of
   * stretching the whole map workspace.
   */
  overflow-y: auto;
  overflow-x: hidden;

  overscroll-behavior: contain;
}


/* =========================================================
   MAP SHELL — MATCH WORKSPACE HEIGHT
   ========================================================= */

.map-shell {
  position: relative;

  min-width: 0;
  min-height: 0;

  width: 100%;
  height: 100%;

  overflow: hidden;

  background: #040b12;
}


/* =========================================================
   LEAFLET MAP — FILL ENTIRE MAP SHELL
   ========================================================= */

.map-shell #map {
  position: absolute;

  inset: 0;

  width: 100%;
  height: 100%;

  min-height: 100%;

  background: #06111d;
}


/* =========================================================
   MAP TOOLBAR
   ========================================================= */

.map-toolbar {
  position: absolute;

  top: 14px;
  left: 54px;

  z-index: 900;

  display: flex;
  flex-wrap: wrap;

  gap: 6px;

  max-width: calc(100% - 230px);
}


/* =========================================================
   MAP STATUS
   ========================================================= */

.map-status {
  position: absolute;

  top: 58px;
  left: 14px;

  z-index: 900;

  display: flex;
  gap: 6px;
  flex-wrap: wrap;

  max-width: calc(100% - 28px);
}


/* =========================================================
   TIMELINE
   ========================================================= */

.timeline-card {
  position: absolute;

  left: 18px;
  right: 18px;
  bottom: 18px;

  z-index: 900;

  display: grid;

  grid-template-columns:
    minmax(150px, auto)
    auto
    minmax(160px, 1fr);

  align-items: center;

  gap: 14px;

  padding: 12px 14px;

  background:
    rgba(5, 16, 27, 0.94);

  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);

  border: 1px solid var(--line);
  border-radius: 13px;

  box-shadow:
    0 12px 34px rgba(0, 0, 0, 0.24);
}


/* =========================================================
   LEGEND
   ========================================================= */

.legend {
  position: absolute;

  right: 16px;
  top: 16px;

  z-index: 900;

  display: flex;
  flex-wrap: wrap;

  gap: 9px;

  max-width: calc(100% - 200px);

  padding: 8px 10px;

  background:
    rgba(5, 16, 27, 0.91);

  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  border: 1px solid var(--line);
  border-radius: 9px;

  color: var(--text-soft);

  font-size: 9px;
}


/* =========================================================
   LARGE DESKTOPS
   ========================================================= */

@media (min-width: 1500px) {

  .workspace {
    grid-template-columns:
      380px
      minmax(0, 1fr);

    height: min(78vh, 850px);
    max-height: 850px;
  }

}


/* =========================================================
   NORMAL LAPTOP
   ========================================================= */

@media (max-width: 1180px) {

  .workspace {
    grid-template-columns:
      330px
      minmax(0, 1fr);

    height: min(74vh, 760px);
    min-height: 620px;
  }

  .side-panel {
    padding: 18px;
  }

  .map-toolbar {
    max-width: calc(100% - 160px);
  }

}


/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 900px) {

  .hero {
    grid-template-columns: 1fr;
  }

  /*
   * On tablet/mobile the side panel and map stack naturally.
   * Do not preserve the desktop fixed-height viewport.
   */
  .workspace {
    display: block;

    height: auto;
    min-height: 0;
    max-height: none;

    overflow: visible;
  }

  .side-panel {
    height: auto;

    max-height: none;

    border-right: 0;
    border-bottom: 1px solid var(--line);

    overflow: visible;
  }

  .map-shell {
    height: 620px;
    min-height: 620px;
  }

  .map-shell #map {
    position: absolute;
    inset: 0;

    height: 100%;
    min-height: 100%;
  }

  .sources-section {
    grid-template-columns: 1fr;
  }

  .map-toolbar {
    max-width: calc(100% - 80px);
  }

}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 620px) {

  .topbar {
    min-height: 64px;

    padding:
      11px
      14px;

    align-items: center;
  }

  .brand small {
    display: none;
  }

  .brand strong {
    font-size: 13px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .live-pill {
    max-width: 146px;

    padding: 0 9px;

    font-size: 9px;
  }

  main {
    padding:
      0
      10px
      28px;
  }

  .hero {
    padding:
      28px
      2px
      22px;
  }

  .hero h1 {
    font-size: clamp(31px, 10vw, 45px);
  }

  .hero p {
    font-size: 12px;
  }

  .search-row {
    flex-direction: column;
  }

  .search-row button {
    min-height: 44px;
  }

  .workspace {
    border-radius: 15px;
  }

  .side-panel {
    padding: 18px;
  }

  .risk-score {
    padding: 20px 0;
  }

  .risk-ring {
    width: 88px;
    height: 88px;
  }

  /*
   * Map gets its own proper mobile viewport.
   */
  .map-shell {
    height: 560px;
    min-height: 560px;
  }

  .map-shell #map {
    position: absolute;

    inset: 0;

    width: 100%;
    height: 100%;
  }

  .map-toolbar {
    top: 12px;
    left: 12px;
    right: 12px;

    max-width: none;

    gap: 5px;
  }

  .layer-btn {
    min-height: 32px;

    padding:
      0
      9px;

    font-size: 9px;
  }

  /*
   * Move source/mode status below layer controls.
   */
  .map-status {
    top: 56px;
    left: 12px;
    right: 12px;

    max-width: none;
  }

  /*
   * Legend goes beneath the map-status area instead of
   * overlapping layer controls.
   */
  .legend {
    top: 94px;
    left: 12px;
    right: 12px;

    max-width: none;

    justify-content: flex-start;
  }

  .timeline-card {
    left: 10px;
    right: 10px;
    bottom: 10px;

    grid-template-columns:
      minmax(0, 1fr)
      auto;

    gap: 8px;

    padding: 10px;
  }

  .timeline-card input {
    grid-column: 1 / -1;
  }

  .source-grid {
    grid-template-columns: 1fr;
  }

  .sources-section {
    padding-top: 38px;
  }

  .risk-detail-grid {
    grid-template-columns:
      repeat(2, minmax(0, 1fr));
  }

  footer {
    flex-direction: column;
    align-items: flex-start;
  }

}


/* =========================================================
   VERY SMALL MOBILE
   ========================================================= */

@media (max-width: 380px) {

  .metrics {
    grid-template-columns:
      repeat(2, minmax(0, 1fr));
  }

  .risk-score {
    gap: 14px;
  }

  .risk-ring {
    width: 82px;
    height: 82px;
  }

  .risk-ring strong {
    font-size: 24px;
  }

  .risk-item {
    padding: 9px;
  }

  .risk-item-title {
    font-size: 10px;
  }

  .map-shell {
    height: 520px;
    min-height: 520px;
  }

}

/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}