:root {
  --bg: #f6f7f4;
  --ink: #17201b;
  --muted: #68766e;
  --line: #dce3de;
  --panel: #ffffff;
  --green: #166534;
  --mint: #dff5e8;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --red: #b91c1c;
  --amber: #b45309;
  --shadow: 0 18px 45px rgba(18, 32, 24, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  padding: 22px 16px;
  background: #101914;
  color: #eef8f1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e7f8ee;
  color: #14532d;
  font-weight: 800;
}

.brand strong { display: block; font-size: 15px; }
.brand span { display: block; color: #9fb3a7; font-size: 12px; margin-top: 2px; }

nav { display: grid; gap: 4px; }
nav a, .logout {
  color: #dbeee2;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 6px;
}
nav a:hover, .logout:hover { background: rgba(255,255,255,.08); }
.logout { margin-top: auto; color: #fecaca; }

main {
  margin-left: 252px;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 22px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.1; letter-spacing: 0; }
.topbar p { color: var(--muted); margin-top: 7px; }
h2 { font-size: 17px; line-height: 1.2; }

.controls {
  display: flex;
  gap: 10px;
  align-items: end;
}

label { color: var(--muted); font-size: 12px; display: grid; gap: 5px; }
select, button, input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
button {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

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

.kpi-grid article { padding: 16px; }
.kpi-grid span { color: var(--muted); display: block; font-size: 12px; }
.kpi-grid strong { display: block; margin-top: 7px; font-size: 26px; line-height: 1; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(340px, .6fr);
  gap: 14px;
  margin-bottom: 14px;
}

.grid-two, .grid-three {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}
.grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.panel { padding: 16px; min-width: 0; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head span { color: var(--muted); font-size: 12px; }

#leaflet-map {
  height: 430px;
  border-radius: 8px;
  overflow: hidden;
  background: #e9efe9;
}

.rank-list {
  display: grid;
  gap: 9px;
}

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.rank-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.rank-value { font-weight: 800; }
.bar {
  grid-column: 1 / -1;
  height: 7px;
  background: #eef2ef;
  border-radius: 999px;
  overflow: hidden;
}
.bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--blue)); }

.compact .rank-row { grid-template-columns: minmax(0, 1fr) auto; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.compact .bar { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--mint);
  color: #14532d;
  font-weight: 700;
}
.chip span { color: #315d42; font-weight: 600; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}
th, td {
  padding: 10px 9px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
td { font-size: 13px; }

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(22,101,52,.12), transparent 30%),
    linear-gradient(315deg, rgba(29,78,216,.11), transparent 35%),
    var(--bg);
}

.login {
  width: min(420px, 100%);
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 15px;
}
.login h1 { font-size: 28px; }
.login p { color: var(--muted); }
.login button { width: 100%; }
.error { color: var(--red); font-weight: 700; }

.data-attribution {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.data-attribution a {
  color: inherit;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout, .grid-two, .grid-three { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    position: static;
    width: auto;
    padding: 14px;
  }
  nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .logout { margin-top: 0; }
  main { margin-left: 0; padding: 16px; }
  .topbar { display: grid; }
  .controls { align-items: stretch; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 24px; }
  #leaflet-map { height: 360px; }
  .data-attribution { text-align: left; }
}
