:root {
  --bg: #f4f1eb;
  --ink: #17191f;
  --muted: #667085;
  --line: #ddd6ca;
  --panel: #fffdf8;
  --panel-soft: #faf7f0;
  --red: #b23b36;
  --blue: #235f89;
  --green: #3f7349;
  --gold: #aa7a21;
  --teal: #197271;
  --violet: #674c9b;
  --shadow: 0 18px 45px rgba(35, 32, 28, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #27231f 0, #27231f 260px, var(--bg) 260px);
  color: var(--ink);
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 36px clamp(18px, 4vw, 52px) 28px;
  color: #fffaf2;
}

.eyebrow {
  margin: 0 0 7px;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: #f0bf61;
  font-weight: 800;
}

h1, h2, p {
  margin: 0;
}

h1 {
  max-width: 900px;
  font-size: clamp(28px, 4.6vw, 58px);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: 0;
}

.dek {
  max-width: 820px;
  margin-top: 16px;
  color: #d9d2c5;
  font-size: clamp(14px, 1.4vw, 17px);
  line-height: 1.55;
}

.header-stat {
  color: #f0e7d9;
  font-size: 13px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  border-radius: 999px;
}

main {
  padding: 0 clamp(18px, 4vw, 52px) 48px;
}

.filters {
  position: sticky;
  top: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: minmax(190px, 1.4fr) repeat(7, minmax(130px, 1fr));
  gap: 12px;
  align-items: end;
  margin: 0 0 18px;
  padding: 16px;
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

label {
  display: grid;
  gap: 6px;
  color: #555c67;
  font-size: 12px;
  font-weight: 800;
}

input, select, button {
  min-height: 42px;
  border: 1px solid #d4cbbd;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 95, 137, 0.14);
}

button {
  cursor: pointer;
  font-weight: 800;
  background: #1f252c;
  color: white;
  border-color: #1f252c;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: #101419;
}

.floating-reset {
  position: fixed;
  right: clamp(16px, 3vw, 34px);
  bottom: clamp(16px, 3vw, 34px);
  z-index: 30;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 18px 38px rgba(178, 59, 54, 0.32);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpis article,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpis article {
  position: relative;
  overflow: hidden;
  padding: 18px;
  min-height: 116px;
}

.kpis article::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--blue);
}

.kpis article:nth-child(2)::before { background: var(--red); }
.kpis article:nth-child(3)::before { background: var(--gold); }
.kpis article:nth-child(4)::before { background: var(--green); }
.kpis article:nth-child(5)::before { background: var(--violet); }

.kpis article:hover,
.panel:hover {
  box-shadow: 0 20px 50px rgba(35, 32, 28, 0.13);
}

.kpis span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.kpis strong {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1;
  letter-spacing: 0;
}

.grid {
  display: grid;
  gap: 20px;
  margin-bottom: 20px;
  align-items: start;
}

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

.two {
  align-items: stretch;
}

.two .panel:first-child {
  grid-column: span 2;
}

.two .panel {
  height: 100%;
}

.three {
  grid-template-columns: repeat(3, 1fr);
}

.three:not(.compact),
.three.compact {
  align-items: stretch;
}

.three:not(.compact) .panel,
.three.compact .panel {
  height: 100%;
}

.map-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  align-items: stretch;
}

.map-grid .panel {
  height: 100%;
}

.panel {
  padding: 20px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 12px;
}

.panel p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.chart {
  width: 100%;
  height: 280px;
}

.chart.tall {
  height: 330px;
}

.compact .panel {
  padding: 16px 18px;
}

.compact .chart {
  height: 150px;
}

#bodyNameChart,
#actionChart,
#arrestsStateChart,
#affectedStateChart {
  height: 280px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 6px;
}

.map {
  height: 520px;
  overflow: hidden;
}

.map-total {
  border: 1px solid #d1c7b7;
  border-radius: 7px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.chart-selection {
  border: 1px solid #d1c7b7;
  border-radius: 7px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.map .empty {
  height: 100%;
}

svg {
  width: 100%;
  height: 100%;
  display: block;
}

.axis,
.axis text,
.legend text,
.map-label {
  fill: var(--muted);
  font-size: 11px;
}

.axis line,
.axis path,
.grid-line {
  stroke: #e5ded3;
}

.bar {
  rx: 4;
  transition: opacity 140ms ease, filter 140ms ease;
}

.bar,
circle[data-filter-field],
rect[data-filter-field] {
  cursor: pointer;
}

.bar:hover,
circle[data-filter-field]:hover,
rect[data-filter-field]:hover {
  opacity: 0.86;
  filter: brightness(0.96);
}

.bar-label {
  font-size: 12px;
  fill: var(--ink);
}

.donut-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 16px;
  margin-top: 4px;
}

.donut-legend-item {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.donut-legend-item:hover {
  transform: none;
  background: transparent;
}

.donut-legend-item span {
  width: 10px;
  height: 10px;
}

.donut-legend-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.donut-legend-item em {
  color: var(--muted);
  font-style: normal;
  font-weight: 800;
  font-size: 13px;
}

.mobile-bar-list {
  display: grid;
  gap: 12px;
  padding-top: 8px;
}

.mobile-bar-row {
  cursor: pointer;
}

.mobile-bar-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.mobile-bar-head span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mobile-bar-head strong {
  flex: 0 0 auto;
  font-size: 13px;
}

.mobile-bar-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece6dc;
}

.mobile-bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
}

.table-panel {
  padding-bottom: 0;
}

.table-wrap {
  overflow: auto;
  margin: 0 -20px;
  max-height: 650px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e9e1d5;
  text-align: left;
  padding: 12px 14px;
  font-size: 12px;
  color: #343941;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  padding: 13px 14px;
  border-top: 1px solid #eee8df;
  vertical-align: top;
  line-height: 1.4;
}

tbody tr:nth-child(even) {
  background: #fbf8f2;
}

tbody tr:hover {
  background: #f3efe6;
}

td:nth-child(2) {
  max-width: 360px;
  font-weight: 700;
}

a {
  color: var(--blue);
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: white;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(23, 25, 31, 0.96);
  color: white;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 12px;
  max-width: 280px;
  z-index: 20;
  box-shadow: 0 12px 26px rgba(0,0,0,0.24);
}

.empty {
  color: var(--muted);
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
}

@media (max-width: 1100px) {
  .filters,
  .kpis,
  .two,
  .three,
  .map-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two .panel:first-child {
    grid-column: auto;
  }

  .filters {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-header,
  .panel-head {
    display: block;
  }

  .header-stat {
    display: inline-block;
    margin-top: 12px;
  }

  .filters,
  .kpis,
  .two,
  .three,
  .map-grid {
    grid-template-columns: 1fr;
  }

  .two,
  .three,
  .map-grid {
    align-items: start;
  }

  .two .panel,
  .three .panel,
  .map-grid .panel {
    height: auto;
  }

  #statusChart {
    height: auto;
  }

  #statusChart svg {
    height: 165px;
  }

  .map {
    height: 400px;
  }

  .map svg {
    transform: scale(2);
    transform-origin: center center;
  }

  .donut-legend {
    gap: 7px 10px;
    margin-top: 0;
  }

  .donut-legend-item {
    min-height: 22px;
    gap: 6px;
  }

  .donut-legend-item strong,
  .donut-legend-item em {
    font-size: 13px;
  }

  .floating-reset {
    right: 14px;
    bottom: 14px;
    min-height: 44px;
    padding: 0 15px;
  }
}
