:root {
  --bg: #f4f5f7;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --text: #1a1c22;
  --text-dim: #6b7280;
  --accent: #0d9488;
  --accent-2: #0f766e;
  --accent-ink: #1a1c22;
  --danger: #e05a5a;
  --border: rgba(17, 19, 24, 0.1);
  --shadow-sm: 0 1px 2px rgba(17, 19, 24, 0.06);
  --shadow: 0 1px 3px rgba(17, 19, 24, 0.07), 0 12px 30px rgba(17, 19, 24, 0.09);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Mulish', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 26px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-logo {
  width: 46px; height: 46px;
  object-fit: contain;
  display: block;
  animation: brandSpin 9s linear infinite;
}
@keyframes brandSpin { to { transform: rotate(360deg); } }
.brand-text h1 { font-family: 'Sora', sans-serif; font-size: 15.5px; font-weight: 700; letter-spacing: 0.2px; }
.brand-text p { font-size: 11.5px; color: var(--text-dim); font-weight: 600; }

.stat-strip { display: flex; gap: 10px; margin-left: auto; }
.stat-item {
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 7px 18px; min-width: 82px;
  box-shadow: var(--shadow-sm);
}
.stat-num { font-family: 'Sora', sans-serif; font-size: 20px; font-weight: 700; color: var(--accent-2); line-height: 1.2; }
.stat-lbl { font-size: 11px; color: var(--text-dim); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: none; cursor: pointer;
  padding: 10px 18px; border-radius: 11px;
  font-family: inherit; font-size: 13.5px; font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s, color 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.45);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(13, 148, 136, 0.6); }
.btn-ghost {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 4px 14px rgba(224, 90, 90, 0.3); }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.hidden { display: none !important; }

/* Layout */
.layout { display: flex; flex: 1; min-height: 0; }

/* Sidebar */
.sidebar {
  width: 410px; min-width: 410px;
  display: flex; flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.sidebar-head { padding: 16px 18px 12px; }

.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text-dim);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18); }
.search input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 13.5px;
}
.search input::placeholder { color: var(--text-dim); }
.search-clear {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 20px; line-height: 1; padding: 0 2px;
}
.search-clear:hover { color: var(--text); }

/* Resumo */
.resumo { padding: 4px 18px 14px; border-bottom: 1px solid var(--border); }
.resumo-title {
  font-family: 'Sora', sans-serif; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-dim); margin-bottom: 11px;
}
.resumo-total { font-family: 'Sora', sans-serif; font-size: 24px; font-weight: 800; color: var(--accent-2); }
.resumo-total-lbl { font-size: 11px; color: var(--text-dim); font-weight: 600; margin-bottom: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-label { width: 48px; font-size: 12px; font-weight: 700; color: var(--text); }
.bar-track { flex: 1; height: 8px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 6px; transition: width 0.5s ease; }
.bar-val { width: 22px; text-align: right; font-size: 12px; font-weight: 800; color: var(--text-dim); }

.tabs { display: flex; gap: 6px; padding: 12px 16px 0; }
.tab {
  flex: 1; padding: 9px 0; border: 1px solid var(--border);
  background: var(--panel); color: var(--text-dim);
  border-radius: 10px; font-family: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
}
.tab:hover { border-color: var(--accent); color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}
.tab-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.list-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px 0; }
.list-toolbar .chips { flex: 1; }
.mini-select {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 10px; color: var(--text);
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; outline: none;
}
.mini-select:focus { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.list-toolbar .chips { padding: 0; }
.chip {
  padding: 6px 13px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600; cursor: pointer;
  color: var(--text-dim); transition: all 0.2s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
}

.link-list, .mun-list { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.link-list::-webkit-scrollbar, .mun-list::-webkit-scrollbar { width: 8px; }
.link-list::-webkit-scrollbar-thumb, .mun-list::-webkit-scrollbar-thumb { background: #d7dce3; border-radius: 8px; }
.empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 30px 10px; line-height: 1.6; }

.link-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.link-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.link-card-top { display: flex; align-items: center; gap: 10px; }
.link-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.link-name { font-weight: 700; font-size: 13.5px; flex: 1; }
.link-cat {
  font-size: 10.5px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.5px; color: #0f766e;
  background: rgba(13, 148, 136, 0.16);
  padding: 3px 8px; border-radius: 8px;
}
.link-desc { margin-top: 6px; font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }
.link-mun { margin-top: 6px; font-size: 12px; color: var(--text); font-weight: 700; }
.link-actions {
  display: flex; gap: 6px; margin-top: 10px;
  opacity: 0.7; transition: opacity 0.2s;
}
.link-card:hover .link-actions { opacity: 1; }
.link-actions .btn { padding: 5px 10px; font-size: 11px; }

/* Grupos por região/município */
.region-block { display: flex; flex-direction: column; gap: 7px; }
.region-block + .region-block { margin-top: 8px; }
.mun-block-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 4px 0; margin-top: 4px;
}
.mun-block-name { font-weight: 800; font-size: 12.5px; color: var(--text); }
.mun-block-count {
  font-size: 11px; font-weight: 800; color: #0f766e;
  background: rgba(13, 148, 136, 0.16); padding: 1px 8px; border-radius: 8px;
}

.mun-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}
.mun-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.mun-card-top { display: flex; align-items: center; gap: 12px; }
.mun-name { font-weight: 700; font-size: 14px; flex: 1; }
.mun-region {
  font-size: 10px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-dim);
  background: var(--panel-2); padding: 2px 7px; border-radius: 6px;
}
.mun-count {
  font-size: 12px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); padding: 3px 10px; border-radius: 8px;
}
.mun-links { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.mun-link { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.mun-link:hover { color: var(--text); }
.mun-link .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.region-header {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Sora', sans-serif; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-dim); padding: 8px 4px 2px;
}
.region-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* Rótulos dos municípios no mapa */
.mun-label {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #3a4150 !important;
  font-family: 'Mulish', sans-serif;
  font-size: 10px !important;
  font-weight: 700;
  text-shadow: 0 0 3px rgba(255,255,255,0.95), 0 0 3px rgba(255,255,255,0.95), 0 0 2px rgba(255,255,255,0.9);
  pointer-events: none !important;
}
.mun-label.bold {
  font-weight: 800 !important;
  color: #12141a !important;
  font-size: 10.5px !important;
}

.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 12px; font-weight: 600; }

/* Map */
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: radial-gradient(120% 120% at 50% 0%, #fbfcfd 0%, #e9edf2 100%); }
#map .leaflet-overlay-pane svg { filter: drop-shadow(0 8px 20px rgba(17, 19, 24, 0.14)); }

.legend {
  position: absolute; bottom: 20px; right: 20px; z-index: 1000;
  background: rgba(255, 255, 255, 0.97); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px; box-shadow: var(--shadow);
}
.legend-title { font-family: 'Sora', sans-serif; font-size: 11.5px; font-weight: 700; margin-bottom: 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); padding: 3px 0; }
.legend-row[data-region] { cursor: pointer; border-radius: 6px; padding: 3px 6px; margin: 0 -6px; transition: background 0.2s; }
.legend-row[data-region]:hover { background: var(--panel-2); color: var(--text); }
.swatch { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; }
.swatch-active { border-radius: 50%; background: transparent; border: 2.5px solid var(--accent-2); }

.map-ctl, .layer-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; font-size: 18px; color: var(--text);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.map-ctl:hover, .layer-btn:hover { border-color: var(--accent); }

.layer-ctl { position: relative; }
.layer-panel {
  position: absolute; top: 44px; right: 0;
  background: rgba(255, 255, 255, 0.99);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  min-width: 170px;
}
.layer-panel-title { font-family: 'Sora', sans-serif; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); margin-bottom: 8px; }
.layer-item { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; cursor: pointer; }
.layer-item input { accent-color: var(--accent); }

/* Contador de links por município */
.mun-badge {
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  color: #fff; font-size: 12px; font-weight: 800;
  border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(17, 19, 24, 0.28);
  cursor: pointer;
}

/* Marcadores de link */
.ms-marker {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  color: #fff; font-size: 17px; line-height: 1;
  border: 2.5px solid #fff;
  box-shadow: 0 4px 12px rgba(17, 19, 24, 0.3);
  cursor: pointer;
}

/* Pino de localização */
.pin-marker { position: relative; width: 22px; height: 34px; }
.pin-head {
  position: absolute; top: 0; left: 3px;
  width: 16px; height: 16px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}
.pin-tail {
  position: absolute; top: 10px; left: 9px;
  width: 6px; height: 6px; border-radius: 50%;
  background: #fff;
}

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(17, 19, 24, 0.45);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 20px;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 30px;
  width: 100%; max-width: 430px;
  box-shadow: 0 20px 60px rgba(17, 19, 24, 0.22);
  position: relative;
  animation: pop 0.25s ease;
}
.modal-wide { max-width: 490px; }
@keyframes pop { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: transparent; border: none;
  color: var(--text-dim); font-size: 26px; cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.4);
}
.modal h2 { font-family: 'Sora', sans-serif; font-size: 20px; font-weight: 700; }
.modal-sub { color: var(--text-dim); font-size: 13px; margin: 4px 0 18px; }

.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12.5px; font-weight: 700; color: var(--text-dim);
}
.modal input[type="text"], .modal input[type="url"], .modal input[type="password"], .modal textarea, .modal select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text); font-family: inherit; font-size: 13.5px;
  outline: none;
}
.modal select { cursor: pointer; }
.modal input:focus, .modal textarea:focus, .modal select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18); }
.modal input[type="color"] {
  width: 100%; height: 44px; border: none; border-radius: 10px;
  background: transparent; cursor: pointer; padding: 0;
}
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .btn { flex: 1; justify-content: center; }

.error-msg { color: var(--danger); font-size: 12.5px; font-weight: 600; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1a1c22; color: #fff;
  padding: 12px 22px; border-radius: 12px;
  font-size: 13.5px; font-weight: 700;
  box-shadow: var(--shadow); z-index: 3000;
  animation: pop 0.25s ease;
}

@media (max-width: 900px) {
  .sidebar { width: 310px; min-width: 310px; }
}

/* ---- Polimento visual ---- */
.topbar { position: relative; }
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(13, 148, 136, 0.75), transparent);
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.link-card, .mun-card { animation: fadeIn 0.22s ease both; }
.region-block { animation: fadeIn 0.28s ease both; }

.stat-item { transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s; }
.stat-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: rgba(13, 148, 136, 0.5); }

.region-header {
  padding: 6px 8px;
  margin: 2px -4px 0;
  background: linear-gradient(90deg, rgba(13, 148, 136, 0.1), transparent);
  border-radius: 8px;
}
.mun-block-head { border-top: 1px dashed var(--border); margin-top: 9px; padding: 9px 4px 0; }
.region-block:first-child .mun-block-head:first-of-type { border-top: none; margin-top: 2px; }

.link-card:active { transform: translateY(0) scale(0.995); }

/* Scrollbar */
.link-list, .mun-list { scrollbar-width: thin; scrollbar-color: #d7dce3 transparent; }
.link-list::-webkit-scrollbar-thumb, .mun-list::-webkit-scrollbar-thumb { background: #cfd6df; }
.link-list::-webkit-scrollbar-thumb:hover, .mun-list::-webkit-scrollbar-thumb:hover { background: #b9c1cd; }