/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d1117;       /* Substack deep navy background */
  --surface:    #161b22;       /* Slightly lighter panel surface */
  --surface-2:  #1c2333;       /* Hover / toolbar tint */
  --border:     #2a3142;       /* Subtle border */
  --text:       #e6edf3;       /* Primary off-white text */
  --text-muted: #8b949e;       /* Secondary grey text */
  --accent:     #e8622a;       /* Substack burnt orange */
  --accent-dim: rgba(232,98,42,.15);
  --header-h:   52px;
  --font-ui:    'DM Mono', 'Courier New', monospace;
  --font-body:  'DM Sans', system-ui, sans-serif;
  --radius:     4px;
  --shadow:     0 2px 12px rgba(0,0,0,.4);
}

/* ── Google Fonts ─────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600&display=swap');

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.app-header h1 {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text);
}

.header-sub {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

/* ── Country nav ─────────────────────────────────────────────────────────── */
.country-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  border-left: 1px solid var(--border);
  padding-left: 12px;
  margin-left: 0;
}

.country-nav-item {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 4px 10px;
  border-radius: calc(var(--radius) - 1px);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.country-nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.country-nav-item.active {
  background: var(--accent);
  color: #fff;
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-rows: 60vh 1fr;
  min-height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
}

@media (min-width: 900px) {
  .layout {
    grid-template-rows: 1fr;
    grid-template-columns: 1fr 8px 1fr;
    height: calc(100vh - var(--header-h));
  }
}

/* ── Map panel ───────────────────────────────────────────────────────────── */
.map-panel {
  display: flex;
  flex-direction: column;
  position: relative;
}

/* map-content fills all space below the layer switcher */
.map-content {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  min-height: 0;
}

/* ── Layer switcher ──────────────────────────────────────────────────────── */
.layer-switcher {
  flex-shrink: 0;
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  z-index: 10;
}

.layer-btn {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: calc(var(--radius) - 1px);
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}

.layer-btn input[type="radio"] { display: none; }

.layer-btn:hover { background: var(--surface-2); color: var(--text); }

.layer-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── MapLibre popup ──────────────────────────────────────────────────────── */
.maplibregl-popup-content {
  font-family: var(--font-body);
  font-size: 13px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  max-width: 240px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.maplibregl-popup-tip {
  border-top-color: var(--surface) !important;
  border-bottom-color: var(--surface) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
}

.maplibregl-popup-content strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin-bottom: 4px;
}

/* MapLibre nav controls */
.maplibregl-ctrl-group {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
}

.maplibregl-ctrl-group button {
  background-color: var(--surface) !important;
  color: var(--text) !important;
}

.maplibregl-ctrl-group button:hover {
  background-color: var(--surface-2) !important;
}

.maplibregl-ctrl-attrib {
  background: rgba(13,17,23,.8) !important;
  color: var(--text-muted) !important;
}

.maplibregl-ctrl-attrib a {
  color: var(--text-muted) !important;
}

.maplibregl-ctrl-scale {
  background: rgba(13,17,23,.7) !important;
  border-color: var(--text-muted) !important;
  color: var(--text-muted) !important;
}

/* ── Map legend ──────────────────────────────────────────────────────────── */
.map-legend {
  position: absolute;
  bottom: 32px;
  left: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  z-index: 10;
  min-width: 160px;
}

.legend-title {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.legend-row:last-child { margin-bottom: 0; }

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-label {
  font-family: var(--font-body);
  font-size: 11.5px;
  color: var(--text);
}


.divider {
  width: 8px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  transition: background .15s;
  z-index: 10;
  flex-shrink: 0;
}

.divider:hover,
.divider.dragging {
  background: var(--accent);
}

.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  border-radius: 1px;
  background: var(--text-muted);
  opacity: 0.5;
}


.table-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.table-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.table-count {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.table-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}

/* Dark scrollbar */
.table-scroll::-webkit-scrollbar { width: 6px; }
.table-scroll::-webkit-scrollbar-track { background: var(--surface); }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Table ───────────────────────────────────────────────────────────────── */
#incidentTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

#incidentTable thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

#incidentTable thead th:hover { color: var(--text); }

.sort-icon { opacity: .4; font-size: 9px; }

#incidentTable tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}

#incidentTable tbody tr:hover { background: var(--surface-2); }

#incidentTable tbody tr.active {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
}

#incidentTable tbody td {
  padding: 7px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* Per-column widths — date, type, location fixed; title expands; score sticky-right */
#incidentTable th:nth-child(1),
#incidentTable td:nth-child(1) { width: 110px; min-width: 110px; }
#incidentTable th:nth-child(2),
#incidentTable td:nth-child(2) { width: 140px; min-width: 140px; }
#incidentTable th:nth-child(3),
#incidentTable td:nth-child(3) { width: auto;  min-width: 180px; }
#incidentTable th:nth-child(4),
#incidentTable td:nth-child(4) { width: 180px; min-width: 140px; }
#incidentTable th:nth-child(5),
#incidentTable td:nth-child(5) {
  width: 72px; min-width: 72px;
  text-align: right;
  position: sticky;
  right: 0;
  background: var(--bg);
}
/* sticky header cell needs slightly higher z-index to sit above body cells */
#incidentTable thead th:nth-child(5) {
  z-index: 2;
}
/* hover/active rows: keep sticky cell consistent with row state */
#incidentTable tbody tr:hover td:nth-child(5) {
  background: var(--surface-2);
}
#incidentTable tbody tr.active td:nth-child(5) {
  background: var(--accent-dim);
}

.placeholder-row td {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 32px !important;
}

/* ── Type badge ──────────────────────────────────────────────────────────── */
.type-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 2px;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .05em;
  font-weight: 500;
  text-transform: uppercase;
  color: #fff;
}

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.table-toolbar {
  flex-wrap: wrap;
  gap: 8px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.filter-label {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 4px 8px;
  outline: none;
  transition: border-color .15s;
}

.filter-input:focus {
  border-color: var(--accent);
}

.filter-date  { width: 128px; }
.filter-select { width: 148px; cursor: pointer; }

.filter-search-group { margin-left: auto; }
.filter-search { width: 180px; }
.filter-search::placeholder { color: var(--text-muted); }

/* Style native date/select for dark theme */
.filter-input option { background: var(--surface); color: var(--text); }
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.6);
  cursor: pointer;
}

.filter-reset {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  padding: 3px 8px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  line-height: 1;
}

.filter-reset:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-disabled {
  opacity: 0.4;
  cursor: not-allowed !important;
}

/* ── Expandable rows ─────────────────────────────────────────────────────── */
.expand-row { display: none; }
.expand-row.open { display: table-row; }

.expand-row td {
  padding: 0 !important;
  border-bottom: 2px solid var(--accent) !important;
}

.expand-body {
  padding: 12px 16px 14px 16px;
  background: var(--surface-2);
  display: flex;
  gap: 24px;
}

.expand-section {
  flex: 1;
  min-width: 0;
}

.expand-section:first-child {
  flex: 2;
}

.expand-label {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.expand-text {
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.55;
  white-space: normal;
}

.expand-weapons {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.expand-none {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.expand-section--location {
  flex: 0 0 auto;
  min-width: 140px;
  max-width: 200px;
}

.expand-section--location .expand-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 2px;
}

.expand-section--location .expand-text:first-of-type {
  color: var(--text);
  font-size: 12.5px;
}

/* Source icon cell — aligns with the sticky Arms Score column */
.expand-source-cell {
  width: 72px;
  min-width: 72px;
  text-align: center;
  vertical-align: middle;
  position: sticky;
  right: 0;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
}

.expand-source-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  opacity: 0.75;
  transition: opacity .15s, color .15s;
}

.expand-source-icon:hover {
  opacity: 1;
  color: #fff;
}

.expand-source-text {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-ui);
}

/* ── Multi-select dropdown ───────────────────────────────────────────────── */
.ms-wrap {
  position: relative;
}

.ms-btn {
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpolyline points='1,1 5,5 9,1' fill='none' stroke='%238b949e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
}

.ms-btn.ms-active {
  border-color: var(--accent);
  color: var(--accent);
}

.ms-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 180px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px 0;
}

.ms-panel::-webkit-scrollbar { width: 5px; }
.ms-panel::-webkit-scrollbar-track { background: var(--surface); }
.ms-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.ms-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: background .1s, color .1s;
}

.ms-row:hover {
  background: var(--surface-2);
  color: var(--text);
}

.ms-row.ms-checked {
  color: var(--text);
}

.ms-all-row {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.ms-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.ms-check {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: border-color .1s, background .1s;
}

.ms-row.ms-checked .ms-check {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.ms-option-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
