:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dce3ec;
  --text: #172033;
  --muted: #65758b;
  --blue: #0878f8;
  --blue-dark: #075bc0;
  --green: #00a878;
  --amber: #d08a00;
  --red: #ee4266;
  --shadow: 0 14px 34px rgba(24, 39, 75, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.icon-button {
  display: grid;
  gap: 4px;
  width: 38px;
  height: 38px;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.icon-button span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 19px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 16px;
  font-weight: 720;
}

.user-badge {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

main {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.filter-panel,
.chart-card,
.table-card,
.kpi-card {
  border: 1px solid var(--line);
  border-top: 3px solid var(--blue);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.filter-panel {
  padding: 18px;
}

.panel-heading,
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.filter-actions {
  display: flex;
  gap: 10px;
}

button {
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.link-button {
  width: fit-content;
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.primary-button,
.ghost-button {
  min-width: 110px;
  height: 40px;
  border-radius: 8px;
}

.primary-button {
  border: 0;
  background: var(--blue);
  color: white;
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
}

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: #29364a;
  font-size: 12px;
  font-weight: 800;
}

select,
input {
  width: 100%;
  min-width: 0;
  height: 39px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: white;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 0 11px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 16px;
}

.kpi-card span,
.kpi-card small,
.card-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi-card strong {
  overflow-wrap: anywhere;
  font-size: 30px;
  line-height: 1;
}

.kpi-card.accent {
  border-top-color: var(--amber);
  background: linear-gradient(180deg, #fffaf0, #ffffff 72%);
}

.compact-card {
  padding: 16px;
}

.recap-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.recap-grid article {
  display: grid;
  gap: 5px;
  min-height: 86px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.recap-grid span,
.recap-grid small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.recap-grid strong {
  font-size: 25px;
  line-height: 1;
}

.layout-map {
  display: grid;
}

.chart-card {
  min-width: 0;
  padding: 16px;
}

#map {
  height: 430px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #d9ecf5;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.mini-button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 50%;
}

.legend-dot.low {
  background: #0b8ff4;
}

.legend-dot.medium {
  background: #f59e0b;
}

.legend-dot.high {
  background: #ef4444;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.span-4 {
  grid-column: span 4;
}

.span-5 {
  grid-column: span 5;
}

.span-6 {
  grid-column: span 6;
}

.span-7 {
  grid-column: span 7;
}

.span-8 {
  grid-column: span 8;
}

canvas {
  width: 100% !important;
  height: 350px !important;
  margin-top: 12px;
}

.span-4 canvas,
.span-5 canvas {
  height: 360px !important;
}

.table-card {
  padding: 16px;
}

.hidden {
  display: none;
}

.panel-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.table-wrap {
  max-height: 430px;
  margin-top: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4fb;
  color: #263247;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:nth-child(even) {
  background: #fbfdff;
}

.leaflet-popup-content {
  font: 13px/1.45 Inter, system-ui, sans-serif;
}

@media (max-width: 1200px) {
  .filters {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .recap-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .span-4,
  .span-5,
  .span-6,
  .span-7,
  .span-8 {
    grid-column: span 12;
  }
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: auto 1fr;
  }

  .user-badge {
    display: none;
  }

  main {
    padding: 12px;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filters,
  .kpi-grid,
  .recap-grid {
    grid-template-columns: 1fr;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  #map {
    height: 360px;
  }

  canvas {
    height: 320px !important;
  }
}

/* ============================================================
   MENU DOWNLOAD PER CHART
   ============================================================ */
.chart-card .card-title {
  position: relative;
}

.chart-download {
  position: relative;
  margin-left: 8px;
  flex: 0 0 auto;
}

.chart-menu-button {
  width: 34px;
  height: 32px;
  border: 1px solid #dce4ef;
  border-radius: 8px;
  background: #ffffff;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

.chart-menu-button:hover {
  background: #f3f7fc;
  border-color: #b9c7d9;
}

.chart-menu-button span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: #334155;
}

.chart-download-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 7px);
  right: 0;
  width: 170px;
  padding: 6px;
  border: 1px solid #dce4ef;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 14px 35px rgba(15, 23, 42, 0.18);
  display: none;
}

.chart-download-menu.open {
  display: block;
}

.chart-download-menu button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #172033;
  font: 600 12px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  cursor: pointer;
}

.chart-download-menu button:hover {
  background: #eef6ff;
  color: #0868c9;
}

.chart-menu-separator {
  height: 1px;
  margin: 5px 3px;
  background: #e5eaf1;
}
