:root {
  --bg: #0b1220;
  --bg-soft: #0f1a2e;
  --panel: #122036;
  --panel-2: #16263f;
  --border: #22334f;
  --text: #e6edf6;
  --muted: #8ba0bd;
  --accent: #2f6fed;
  --accent-2: #16b8a6;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #eab308;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Shared ---------- */
.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-size: 24px;
  box-shadow: 0 6px 18px rgba(47, 111, 237, .35);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .15s ease, background .15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2154c4);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(47, 111, 237, .3);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(47, 111, 237, .45); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--panel-2); }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 1rem; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: .9rem;
  margin-bottom: 16px;
}
.alert-error { background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .4); color: #fca5a5; }
.alert-success { background: rgba(34, 197, 94, .12); border: 1px solid rgba(34, 197, 94, .4); color: #86efac; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input,
.field select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .92rem;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus,
.field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 237, .2); }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(47, 111, 237, .25), transparent 60%),
    radial-gradient(700px 420px at 95% 5%, rgba(22, 184, 166, .18), transparent 55%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 26px; }
.brand .brand-badge { margin: 0 auto 14px; width: 60px; height: 60px; font-size: 30px; border-radius: 16px; }
.brand h1 { margin: 0; font-size: 1.8rem; letter-spacing: -.02em; }
.brand p { margin: 6px 0 0; color: var(--muted); font-size: .92rem; }
.login-form { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Dashboard ---------- */
.dash-body { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(11, 18, 32, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row h1 { margin: 0; font-size: 1.25rem; }
.brand-row p { margin: 2px 0 0; color: var(--muted); font-size: .78rem; }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta strong { font-size: .86rem; }
.user-meta span { color: var(--muted); font-size: .74rem; }

.dash-main { padding: 20px 22px 40px; max-width: 1560px; margin: 0 auto; }

.filters-bar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.filters-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 14px;
  align-items: end;
}
.filters-actions { display: flex; gap: 8px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 22px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.stat-value { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.stat-label { color: var(--muted); font-size: .82rem; }

.filter-note {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 18px;
  background: rgba(234, 179, 8, .1);
  border: 1px solid rgba(234, 179, 8, .3);
  color: #fde68a;
  font-size: .88rem;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.map-panel { grid-column: span 2; grid-row: span 2; }
.table-panel { grid-column: 1 / -1; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.panel-head h2 { margin: 0; font-size: 1rem; }
.count-pill {
  margin-left: 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  padding: 2px 9px;
  font-size: .72rem;
  font-weight: 700;
}
.seg { display: flex; background: var(--bg-soft); border-radius: 9px; padding: 3px; }
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
}
.seg-btn.active { background: var(--accent); color: #fff; }

#map { height: 620px; width: 100%; background: #0d1524; z-index: 0; }
.chart-wrap { padding: 14px; height: 300px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

.table-panel .panel-head { flex-wrap: wrap; }
.table-search {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: .86rem;
  outline: none;
  min-width: 240px;
}
.table-scroll { max-height: 520px; overflow: auto; }
.incident-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.incident-table th, .incident-table td { padding: 11px 14px; text-align: left; white-space: nowrap; }
.incident-table th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.incident-table tbody tr { border-bottom: 1px solid rgba(34, 51, 79, .5); }
.incident-table tbody tr:hover { background: var(--panel-2); }
.incident-table .details-cell {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.type-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .76rem;
  font-weight: 600;
  color: #0b1220;
  background: var(--chip);
}
.empty-row { text-align: center; color: var(--muted); padding: 28px !important; }

.dash-footer {
  margin-top: 22px;
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
}

/* Leaflet overrides to fit dark theme */
.leaflet-container { background: #0d1524; font-family: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-content strong { color: var(--accent-2); }
.leaflet-popup-content p { margin: 4px 0; }
.leaflet-control-zoom a { background: var(--panel-2) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-attribution { background: rgba(11, 18, 32, .8) !important; color: var(--muted) !important; font-size: .68rem !important; }

/* Incident circle marker popup */
.inc-cursor { cursor: pointer; }

@media (max-width: 1100px) {
  .filters-form { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .map-panel { grid-column: 1 / -1; grid-row: auto; }
}
@media (max-width: 640px) {
  .filters-form { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-user { width: 100%; justify-content: space-between; }
  .incident-table td { white-space: normal; }
}