:root {
  --bg: #1a1d21;
  --panel: #22262b;
  --cyan: #7aa2c4;
  --cyan-dim: rgba(122, 162, 196, 0.22);
  --red: #d16b6b;
  --red-dim: rgba(209, 107, 107, 0.22);
  --amber: #c4a35a;
  --green: #7d9e78;
  --text: #e6e8eb;
  --muted: #8b939c;
  --line: #2e343c;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: #1e2227;
  position: relative;
  z-index: 2000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 8px;
  display: block;
}

.brand-text { min-width: 0; }

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  white-space: nowrap;
}

.brand .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 20px;
}

.nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  border-color: var(--line);
}

.nav-link.on {
  background: var(--bg);
  color: var(--cyan);
  border-color: var(--line);
}

.status-cluster { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.pill {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
}

.pill:hover {
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

.pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
}

.pill.live { color: #9db89a; border-color: #3a4a3a; }
.pill.live .dot { background: #7d9e78; }
.pill.down { color: var(--red); border-color: var(--red-dim); }
.pill.down .dot { background: var(--red); }
.pill.dim { color: var(--amber); }

.pill.toggle.on {
  color: #9db89a;
  border-color: #3a4a3a;
}

.clock {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  min-width: 88px;
  text-align: right;
}

/* ================= APP MENU (HAMBURGER) ================= */
.app-menu { display: none; position: relative; }
.app-menu-btn {
  cursor: pointer;
  list-style: none;
  padding: 6px 8px;
}
.app-menu-btn::-webkit-details-marker,
.app-menu-btn::marker { display: none; content: ""; }
.app-menu-btn svg { display: block; }
.app-menu[open] .app-menu-btn {
  color: var(--text);
  border-color: var(--line);
}
.app-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 168px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #1e2227;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 2500;
}
.app-menu-link {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--muted);
  text-decoration: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  cursor: pointer;
}
.app-menu-link:hover { color: var(--text); }
.app-menu-link.on {
  color: var(--text);
  border-color: var(--line);
  background: var(--bg);
}
.app-menu-out { color: var(--red); }
.app-menu-out:hover { color: var(--red); }

/* ================= LAYOUT ================= */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: minmax(0, 1fr);
}

.map-wrap {
  position: relative;
  z-index: 0;
  isolation: isolate;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--line);
}

#map { height: 100%; width: 100%; background: #2a2e33; }
.leaflet-container { background: #2a2e33 !important; font-family: var(--sans); }
.leaflet-control-attribution {
  background: rgba(30, 34, 39, 0.85) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}

.map-hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.hud-item {
  background: rgba(30, 34, 39, 0.9);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 10px;
  min-width: 86px;
}

.hud-item .k { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.hud-item span:last-child { color: var(--text); font-size: 13px; font-family: var(--mono); }

.leaflet-tooltip.map-tooltip {
  background: #1e2227;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  padding: 6px 8px;
  box-shadow: none;
}

.leaflet-tooltip.map-tooltip::before {
  border-top-color: #1e2227;
}

/* ================= FEED ================= */
.feed-wrap {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.feed-head {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.feed-head h2 { font-size: 13px; font-weight: 600; color: var(--text); }
.live-tag { font-size: 11px; color: var(--muted); }

.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 8px;
}

.feed::-webkit-scrollbar { width: 8px; }
.feed::-webkit-scrollbar-thumb { background: #3a4149; border-radius: 4px; }

.row {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  font-size: 12.5px;
  line-height: 1.45;
  transition: background 0.15s ease;
}

.row.ban { background: rgba(209, 107, 107, 0.08); }
.row:hover { background: rgba(255, 255, 255, 0.02); }
.row .meta { color: var(--muted); }
.row .ip { font-family: var(--mono); color: var(--text); font-weight: 500; }

.geo-ext {
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  color: var(--muted);
  text-decoration: none;
  vertical-align: -1px;
  transition: color 0.15s ease;
}
.geo-ext:hover,
.geo-ext:focus-visible {
  color: var(--cyan);
}
.geo-ext-icon { display: block; }

.row .tag {
  display: inline-block;
  margin-top: 5px;
  padding: 1px 7px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 3px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.row .tag.ban { color: var(--red); border-color: var(--red-dim); }
.row .tag.ign { color: var(--cyan); }

.feed-method {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 4px;
}

.method-GET { background: rgba(122, 162, 196, 0.2); color: var(--cyan); }
.method-POST { background: rgba(125, 158, 120, 0.2); color: var(--green); }
.method-PUT, .method-PATCH { background: rgba(196, 163, 90, 0.2); color: var(--amber); }
.method-DELETE { background: rgba(209, 107, 107, 0.2); color: var(--red); }

/* ================= STATSBAR ================= */
.statsbar {
  height: 64px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--line);
  background: #1e2227;
}

.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 16px;
  border-right: 1px solid var(--line);
}

.stat:last-child { border-right: none; }
.stat .n { font-family: var(--mono); font-size: 18px; color: var(--text); font-weight: 500; }
.stat .l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.alert .n { color: var(--red); }
.stat.success .n { color: #9db89a; }
.stat.warn .n { color: var(--amber); }
.stat.highlight .n { color: var(--cyan); }

/* ================= LEAFLET RADAR / HQ / SHOT ================= */
.leaflet-div-icon.radar-icon,
.leaflet-div-icon.hq-icon,
.leaflet-div-icon.shot-icon {
  background: none;
  border: none;
  overflow: visible;
}

.hq-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px #fff, 0 0 24px var(--cyan);
}

.radar {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: relative;
}

.radar-2xx {
  background: #7aa2c4;
  box-shadow: 0 0 0 1px rgba(122, 162, 196, 0.45);
}
.radar-2xx::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 1.5px solid rgba(122, 162, 196, 0.7);
  border-radius: 50%;
  animation: ping 1.8s ease-out infinite;
}

.radar-4xx, .radar-3xx {
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(196, 163, 90, 0.5);
}
.radar-4xx::after, .radar-3xx::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 1.5px solid rgba(196, 163, 90, 0.75);
  border-radius: 50%;
  animation: ping 1.8s ease-out infinite;
}

.radar-threat {
  background: var(--red);
  box-shadow: 0 0 0 1px rgba(209, 107, 107, 0.5);
}
.radar-threat::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 1.5px solid rgba(209, 107, 107, 0.85);
  border-radius: 50%;
  animation: ping 1.2s ease-out infinite;
}

.radar.shot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}
.shot-2xx { background: #fff; box-shadow: 0 0 6px #fff, 0 0 10px #7aa2c4; }
.shot-3xx, .shot-4xx { background: #fff; box-shadow: 0 0 6px #fff, 0 0 10px var(--amber); }
.shot-threat { background: #fff; box-shadow: 0 0 6px #fff, 0 0 10px var(--red); }

@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ================= TABLES & EXPLORER (AUTH-ATTACK DESIGN) ================= */
body.page-table {
  overflow: hidden;
  height: 100%;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 12px;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
}

.table-toolbar .lede {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.table-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

.table-meta select, .select-filter {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font: inherit;
  font-size: 13px;
  outline: none;
}

.table-meta select:focus, .select-filter:focus, .input-search:focus {
  border-color: var(--cyan);
}

.input-search {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  min-width: 260px;
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

/* ================= THREATS SPECIFIC LAYOUT & TABLE ================= */
.threats-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px 12px;
  overflow: hidden;
}

.threats-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
}

.threats-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  flex: 1;
}

table.threats-table th,
table.threats-table td {
  font-size: 11px;
  padding: 8px 8px;
}

table.threats-table .path-cell {
  max-width: 240px;
  white-space: normal;
  word-break: break-all;
  line-height: 1.3;
  font-family: var(--mono);
  color: #ff6b81;
}

table.threats-table .ua-cell {
  max-width: 200px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
  font-size: 10.5px;
  color: var(--muted);
}

table.threats-table .threat-type-cell {
  max-width: 140px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.25;
}

@media (max-width: 960px) {
  .threats-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

table.attackers, table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.attackers th, table.data-table th,
table.attackers td, table.data-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.attackers th, table.data-table th {
  position: sticky;
  top: 0;
  background: #1e2227;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  z-index: 5;
}

table.attackers .mono, table.data-table .mono { font-family: var(--mono); }
table.attackers .ip-cell, table.data-table .ip-cell { white-space: nowrap; }
table.attackers .num, table.data-table .num { font-family: var(--mono); text-align: right; }
table.attackers .meta, table.data-table .meta { color: var(--muted); }
table.attackers .empty, table.data-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  white-space: normal;
}

table.attackers tr:hover td, table.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

table.attackers tr.threat-row td, table.data-table tr.threat-row td {
  background: rgba(209, 107, 107, 0.06);
}

.pill-icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  flex-shrink: 0;
}

.pager #page-label, .pager .pagination-info {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

.pager .pill:disabled, .pager .pill[disabled],
.pill:disabled, .pill[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ================= MODAL ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-panel {
  width: 90%;
  max-width: 620px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-row .k {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-row .v {
  font-family: var(--mono);
  background: var(--bg);
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid var(--line);
  word-break: break-all;
}

/* ================= SCORE BADGES & METERS ================= */
.score-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 95px;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
  width: fit-content;
}

.score-badge.score-zero {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
}

.score-badge.score-safe {
  color: var(--cyan);
  background: rgba(122, 162, 196, 0.15);
  border-color: rgba(122, 162, 196, 0.3);
}

.score-badge.score-warn {
  color: var(--amber);
  background: rgba(196, 163, 90, 0.18);
  border-color: rgba(196, 163, 90, 0.4);
}

.score-badge.score-danger {
  color: #ff6b81;
  background: rgba(255, 107, 129, 0.2);
  border-color: rgba(255, 107, 129, 0.5);
}

.score-badge.score-ban {
  color: #fff;
  background: var(--red);
  border-color: rgba(255, 255, 255, 0.3);
}

.score-meter-wrap {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.score-meter-fill.meter-safe { background: var(--cyan); }
.score-meter-fill.meter-warn { background: var(--amber); }
.score-meter-fill.meter-danger { background: #ff6b81; }
.score-meter-fill.meter-ban { background: var(--red); }

/* ================= RESPONSIVE MOBILE STYLES ================= */
@media (max-width: 768px) {
  .topbar {
    height: 52px;
    padding: 0 10px;
    gap: 8px;
  }
  .brand-mark { width: 28px; height: 28px; border-radius: 6px; }
  .brand h1 { font-size: 15px; }
  .brand .sub { display: none; } /* Hide second title line on mobile */

  .nav,
  .status-cluster > .logout-bar {
    display: none;
  }
  .app-menu { display: block; }

  .clock {
    min-width: 0;
    font-size: 12px;
  }
  .status-cluster { gap: 6px; }

  .conn-pill {
    padding: 6px;
    min-width: 28px;
    justify-content: center;
  }
  .conn-pill .pill-text { display: none; }
  .pill.toggle { padding: 4px 7px; font-size: 11px; }

  /* Map View */
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 52%) minmax(0, 48%);
  }
  .map-wrap {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .map-hud {
    display: none; /* Hide overlay cards on mobile map */
  }
  .feed-head {
    display: none; /* Remove redundant Activity/Live header on mobile */
  }
  .feed-wrap {
    border-top: 3px solid var(--line);
  }
  .statsbar {
    height: auto;
    min-height: 48px;
    grid-template-columns: repeat(4, 1fr) !important;
  }
  .stat {
    padding: 5px 4px;
    border-bottom: 1px solid var(--line);
    text-align: center;
    align-items: center;
  }
  .stat .n { font-size: 14px; }
  .stat .l { font-size: 10px; margin-top: 1px; }

  /* Explorer View */
  .table-wrap {
    padding: 10px 10px 8px;
  }
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .table-filters {
    gap: 6px;
  }
  .input-search {
    min-width: 130px;
    flex: 1;
  }

  /* Threats View */
  .threats-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 10px 10px 8px;
    gap: 8px;
  }
  .threats-sidebar {
    max-height: 180px;
    gap: 8px;
    overflow-y: auto;
  }
  .threats-sidebar > div {
    padding: 10px 12px !important;
  }
  .threats-main .table-toolbar {
    margin-bottom: 6px;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .threats-main .table-toolbar .lede {
    display: none; /* Hide redundant "Malicious Payloads & Probe Timeline" in mobile */
  }

  /* Mobile threats table: focus on critical columns, hide raw user agent */
  table.threats-table .ua-cell,
  table.threats-table th:last-child {
    display: none;
  }
  table.threats-table .path-cell {
    max-width: 160px;
  }
}
