/* ==========================================================================
   GeoViz — site.css
   Base compartilhada (landing, catálogo, /app/) + design system do workspace.
   ========================================================================== */

:root {
  --ink: #182b2a;
  --ink-soft: #41564c;
  --ink-muted: #64736e;
  --ink-faint: #7d8a84;
  --paper: #f7f8f4;
  --card: #ffffff;
  --line: #e3e8e1;
  --line-soft: #ecefe8;
  --brand: #1c6658;
  --brand-deep: #104e44;
  --brand-ink: #275f51;
  --accent: #84b541;
  --danger: #983e36;
  --danger-bg: #fcf5f3;
  --warn: #6f5a1a;
  --warn-bg: #faf5e6;
  --warn-line: #e8ddb9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(24, 43, 42, 0.05), 0 4px 14px rgba(24, 43, 42, 0.06);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: inherit; }

/* ---------- Chrome compartilhado ---------- */

.nav {
  height: 68px;
  padding: 0 max(4vw, 24px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e6e9e1;
  background: #fff;
}
.brand {
  font: 800 23px/1 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  text-decoration: none;
  letter-spacing: -1.2px;
}
.brand span { color: var(--accent); font-size: 13px; margin-left: 4px; }
.nav nav { display: flex; gap: 18px; align-items: center; }
.nav-link {
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
}
.nav-link:hover { color: var(--brand); }

.button {
  border: 0;
  background: var(--brand);
  color: #fff;
  text-decoration: none;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font: 700 14px/1.2 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.button:hover { background: var(--brand-deep); }
.small { padding: 10px 15px; min-height: 44px; }
.secondary { background: #fff; color: var(--brand-ink); border: 1px solid #b9cdc2; }
.secondary:hover { background: #f4f8f5; color: var(--brand-deep); }

main { max-width: 1120px; margin: auto; padding: 78px 24px; }

.hero { padding: 40px 0 90px; max-width: 820px; }
.eyebrow {
  color: #638b4b;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.7px;
  text-transform: uppercase;
  margin: 0;
}
.hero h1, h1 {
  font: 800 clamp(38px, 6vw, 68px)/1.06 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: -2.8px;
  margin: 18px 0;
}
.lead { font-size: 19px; line-height: 1.65; color: var(--ink-muted); max-width: 720px; margin: 0 0 28px; }

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.columns article, .cta, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
.columns h2, .cta h2, .panel h2 { font: 700 20px/1.3 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.columns p, .cta p { color: var(--ink-muted); line-height: 1.6; }
.number { color: #83a753; font-weight: 700; }
.cta { margin-top: 20px; background: #edf3e7; }

.page { padding-top: 56px; min-height: calc(100vh - 150px); }
.page h1 { font-size: 48px; }

.toolbar { display: flex; justify-content: space-between; align-items: end; margin: 34px 0 16px; gap: 16px; }
.search { font-size: 13px; font-weight: 700; display: grid; gap: 8px; }
.search input, textarea {
  font: inherit;
  border: 1px solid #ccd6ce;
  border-radius: var(--radius-sm);
  padding: 12px;
  min-width: 300px;
  background: #fff;
  color: var(--ink);
}
.search input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(40, 120, 165, 0.45);
  outline-offset: 1px;
  border-color: #9db8ab;
}
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 15px; border-bottom: 1px solid #e9ece7; }
th { font-size: 12px; text-transform: uppercase; color: #75817b; letter-spacing: 0.4px; }
td small { display: block; color: #7b8781; margin-top: 4px; }

.badge { padding: 5px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.good { background: #e3f2e5; color: #267341; }
.muted { background: #f1f2ef; color: #65716b; }

.empty { padding: 40px; text-align: center; color: #66736e; }

.workspace { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; }
.workspace > div { display: grid; gap: 14px; }

.panel { padding: 22px; }
.panel h2 { margin: 0 0 14px; }
.panel[data-state="loading"] { opacity: 0.72; }
.panel[data-state="error"] { border-color: #d99; color: var(--danger); }

.map { min-height: 600px; background: #e7eddf; border: 1px solid #d6dfd1; border-radius: var(--radius); display: grid; place-items: center; overflow: hidden; }
.map-grid {
  height: 100%; min-height: inherit; width: 100%;
  display: grid; place-items: center; position: relative;
  background-color: #edf0e7;
  background-image:
    linear-gradient(32deg, transparent 48%, #dce4d7 49%, #dce4d7 51%, transparent 52%),
    linear-gradient(115deg, transparent 45%, #d9e1d4 46%, #d9e1d4 48%, transparent 49%);
  background-size: 170px 150px;
}
.map-label { background: #fff; padding: 10px 14px; border-radius: 6px; color: #5d6e63; box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08); }
.pin { position: absolute; top: 45%; left: 55%; font-size: 40px; color: var(--brand); }

textarea { display: block; min-width: 0; width: 100%; height: 90px; margin: 8px 0 14px; resize: vertical; }
.note { font-size: 12px; color: #79847e; line-height: 1.5; }

footer {
  padding: 28px max(4vw, 24px);
  border-top: 1px solid #e6e9e1;
  color: #748079;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
footer a { color: #316b58; }

@media (max-width: 720px) {
  main { padding: 48px 20px; }
  .hero { padding: 20px 0 55px; }
  .columns, .workspace { grid-template-columns: 1fr; }
  .map { min-height: 330px; }
  .toolbar { align-items: stretch; gap: 14px; flex-direction: column; }
  .search input { min-width: 0; }
  .nav { padding: 0 18px; }
  .nav nav { gap: 12px; }
  .page h1 { font-size: 40px; }
}

/* ==========================================================================
   Workspace /app/ — Modo Operate
   ========================================================================== */

.app-page { width: min(100%, 1600px); max-width: none; padding: 26px clamp(16px, 3vw, 40px) 44px; }

.app-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 4px 0 20px;
  flex-wrap: wrap;
}
.app-head-title .eyebrow { margin: 0 0 6px; font-size: 11px; }
.app-head h1 {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 30px);
  letter-spacing: -0.8px;
  line-height: 1.15;
}
.app-head .lead { margin: 0; font-size: 14px; max-width: 460px; color: var(--ink-faint); }

.workspace {
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  min-width: 0;
}

/* --- Sidebar de camadas: scroll próprio, sticky --- */
.layer-sidebar {
  display: grid;
  gap: 12px;
  min-width: 0;
  align-content: start;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: #c3cec6 transparent;
}
.layer-sidebar::-webkit-scrollbar { width: 8px; }
.layer-sidebar::-webkit-scrollbar-thumb { background: #c3cec6; border-radius: 8px; }
.layer-sidebar::-webkit-scrollbar-track { background: transparent; }

.app-page .panel { padding: 18px; border-radius: var(--radius); box-shadow: none; }
.app-page .panel h2 { font-size: 15px; letter-spacing: -0.1px; }
.panel { min-width: 0; }

.side-panel { color: var(--ink); }
.side-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.side-panel-head h2 { margin: 0; }
.panel-chip {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #6d7a72;
  background: #f1f4ef;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 8px;
}
.side-panel form label { font-size: 12px; font-weight: 700; color: var(--ink-soft); display: grid; gap: 6px; }
.side-panel .button { width: 100%; }

/* --- Coluna do mapa: dominante e sticky --- */
.map-column { position: sticky; top: 16px; min-width: 0; }

.map {
  position: relative;
  display: block;
  height: min(78vh, 840px);
  min-height: 560px;
  background: #e7eddf;
  border: 1px solid #d6dfd1;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
#leaflet-map { position: absolute; inset: 0; width: 100%; height: 100%; }
.leaflet-popup-content { overflow-wrap: anywhere; }

.map-controls { position: absolute; z-index: 500; top: 14px; right: 14px; display: grid; gap: 6px; }
.map-control {
  width: 44px;
  height: 44px;
  border: 1px solid #cbd5cd;
  border-radius: 9px;
  background: #fff;
  color: var(--brand);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.12);
  transition: background 0.15s ease, color 0.15s ease;
}
.map-control:hover { background: #f2f7f4; color: var(--brand-deep); }

.map-status {
  position: absolute;
  z-index: 500;
  left: 14px;
  top: 14px;
  max-width: min(72%, 430px);
  margin: 0;
  padding: 9px 13px;
  border: 1px solid #d8ded8;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
}
.map[data-state="loading"] .map-status::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border: 2px solid #b9cdc2;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: map-spin 0.8s linear infinite;
}
.map[data-state="error"] .map-status { color: var(--danger); border-color: #d99; }
.map[data-state="success"] .map-status { color: var(--brand-deep); border-color: #c6dccf; }
@keyframes map-spin { to { transform: rotate(360deg); } }

/* --- Legenda: canto inferior esquerdo, nunca cobre controles/atribuição --- */
.map-legend {
  position: absolute;
  z-index: 450;
  left: 14px;
  bottom: 14px;
  width: min(260px, calc(100% - 150px));
  max-height: 40%;
  overflow: auto;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid #d8ded8;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.map-legend[hidden] { display: none; }
.map-legend h2 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--ink-muted); }
.map-legend ul { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.map-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr); align-items: center; column-gap: 8px; font-size: 12px; color: var(--ink-soft); }
.map-legend li small { grid-column: 2; color: var(--ink-faint); font-size: 10px; font-variant-numeric: tabular-nums; }
.map-legend .legend-swatch { width: 10px; height: 10px; border-radius: 3px; }

.leaflet-control-attribution { font-size: 10px; }
.leaflet-control-scale-line { font-size: 10px; }

/* --- Painel de camadas --- */
.layer-panel { padding: 18px; }
.layer-panel[data-state="loading"] { opacity: 1; }

.layer-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.layer-panel-heading > div { min-width: 0; }
.layer-panel-heading .eyebrow { margin: 0 0 4px; font-size: 10px; }
.layer-panel-heading h2 { margin: 0; font-size: 17px; }
.layer-panel-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.layer-count, .layer-group-count {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #5f7068;
  background: #f1f4ef;
  border: 1px solid var(--line-soft);
  border-radius: 99px;
  padding: 4px 9px;
  white-space: nowrap;
}

.ghost-btn {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--brand-ink);
  font: 600 12px/1 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.ghost-btn:hover { background: #f4f8f5; border-color: #b9cdc2; }

/* Skeleton enquanto o catálogo carrega */
.layer-skeleton { display: grid; gap: 10px; padding: 6px 2px; }
.layer-skeleton .sk {
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(90deg, #eef1eb 25%, #f7f9f4 50%, #eef1eb 75%);
  background-size: 200% 100%;
  animation: sk-slide 1.3s ease infinite;
}
.layer-skeleton .sk:nth-child(2) { width: 82%; }
.layer-skeleton .sk:nth-child(3) { width: 68%; }
@keyframes sk-slide { to { background-position: -200% 0; } }

/* Grupos (fonte/categoria) */
.layer-group { border-top: 1px solid var(--line-soft); }
.layer-group:first-child { border-top: 0; }
.layer-group summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  color: #344b42;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 2px;
}
.layer-group summary::-webkit-details-marker { display: none; }
.layer-group summary::after {
  content: "";
  order: -1;
  flex: none;
  width: 8px;
  height: 8px;
  border-right: 2px solid #819087;
  border-bottom: 2px solid #819087;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.16s ease;
}
.layer-group[open] summary::after { transform: rotate(225deg) translateY(-1px); }
.layer-group-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.3;
}
.layer-group summary .layer-group-count { flex: none; margin-left: auto; }
.layer-group-items { padding: 0 0 8px; min-width: 0; }

/* Linhas de camada */
.layer-row {
  min-height: 44px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  min-width: 0;
}
.layer-row:hover { background: #f6f8f4; }
.layer-row[data-state="error"] { background: var(--danger-bg); }
.layer-row[data-state="idle"] .layer-state { color: transparent; }

.layer-choice {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  min-width: 0;
  cursor: pointer;
  color: #344b42;
  font-size: 13px;
  font-weight: 600;
}
.layer-choice input { width: 17px; height: 17px; margin: 0; accent-color: var(--brand); flex: none; cursor: pointer; }
.layer-choice:focus-within { outline: 2px solid #316b58; outline-offset: 2px; border-radius: 6px; }

.layer-swatch, .legend-swatch {
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 4px;
  background: var(--layer-color);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.layer-label { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; line-height: 1.3; }

.feature-count {
  flex: none;
  margin-left: auto;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2ec;
  color: #46594e;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.layer-state {
  grid-column: 1;
  grid-row: 2;
  min-height: 16px;
  padding: 1px 0 0 50px;
  color: #748079;
  font-size: 11px;
  line-height: 1.4;
}
.layer-row[data-state="loading"] .layer-state::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border: 2px solid #c3d2c8;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: map-spin 0.8s linear infinite;
  vertical-align: -1px;
}
.layer-row[data-state="error"] .layer-state { color: var(--danger); }
.layer-row[data-state="empty"] .layer-state { color: var(--ink-faint); }

.layer-retry {
  grid-column: 2;
  grid-row: 1 / 3;
  min-height: 44px;
  border: 1px solid #cbd8ce;
  border-radius: 7px;
  background: #fff;
  color: var(--brand-ink);
  padding: 0 10px;
  font: 600 11px/1 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  cursor: pointer;
}
.layer-retry:hover { background: #f4f8f5; }
.layer-retry[hidden] { display: none; }

/* Camada declarada mas não ingerida — estado honesto, não clicável */
.layer-row-pending { color: #52645a; }
.layer-row-pending:hover { background: transparent; }
.layer-row-pending .layer-choice { cursor: not-allowed; }
.layer-row-pending .layer-label, .layer-row-pending .feature-count { opacity: 0.55; }
.layer-row-pending .layer-swatch {
  background: transparent;
  border: 1.5px dashed #a9b6ac;
  box-shadow: none;
  opacity: 0.8;
}
.layer-row-pending .layer-state { padding-left: 23px; }
.pending-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.pending-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c9a227;
  flex: none;
}

/* Estados de erro/vazio do painel de camadas */
.layer-panel .panel-error, .layer-panel .panel-empty {
  padding: 22px 14px;
  text-align: center;
  color: var(--ink-muted);
}
.layer-panel .panel-error h3, .layer-panel .panel-empty h3 { margin: 0 0 6px; font-size: 14px; color: var(--ink-soft); }
.layer-panel .panel-error p, .layer-panel .panel-empty p { margin: 0 0 14px; font-size: 12px; line-height: 1.5; }
.layer-panel .panel-error { color: var(--danger); }
.layer-panel .panel-error h3 { color: var(--danger); }

/* Focus rings consistentes */
.layer-group summary:focus-visible,
.map-control:focus-visible,
.layer-retry:focus-visible,
.ghost-btn:focus-visible,
.layer-choice:focus-within {
  outline: 3px solid rgba(40, 120, 165, 0.6);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Mobile / telas estreitas ---------- */
@media (max-width: 720px) {
  .app-page { padding: 18px 14px 32px; }
  .app-head { margin-bottom: 14px; gap: 8px; }
  .app-head h1 { font-size: 24px; }
  .app-head .lead { font-size: 13px; max-width: none; }

  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .map-column { position: relative; top: auto; order: -1; }
  .map { height: 54vh; min-height: 340px; max-height: 480px; }

  .layer-sidebar { position: static; max-height: none; overflow: visible; scrollbar-gutter: auto; padding-right: 0; }

  .app-page .panel { padding: 16px; }
  .layer-panel-heading { align-items: flex-start; }

  .map-status { max-width: calc(100% - 78px); font-size: 12px; }
  .map-legend { left: 10px; bottom: 10px; width: min(220px, calc(100% - 20px)); max-height: 34%; }

}
