:root {
  --iab-forest: #12372a;
  --iab-green: #1f7a52;
  --iab-mint: #d9f2e6;
  --iab-ink: #18231f;
  --iab-muted: #66736e;
  --iab-line: #dce5e0;
  --iab-bg: #f3f6f4;
  --iab-a: #c53a35;
  --iab-b: #e4a11b;
  --iab-c: #27865b;
  --iab-confirmed: #7a1f8a;
  --iab-suspect: #d84b3f;
  --iab-high: #e46f1a;
  --iab-medium: #e4b51b;
  --iab-low: #2d8ccf;
  --iab-discarded: #6f7b76;
  --shadow: 0 14px 40px rgba(18, 55, 42, .14);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  color: var(--iab-ink);
  background: var(--iab-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.btn-iab {
  color: #fff;
  background: var(--iab-forest);
  border-color: var(--iab-forest);
}
.btn-iab:hover, .btn-iab:focus { color: #fff; background: #0c2a1f; border-color: #0c2a1f; }
.eyebrow {
  display: block;
  color: var(--iab-green);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

/* Login */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(390px, 42%) 1fr; background: #eef5f1; }
.login-card {
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: min(470px, calc(100% - 64px));
  margin: auto;
  padding: 42px;
  background: rgba(255, 255, 255, .95);
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(18, 55, 42, .13);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 54px; }
.brand-mark, .brand-symbol {
  display: grid; place-items: center; width: 46px; height: 46px; color: #fff;
  background: var(--iab-forest); border-radius: 13px; font-size: 1.2rem;
}
.login-brand > span:last-child { display: flex; flex-direction: column; }
.login-brand strong { font-size: 1.15rem; letter-spacing: .08em; }
.login-brand small { color: var(--iab-muted); }
.login-copy h1 { margin: 8px 0 14px; font-size: clamp(2rem, 4vw, 3.2rem); line-height: .98; letter-spacing: -.045em; }
.login-copy p { color: var(--iab-muted); font-size: 1rem; line-height: 1.6; }
.login-card form { margin-top: 30px; }
.login-card .form-control { border-color: var(--iab-line); border-radius: 12px; }
.login-version { margin: 36px 0 0; color: #93a09b; font-size: .75rem; text-align: center; }
.login-visual {
  position: relative; overflow: hidden; min-height: 100vh;
  background:
    radial-gradient(circle at 72% 25%, rgba(210, 243, 226, .7) 0 5%, transparent 6%),
    linear-gradient(135deg, rgba(18, 55, 42, .1), rgba(18, 55, 42, .76)),
    url("https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=1800&q=84") center/cover;
}
.login-visual::before {
  content: ""; position: absolute; inset: 0; opacity: .3;
  background-image: linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);
  background-size: 72px 72px;
}
.login-visual::after {
  content: ""; position: absolute; left: 58%; top: 38%; width: 34px; height: 34px;
  border: 9px solid #fff; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.25));
}
.visual-caption {
  position: absolute; left: 9%; right: 9%; bottom: 9%; display: flex; flex-direction: column;
  max-width: 620px; color: #fff;
}
.visual-caption span { font-size: .76rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.visual-caption strong { margin-top: 8px; font-size: clamp(1.6rem, 3vw, 3.2rem); line-height: 1.05; }

/* Application shell */
.app-shell { height: 100vh; display: grid; grid-template-rows: 58px 1fr; overflow: hidden; }
.topbar {
  z-index: 1000; display: grid; grid-template-columns: auto minmax(220px, 360px) 1fr;
  align-items: center; gap: 18px; padding: 8px 14px; color: #fff; background: var(--iab-forest);
  box-shadow: 0 4px 24px rgba(6, 27, 19, .18);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-symbol { width: 36px; height: 36px; color: var(--iab-forest); background: var(--iab-mint); border-radius: 10px; }
.brand > span:last-child { display: flex; align-items: baseline; gap: 5px; letter-spacing: .08em; }
.brand small { color: #a9c7ba; }
.municipality-picker { position: relative; display: flex; align-items: center; }
.municipality-picker > i { position: absolute; left: 12px; z-index: 1; color: var(--iab-green); }
.municipality-picker .form-select {
  padding-left: 34px; color: var(--iab-ink); background-color: #fff;
  border: 0; border-radius: 10px; font-weight: 650;
}
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; min-width: 0; }
.btn-topbar { color: #e9f4ef; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.07); }
.btn-topbar:hover { color: #fff; background: rgba(255,255,255,.16); }
.btn-topbar.active { color: #fff; border-color: rgba(46,144,255,.72); background: #1677ff; }
.btn-topbar.locating i { animation: gps-spin 1s linear infinite; }
.user-chip {
  max-width: 120px; overflow: hidden; padding: 5px 9px; color: #cfe3da;
  font-size: .78rem; text-overflow: ellipsis; white-space: nowrap;
}
.workspace { min-height: 0; display: grid; grid-template-columns: minmax(330px, 390px) 1fr; }
.sidebar { z-index: 500; min-width: 0; overflow-y: auto; background: #fff; border-right: 1px solid var(--iab-line); }
.sidebar-header {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: flex-start;
  justify-content: space-between; gap: 10px; padding: 14px 16px 12px;
  background: rgba(255,255,255,.96); border-bottom: 1px solid var(--iab-line); backdrop-filter: blur(10px);
}
.sidebar-header h2 { margin: 2px 0 0; font-size: 1.08rem; letter-spacing: -.02em; }
.btn-icon { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--iab-line); border-radius: 9px; }
.dashboard-panel { padding: 14px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card {
  display: flex; align-items: flex-end; justify-content: space-between; min-height: 86px;
  padding: 15px; text-align: left; background: #f7f9f8; border: 1px solid var(--iab-line);
  border-radius: 14px; transition: .18s ease;
}
.stat-card span { color: var(--iab-muted); font-size: .76rem; font-weight: 650; }
.stat-card strong { font-size: 1.75rem; line-height: 1; }
.stat-card:hover, .stat-card.active { border-color: var(--iab-green); box-shadow: 0 0 0 3px rgba(31,122,82,.09); transform: translateY(-1px); }
.stat-confirmed strong { color: var(--iab-confirmed); }
.stat-suspect strong { color: var(--iab-suspect); }
.stat-high strong { color: var(--iab-high); }
.info-card {
  display: grid; grid-template-columns: 40px 1fr; gap: 12px; margin-top: 18px; padding: 16px;
  background: #f7f9f8; border: 1px solid var(--iab-line); border-radius: 14px;
}
.info-card > i { display: grid; place-items: center; width: 40px; height: 40px; color: var(--iab-green); background: var(--iab-mint); border-radius: 11px; }
.info-card strong { font-size: .9rem; } .info-card p { margin: 3px 0 0; color: var(--iab-muted); font-size: .82rem; line-height: 1.45; }
.info-card-accent { background: #f0f8f4; border-color: #cfe7da; }
.legend { display: grid; gap: 9px; margin-top: 24px; padding: 16px 4px; border-top: 1px solid var(--iab-line); color: var(--iab-muted); font-size: .8rem; }
.legend-dot { display: inline-block; width: 10px; height: 10px; margin-right: 7px; border-radius: 50%; }
.status-confirmado { background: var(--iab-confirmed); }
.status-sospechoso { background: var(--iab-suspect); }
.status-potencial-alto { background: var(--iab-high); }
.status-potencial-medio { background: var(--iab-medium); }
.status-potencial-bajo { background: var(--iab-low); }
.status-descartado { background: var(--iab-discarded); }
.status-sin-dato { background: var(--iab-c); }

/* Form */
.feature-form { padding: 12px 14px 22px; }
.feature-form fieldset { min-width: 0; padding: 0; border: 0; }
.feature-form legend { margin-bottom: 8px; font-size: .78rem; font-weight: 800; }
.feature-form .form-label { margin-bottom: 4px; color: var(--iab-muted); font-size: .73rem; font-weight: 700; }
.feature-form .form-control, .feature-form .form-select {
  min-height: 34px; padding: .38rem .58rem; border-color: var(--iab-line);
  border-radius: 9px; font-size: .84rem;
}
.feature-form .row.g-3 { --bs-gutter-y: .6rem; }
.feature-form .row.g-2 { --bs-gutter-y: .45rem; --bs-gutter-x: .55rem; }
.feature-form textarea.form-control { min-height: 58px; }
.field-note { padding: 7px 9px; color: #5f6f68; background: #f3f8f5; border: 1px dashed #cbded4; border-radius: 9px; font-size: .68rem; line-height: 1.3; }
.score-strip { display: grid; grid-template-columns: .85fr 1.25fr .8fr; gap: 6px; margin-bottom: 12px; }
.score-strip > div { min-width: 0; padding: 8px 9px; background: #f6f9f7; border: 1px solid var(--iab-line); border-radius: 10px; }
.score-strip span { display: block; color: var(--iab-muted); font-size: .57rem; font-weight: 800; text-transform: uppercase; }
.score-strip strong {
  display: block; overflow-wrap: anywhere; margin-top: 3px;
  font-size: .98rem; line-height: 1.25;
}
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 8px; margin: 16px 0 8px; }
.section-title h3 { margin: 2px 0 0; font-size: .95rem; }
.assessment-list { display: grid; gap: 9px; }
.assessment-item { padding: 10px; background: #fbfcfb; border: 1px solid var(--iab-line); border-radius: 12px; }
.assessment-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.assessment-header > div { display: flex; align-items: center; gap: 8px; }
.assessment-number { font-size: .76rem; font-weight: 800; }
.assessment-badge { padding: 5px 7px; }
.badge-state-a { color: #fff; background: var(--iab-a); }
.badge-state-b { color: #3e2b00; background: #f4c65b; }
.badge-state-c { color: #fff; background: var(--iab-c); }
.btn-quiet { color: var(--iab-muted); border: 0; }
.photo-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-thumb { position: relative; overflow: hidden; aspect-ratio: 1; background: var(--iab-bg); border: 1px solid var(--iab-line); border-radius: 11px; }
.photo-thumb a { display: block; width: 100%; height: 100%; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s ease; }
.photo-thumb a:hover img { transform: scale(1.04); }
.photo-remove {
  position: absolute; top: 5px; right: 5px; z-index: 2; display: grid; place-items: center;
  width: 24px; height: 24px; color: #fff; background: rgba(12,42,31,.78);
  border: 0; border-radius: 999px; line-height: 1;
}
.photo-pending::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 45%, rgba(0,0,0,.42));
}
.photo-pending span {
  position: absolute; z-index: 1; left: 7px; bottom: 6px; color: #fff;
  font-size: .63rem; font-weight: 800; text-transform: uppercase;
}
.photo-controls { display: grid; gap: 5px; }
.photo-controls small { color: var(--iab-muted); font-size: .68rem; }
.empty-photos { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 72px; color: var(--iab-muted); background: #f8faf9; border: 1px dashed #cbd8d1; border-radius: 12px; font-size: .82rem; }
.form-actions {
  position: sticky; bottom: -28px; z-index: 5; display: flex; gap: 10px;
  margin: 18px -14px -22px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.96); border-top: 1px solid var(--iab-line); backdrop-filter: blur(10px);
}

/* Map */
.map-wrap { position: relative; min-width: 0; min-height: 0; }
#map { width: 100%; height: 100%; background: #dce5df; }
#map.placing-point { cursor: crosshair; }
.map-notice {
  position: absolute; z-index: 600; left: 50%; top: 18px; display: flex; align-items: center; gap: 10px;
  max-width: calc(100% - 30px); padding: 10px 13px; color: #fff; background: var(--iab-forest);
  border-radius: 12px; box-shadow: var(--shadow); transform: translateX(-50%); font-size: .82rem;
}
.map-notice button { padding: 2px 6px; color: #bfe7d3; background: transparent; border: 0; font-weight: 700; }
.iab-marker {
  position: relative; display: grid; place-items: center; width: 42px; height: 42px; color: #fff;
  border: 3px solid #fff; border-radius: 50% 50% 50% 0; box-shadow: 0 5px 15px rgba(0,0,0,.3);
  transform: rotate(-45deg);
}
.iab-marker::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  transform: rotate(45deg);
}
.iab-marker span { transform: rotate(45deg); font-size: .68rem; font-weight: 900; letter-spacing: -.02em; }
.iab-marker.status-confirmado { background: var(--iab-confirmed); }
.iab-marker.status-sospechoso { background: var(--iab-suspect); }
.iab-marker.status-potencial-alto { background: var(--iab-high); }
.iab-marker.status-potencial-medio { color: #382800; background: var(--iab-medium); }
.iab-marker.status-potencial-bajo { background: var(--iab-low); }
.iab-marker.status-descartado { background: var(--iab-discarded); }
.iab-marker.status-sin-dato { background: var(--iab-c); }
.iab-cluster {
  display: grid; place-items: center; width: 44px; height: 44px; color: #fff;
  background: var(--iab-forest); border: 3px solid #fff; border-radius: 50%;
  box-shadow: 0 8px 22px rgba(0,0,0,.28);
}
.iab-cluster span { font-size: .86rem; font-weight: 900; letter-spacing: -.03em; }
.iab-cluster-small { background: var(--iab-green); }
.iab-cluster-medium { color: #352600; background: var(--iab-medium); }
.iab-cluster-large { background: var(--iab-suspect); }
.leaflet-marker-icon { touch-action: manipulation; }
.gps-marker {
  position: relative; display: grid; place-items: center; width: 28px; height: 28px;
  background: #1677ff; border: 3px solid #fff; border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.gps-marker::before {
  content: ""; position: absolute; inset: -9px; border: 2px solid rgba(22,119,255,.35);
  border-radius: 50%; animation: gps-pulse 1.8s ease-out infinite;
}
.gps-marker span { width: 7px; height: 7px; background: #fff; border-radius: 50%; }
@keyframes gps-pulse {
  from { transform: scale(.55); opacity: .9; }
  to { transform: scale(1.35); opacity: 0; }
}
@keyframes gps-spin { to { transform: rotate(360deg); } }
.leaflet-control-layers, .leaflet-control-zoom { border: 0 !important; border-radius: 10px !important; box-shadow: var(--shadow) !important; }
.leaflet-control-layers-toggle { width: 40px !important; height: 40px !important; }

/* Users */
.modal-content { border: 0; border-radius: 18px; box-shadow: 0 26px 80px rgba(18,55,42,.25); }
.modal-header { padding: 18px 22px; border-color: var(--iab-line); }
.user-manager { display: grid; grid-template-columns: minmax(280px, 340px) 1fr; gap: 24px; padding: 22px; background: #f7f9f8; }
.user-form { display: grid; align-content: start; gap: 14px; padding: 18px; background: #fff; border: 1px solid var(--iab-line); border-radius: 15px; }
.user-form .form-label, .user-form legend { margin-bottom: 4px; color: var(--iab-muted); font-size: .73rem; font-weight: 750; }
.user-form fieldset { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--iab-line); border-radius: 11px; }
.user-form fieldset > small { color: var(--iab-muted); font-size: .68rem; }
.permissions-list { display: grid; gap: 7px; max-height: 180px; overflow: auto; }
.permission-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-size: .78rem; }
.permission-edit { color: var(--iab-muted); font-size: .72rem; }
.users-table { display: grid; align-content: start; gap: 8px; }
.user-row {
  display: grid; grid-template-columns: 42px minmax(130px, 1fr) auto 12px auto;
  align-items: center; gap: 12px; padding: 12px 14px; background: #fff;
  border: 1px solid var(--iab-line); border-radius: 13px;
}
.user-avatar { display: grid; place-items: center; width: 40px; height: 40px; color: var(--iab-forest); background: var(--iab-mint); border-radius: 12px; font-size: .72rem; font-weight: 850; }
.user-main { display: flex; min-width: 0; flex-direction: column; }
.user-main strong { font-size: .86rem; }
.user-main span { overflow: hidden; color: var(--iab-muted); font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
.scope-all { color: var(--iab-green) !important; }
.role-badge { padding: 5px 8px; border-radius: 20px; font-size: .68rem; font-weight: 700; }
.role-admin { color: #5b2b80; background: #eee0f7; }
.role-field { color: #175a3e; background: #dff3e9; }
.role-viewer { color: #365478; background: #e1ecf7; }
.status-dot { width: 9px; height: 9px; background: #aeb8b4; border-radius: 50%; }
.status-dot.active { background: #27a66d; box-shadow: 0 0 0 4px rgba(39,166,109,.13); }
.user-actions { display: flex; gap: 5px; }

@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; background: linear-gradient(145deg, #e4f1ea, #f7faf8); }
  .login-card { width: min(470px, calc(100% - 30px)); padding: 32px; }
  .login-visual { display: none; }
  .topbar { grid-template-columns: auto 1fr auto; gap: 10px; }
  .workspace { grid-template-columns: minmax(320px, 390px) 1fr; }
  .user-manager { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .app-shell { grid-template-rows: auto 1fr; }
  .topbar { grid-template-columns: auto 1fr; padding: 8px 10px; }
  .municipality-picker { grid-column: 1 / -1; grid-row: 2; }
  .topbar-actions { grid-column: 2; grid-row: 1; }
  .topbar-actions .btn span, .user-chip { display: none; }
  .workspace { position: relative; display: block; }
  .map-wrap { position: absolute; inset: 0; }
  .sidebar {
    position: absolute; z-index: 700; left: 10px; right: 10px; bottom: 10px;
    max-height: min(58vh, 620px); border: 1px solid var(--iab-line); border-radius: 18px;
    box-shadow: 0 18px 50px rgba(13,40,30,.22);
  }
  .sidebar:has(.dashboard-panel:not(.d-none)) { max-height: 210px; }
  .sidebar.dashboard-open { max-height: 210px; }
  .sidebar.feature-open { max-height: min(72vh, 680px); }
  .sidebar-header { padding: 13px 15px 10px; }
  .dashboard-panel { padding: 10px 14px 14px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat-card { display: grid; min-height: 58px; padding: 8px; }
  .stat-card span { font-size: .58rem; } .stat-card strong { font-size: 1.25rem; }
  .dashboard-panel .info-card, .dashboard-panel .legend { display: none; }
  .feature-form { padding: 14px 15px 25px; }
  .form-actions { margin-left: -15px; margin-right: -15px; padding-left: 15px; padding-right: 15px; }
  .map-notice { top: 12px; }
  .user-row { grid-template-columns: 38px 1fr auto; }
  .role-badge, .status-dot { display: none; }
}

@media (max-width: 420px) {
  .login-card { padding: 25px 20px; }
  .login-brand { margin-bottom: 36px; }
  .login-copy h1 { font-size: 2.15rem; }
  .brand > span:last-child { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar:has(.dashboard-panel:not(.d-none)) { max-height: 205px; }
  .photo-list { grid-template-columns: repeat(2, 1fr); }
}
