/* ==========================================================================
   GisMap GovTech Design System v4
   Paleta Prefeitura / GIS corporativo (light-first + dark)
   Stack real: HTML/CSS/JS (não React) — aparência alinhada à especificação
   ========================================================================== */

:root,
html[data-theme='light'] {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-soft: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, 0.12);
  --warn: #ea580c;
  --warn-soft: rgba(234, 88, 12, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 4px 16px rgba(15, 23, 42, 0.06);
  --font:
    'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont,
    sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --header-h: 72px;
  --sidebar-w: 280px;
  --sidebar-collapsed: 72px;
  color-scheme: light;
}

html[data-theme='dark'] {
  --bg: #0f172a;
  --bg-elevated: #111827;
  --surface: #1e293b;
  --surface-2: #243044;
  --surface-3: #334155;
  --border: #334155;
  --border-strong: #475569;
  --border-soft: rgba(51, 65, 85, 0.65);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.12);
  --warn: #fb923c;
  --warn-soft: rgba(251, 146, 60, 0.12);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.22);
  color-scheme: dark;
}

body {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
}

/* —— Header 72px —— */
.top {
  min-height: var(--header-h);
  height: auto;
  padding: 0.75rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px) saturate(1.15);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}
.logo {
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}
.sub {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, #3b82f6 0%, #2563eb 55%, #0f172a 100%);
}

/* —— Sidebar 280px —— */
.dash-shell {
  display: flex;
  min-height: calc(100dvh - var(--header-h));
  background: var(--bg);
}
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  box-shadow: var(--shadow-sm);
}
.sidebar-brand {
  padding: 1.15rem 1.15rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-title {
  display: block;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-brand-sub {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.35;
}
.sidebar-head {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-nav {
  flex: 1 1 auto;
  padding: 0.65rem 0.65rem 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.sidebar-nav .nav-tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  margin: 0;
  padding: 0.7rem 0.85rem 0.7rem 1rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: left;
  line-height: 1.3;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
  box-shadow: none;
}
.sidebar-nav .nav-tab::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  transition: height 0.2s ease;
}
.sidebar-nav .nav-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sidebar-nav .nav-tab.active,
.sidebar-nav .nav-tab[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.sidebar-nav .nav-tab.active::before,
.sidebar-nav .nav-tab[aria-current='page']::before {
  height: 60%;
}
.sidebar-nav .nav-tab .nav-ico {
  flex: 0 0 1.25rem;
  width: 1.25rem;
  text-align: center;
  opacity: 0.9;
  font-size: 1rem;
}
.sidebar-section-label {
  margin: 0.85rem 0.5rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.sidebar-nav .nav-tab.is-soon {
  opacity: 0.55;
  cursor: not-allowed;
}
.sidebar-foot {
  padding: 0.85rem 1.1rem 1.1rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted);
}
.dash-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 1.15rem 1.35rem 2rem;
  max-width: none;
}
.page-header {
  margin-bottom: 1.1rem;
  padding-bottom: 0.95rem;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}
.page-kicker {
  color: var(--accent);
  font-weight: 700;
}

/* —— Cards —— */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 25%, var(--border));
}
.card h2,
.section-label {
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* —— Dashboard hero —— */
.dash-hero {
  position: relative;
  overflow: hidden;
  padding: 1.35rem 1.5rem 1.4rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    radial-gradient(
      600px 240px at 100% 0%,
      rgba(37, 99, 235, 0.16),
      transparent 55%
    ),
    radial-gradient(
      400px 200px at 0% 100%,
      rgba(15, 23, 42, 0.06),
      transparent 50%
    ),
    var(--surface);
  box-shadow: var(--shadow-sm);
}
.dash-hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.dash-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.dash-badge.is-online {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--border));
  background: var(--ok-soft);
}
.dash-badge.is-online::before {
  content: '';
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}
.dash-hero h2 {
  margin: 0 0 0.45rem;
  font-size: clamp(1.25rem, 2.4vw, 1.65rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.25;
  color: var(--text);
  text-transform: none;
}
.dash-hero p {
  margin: 0 0 1rem;
  max-width: 40rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}
.dash-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.dash-hero-actions .btn-primary,
.dash-hero-actions .ghost {
  margin-top: 0;
  min-height: 2.5rem;
  padding: 0.55rem 1.1rem;
  font-weight: 700;
  border-radius: 10px;
  transition:
    background 0.2s ease,
    transform 0.15s ease,
    box-shadow 0.2s ease;
}
.dash-hero-actions .btn-primary:hover {
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
  transform: translateY(-1px);
}

/* KPIs */
.kpi-grid {
  gap: 0.85rem;
}
.kpi-grid .card.kpi {
  position: relative;
  padding: 1.1rem 1.15rem;
  border-radius: 12px;
  overflow: hidden;
}
.kpi-grid .card.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
}
.kpi .kpi-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.kpi .num {
  font-weight: 800;
  font-size: clamp(1.55rem, 2.5vw, 1.9rem);
  letter-spacing: -0.03em;
  color: var(--text);
  margin: 0.35rem 0 0.25rem;
  line-height: 1.15;
}
.kpi-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Buttons */
button.btn-primary,
.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 10px;
}
button.btn-primary:hover,
.btn-primary:hover {
  background: var(--accent-hover);
}
button.ghost {
  border-radius: 10px;
  font-weight: 600;
}

/* Map feature panel — janela de lote GovTech */
#panel-map .map-feature-panel {
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
  padding: 1rem 1.05rem;
}
#panel-map .map-feature-title {
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
}
#panel-map .map-feature-insc {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}
#panel-map .map-feature-actions .btn-sm {
  border-radius: 10px;
  font-weight: 700;
}
#panel-map .map-basemap-row,
#panel-map .map-layer-toggles {
  border-radius: 12px;
}

/* Pop-up GIS */
.leaflet-container .leaflet-popup-content-wrapper {
  border-radius: 14px !important;
  border: 1px solid var(--border) !important;
  background: var(--surface) !important;
  box-shadow: var(--shadow) !important;
}
.gis-popup-title {
  color: var(--text) !important;
}
.gis-popup-v {
  color: var(--text) !important;
}
.gis-popup-btn.is-primary {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}

/* Login */
.login-shell {
  max-width: 1040px;
}
.login-card {
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-hero-title {
  font-weight: 800;
  letter-spacing: -0.03em;
}

/* Tables */
.data-table thead th {
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  color: var(--muted);
}

/* Transitions */
.tab-panel {
  animation: gov-fade 0.2s ease both;
}
@keyframes gov-fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .tab-panel,
  .kpi-grid .card.kpi,
  .sidebar-nav .nav-tab {
    transition: none !important;
    animation: none !important;
  }
}

/* Responsive shell */
@media (max-width: 900px) {
  .sidebar {
    width: min(var(--sidebar-w), 86vw);
    min-width: 0;
    max-width: min(var(--sidebar-w), 86vw);
  }
  .dash-main {
    padding: 0.85rem 0.85rem 1.5rem;
  }
  .dash-hero {
    padding: 1.1rem 1.05rem;
  }
}
@media (max-width: 800px) {
  .dash-shell {
    display: block;
  }
}
/* Painel “Lote selecionado” — GovTech */
.map-lot-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.map-lot-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
}
.map-lot-card-titles {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
}
.map-lot-kicker {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #64748b);
}
.map-lot-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.map-lot-status-badge.is-active {
  color: var(--ok, #16a34a);
  background: var(--ok-soft, rgba(22, 163, 74, 0.12));
  border-color: color-mix(in srgb, var(--ok, #16a34a) 35%, var(--border));
}
.map-lot-status-badge.is-build {
  color: var(--accent, #2563eb);
  background: var(--accent-soft, rgba(37, 99, 235, 0.12));
  border-color: color-mix(in srgb, var(--accent, #2563eb) 35%, var(--border));
}
.map-lot-layer-chip {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
}
.map-lot-highlights {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin: 0.15rem 0 0.35rem;
}
.map-lot-hi {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  min-width: 0;
}
.map-lot-hi-k {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.3;
  word-break: break-word;
}
.map-lot-hi-v {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  word-break: normal;
  overflow-wrap: break-word;
}
.map-lot-hi-v.mono {
  font-family: var(--font-mono, ui-monospace, monospace);
  white-space: nowrap;
  overflow-x: auto;
  max-width: 100%;
}
.map-lot-actions {
  margin-top: 0.35rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}
.map-lot-actions .btn-primary {
  flex: 1 1 100%;
  order: -1;
  font-weight: 700;
}
#map-feature-find-ficha.is-linked {
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.gis-popup-kicker {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #64748b);
  margin: 0 0 0.15rem;
}
.gis-popup-status {
  display: inline-flex;
  align-items: center;
  margin-top: 0.2rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.gis-popup-status.is-active {
  color: var(--ok, #16a34a);
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--border));
}
.gis-popup-status.is-build {
  color: var(--accent, #2563eb);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
@media (max-width: 520px) {
  .map-lot-highlights {
    grid-template-columns: 1fr;
  }
  .map-lot-actions .btn-sm {
    flex: 1 1 100%;
  }
}
/* Skill.md — dashboard inteligente + ferramentas mapa + assistente */
.smart-insights {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
  gap: 0.85rem;
  margin: 0 0 1rem;
}
.smart-card {
  margin: 0;
  padding: 1rem 1.1rem;
}
.smart-card-title {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.smart-card-value {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 750;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
}
.dash-mini-map {
  height: 160px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}
.map-opacity-ctrl {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 7.5rem;
  margin: 0;
  font-weight: 600;
}
.map-opacity-ctrl input[type='range'] {
  width: 100%;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}
.map-measure-status {
  margin: 0 0 0.5rem;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  color: var(--text);
  font-weight: 600;
}
.map-measure-status.hidden {
  display: none !important;
}
#btn-map-measure-dist.is-active-tool,
#btn-map-measure-area.is-active-tool {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.gis-assistant {
  margin: 0.65rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.gis-assistant.hidden {
  display: none !important;
}
.gis-assistant-list {
  margin: 0;
  padding: 0 0 0 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.gis-assistant-item {
  line-height: 1.45;
  word-break: break-word;
  font-size: 0.88rem;
}
.gis-assistant-item.is-ok {
  color: var(--ok);
}
.gis-assistant-item.is-info {
  color: var(--text);
}
.gis-assistant-item.is-warn {
  color: var(--warn);
}
.gis-assistant-item.is-alert {
  color: var(--danger);
  font-weight: 650;
}
/* Glass header sutil (skill.md §8) */
.top {
  background: color-mix(in srgb, var(--surface) 78%, transparent) !important;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
}
/* Dark map panes */
html[data-theme='dark'] .leaflet-container {
  background: #0f172a;
}
html[data-theme='dark'] .map-box {
  background: #0f172a;
}
html[data-theme='dark'] .dash-mini-map {
  background: #111827;
}
/* skill-1: mapa workspace full + export hub + sticky table */
#panel-map.map-workspace-panel {
  margin: 0;
  padding: 0;
  /* Não cobrir header/page-header: altura da área útil do dash-main */
  height: calc(100dvh - var(--header-h, 72px) - 7.5rem);
  max-height: calc(100dvh - var(--header-h, 72px) - 7.5rem);
  display: flex;
  flex-direction: column;
  min-height: 360px;
  position: relative;
  z-index: 1;
}
.page-header {
  position: relative;
  z-index: 40;
}
.nav-drawer-open {
  position: relative;
  z-index: 45;
}
#panel-map.map-workspace-panel.hidden {
  display: none !important;
}
.map-workspace {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.map-layers-drawer {
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem;
  overflow: auto;
  transition:
    width 0.2s ease,
    min-width 0.2s ease,
    padding 0.2s ease,
    opacity 0.2s ease;
}
.map-workspace.is-layers-collapsed .map-layers-drawer {
  width: 0;
  min-width: 0;
  max-width: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  border: none;
}
.map-layers-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.map-layers-drawer-head strong {
  font-weight: 800;
  letter-spacing: -0.02em;
}
.map-drawer-intro {
  margin: 0;
  line-height: 1.4;
}
.map-workspace-main {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.map-layout-workspace {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  margin: 0;
  gap: 0;
}
.map-layout-workspace.has-side {
  grid-template-columns: 1fr minmax(260px, 320px);
}
.map-layout-workspace .map-stage {
  min-height: 0;
  height: 100%;
  border: none;
  border-radius: 0;
}
.map-box-workspace,
#panel-map .map-box.map-box-tab {
  height: 100% !important;
  min-height: 100% !important;
  max-height: none !important;
  border-radius: 0 !important;
}
.map-float-search {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  width: min(420px, calc(100% - 5.5rem));
}
.map-float-search-input {
  width: 100%;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  font-weight: 500;
}
.map-v-toolbar {
  position: absolute;
  top: 0.75rem;
  left: 0.65rem;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: calc(100% - 5rem);
  overflow: auto;
  padding: 0.35rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}
.map-v-btn {
  width: 2.45rem;
  height: 2.45rem;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
  box-shadow: none;
}
.map-v-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  color: var(--accent);
}
.map-v-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.map-v-btn.is-active-tool {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.map-layers-fab {
  position: absolute;
  top: 0.75rem;
  left: 0.65rem;
  z-index: 510;
  margin: 0;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.map-minimap {
  position: absolute;
  right: 0.75rem;
  bottom: 2.6rem;
  width: 140px;
  height: 110px;
  z-index: 450;
  border-radius: 12px;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  background: var(--surface-2);
}
.map-workspace-meta {
  position: absolute;
  left: 0.65rem;
  bottom: 0.35rem;
  z-index: 440;
  margin: 0 !important;
  max-width: min(70%, 28rem);
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  font-size: 0.75rem;
}
/* Export hub */
.export-hub-panel {
  max-width: min(720px, 96vw);
}
.export-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}
.export-hub-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  margin: 0;
  padding: 1rem 0.9rem;
  text-align: left;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  box-shadow: none;
  min-height: 7.5rem;
  transition:
    border-color 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
}
.export-hub-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
  background: var(--surface);
}
.export-hub-ext {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}
.export-hub-card strong {
  font-size: 0.95rem;
  font-weight: 750;
}
.export-hub-note {
  margin: 0.25rem 0 0;
  line-height: 1.45;
}
/* Sticky table cols + hover actions */
#fichas-table th:nth-child(1),
#fichas-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
}
#fichas-table th:nth-child(3),
#fichas-table td:nth-child(3) {
  position: sticky;
  left: 3.2rem;
  z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
}
#fichas-table thead th:nth-child(1),
#fichas-table thead th:nth-child(3) {
  background: var(--surface-2);
  z-index: 3;
}
#fichas-table tbody tr:hover .td-actions-hover {
  opacity: 1;
}
#fichas-table .td-actions-hover {
  opacity: 0.92;
  transition: opacity 0.15s ease;
}
@media (hover: hover) {
  #fichas-table .td-actions-hover {
    opacity: 0.55;
  }
  #fichas-table tbody tr:hover .td-actions-hover,
  #fichas-table tbody tr:focus-within .td-actions-hover {
    opacity: 1;
  }
}
@media (max-width: 900px) {
  .map-layers-drawer {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 25; /* abaixo do page-header (40) */
    box-shadow: var(--shadow);
  }
  .map-float-search,
  .map-v-toolbar,
  .map-layers-fab {
    z-index: 20;
  }
  .map-workspace.is-layers-collapsed .map-layers-fab {
    display: inline-flex !important;
  }
  .map-minimap {
    width: 110px;
    height: 88px;
    z-index: 15;
  }
  .map-v-toolbar {
    max-height: 50%;
  }
  #panel-map.map-workspace-panel {
    height: calc(100dvh - var(--header-h, 72px) - 9rem);
    max-height: calc(100dvh - var(--header-h, 72px) - 9rem);
  }
}

/* ========== skill-2: plataforma territorial (sem inventar dados) ========== */
.quality-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.quality-limits {
  margin: 0.5rem 0 0;
  padding-left: 1.15rem;
  line-height: 1.55;
}
.map-layer-smart,
.map-workspace-presets {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}
.map-smart-lead {
  margin: 0;
}
.map-workspace-preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
#map-workspace-select,
#map-area-min {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.map-float-search {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  width: min(420px, calc(100% - 5.5rem));
}
.map-float-search-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  font: inherit;
}
.map-float-results {
  margin-top: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.map-float-results.hidden {
  display: none !important;
}
.map-float-hit {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.map-float-hit:hover,
.map-float-hit:focus-visible {
  background: color-mix(in srgb, var(--primary, #2563eb) 10%, transparent);
  outline: none;
}
.map-float-hit-title {
  font-weight: 700;
}
.map-float-empty {
  padding: 0.65rem 0.75rem;
}
.map-hud {
  position: absolute;
  top: 0.75rem;
  right: 3.25rem;
  z-index: 21;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  max-width: min(320px, 42vw);
  pointer-events: none;
}
.map-hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.1rem;
  padding: 0.3rem 0.45rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
}
.map-hud-n {
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.map-hud-l {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.map-gps-label {
  background: transparent !important;
  border: 0 !important;
}
.map-gps-label-text {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
body.map-productivity .sidebar,
body.map-productivity .page-header,
body.map-productivity .toolbar,
body.map-productivity .toolbar-hint,
body.map-productivity .footer,
body.map-productivity #offline-banner:not(.hidden) {
  display: none !important;
}
body.map-productivity .dash-shell {
  grid-template-columns: 1fr !important;
}
body.map-productivity .dash-main {
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
}
body.map-productivity #panel-map.map-workspace-panel {
  height: 100dvh !important;
  max-height: 100dvh !important;
  border-radius: 0;
}
body.map-productivity .map-workspace {
  border-radius: 0;
  border: 0;
}
body.map-productivity .top {
  position: fixed;
  top: 0;
  right: 0;
  left: auto;
  width: auto;
  z-index: 60;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border-bottom: 0;
  border-radius: 0 0 0 12px;
  padding: 0.35rem 0.5rem;
  box-shadow: var(--shadow-sm);
}
.activity-panel {
  width: min(480px, 96vw);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
}
.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1 1 auto;
  max-height: 50vh;
}
.activity-item {
  padding: 0.55rem 0.15rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.35;
}
.activity-item.is-ok {
  border-left: 3px solid #16a34a;
  padding-left: 0.5rem;
}
.activity-item.is-err {
  border-left: 3px solid #dc2626;
  padding-left: 0.5rem;
}
.activity-item.is-info {
  border-left: 3px solid #2563eb;
  padding-left: 0.5rem;
}
.activity-when {
  display: inline-block;
  min-width: 4.2rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}
#activity-header-count.badge-count,
#favs-header-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.export-hub-history {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.export-hub-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow: auto;
}
.export-hub-history-list li {
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--border);
}
.sidebar-section-label {
  margin: 0.85rem 0 0.35rem;
  padding: 0 0.35rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
@media (max-width: 900px) {
  .map-hud {
    top: auto;
    bottom: 5.5rem;
    right: 0.5rem;
    left: 0.5rem;
    max-width: none;
    justify-content: flex-start;
  }
  .map-float-search {
    left: 0.5rem;
    right: 3rem;
    width: auto;
    transform: none;
  }
}

/* ========== Melhorias parciais + bugs (2026-07-17) ========== */
.col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 2;
}
.th-resizable {
  position: relative;
}
body.col-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.col-resizing * {
  cursor: col-resize !important;
}
#fichas-table.data-table-resizable {
  table-layout: fixed;
}
#fichas-table.data-table-resizable th,
#fichas-table.data-table-resizable td {
  overflow: hidden;
  text-overflow: ellipsis;
}
.map-stage.has-dual {
  display: block !important;
  position: relative;
}
.map-stage.has-dual .map-box-workspace {
  width: 50% !important;
  height: 100%;
  float: left;
}
.map-stage.has-dual .map-dual-wrap {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  height: 100%;
  min-height: 0;
}
.map-stage.has-dual .map-minimap {
  left: 0.5rem;
  /* fica só sobre o mapa principal (metade esquerda) */
  max-width: 40%;
}
.map-stage.has-dual .map-legend {
  max-width: min(46%, 18rem);
}
.map-dual-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
  border-left: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  z-index: 2;
}
.map-dual-wrap.hidden {
  display: none !important;
}
.map-dual-box {
  flex: 1 1 auto;
  min-height: 200px;
  height: 100%;
  width: 100%;
}
.map-dual-hint {
  margin: 0;
  padding: 0.25rem 0.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  line-height: 1.3;
}
.map-v-btn.is-active-tool {
  background: color-mix(in srgb, var(--primary, #2563eb) 22%, transparent);
  border-color: var(--primary, #2563eb);
  color: var(--primary, #2563eb);
}
@media (max-width: 900px) {
  .map-stage.has-dual {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .map-dual-wrap {
    border-left: 0;
    border-top: 2px solid var(--border);
    min-height: 180px;
  }
}

/* multi-sort: coluna secund�ria */
#fichas-table th.th-sortable.sort-secondary {
  box-shadow: inset 0 -2px 0 0
    color-mix(in srgb, var(--primary, #2563eb) 55%, transparent);
}
#fichas-table th.th-sortable.sort-secondary::after {
  content: ' 2';
  font-size: 0.65em;
  font-weight: 800;
  opacity: 0.75;
  vertical-align: super;
}
.map-perf-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}
tr.page-search-hide {
  display: none !important;
}
.export-hub-count {
  display: block;
  margin-top: 0.25rem;
  font-weight: 600;
}
#f-page-search {
  min-width: 8rem;
  max-width: 11rem;
}

/* GovTech v5: superfície operacional final. */
:root,
html[data-theme='light'] {
  --bg: #f5f7f8;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f4f5;
  --surface-3: #e7ebed;
  --border: #d9dfe2;
  --border-strong: #b8c2c7;
  --border-soft: #edf0f1;
  --text: #182024;
  --text-muted: #5f6d74;
  --muted: #5f6d74;
  --accent: #245fbd;
  --accent-hover: #194b99;
  --accent-soft: rgba(36, 95, 189, 0.1);
  --ok: #16834b;
  --ok-soft: rgba(22, 131, 75, 0.1);
  --warn: #b65d09;
  --warn-soft: rgba(182, 93, 9, 0.1);
  --danger: #b52b32;
  --danger-soft: rgba(181, 43, 50, 0.1);
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(24, 32, 36, 0.09);
  --shadow-sm: 0 2px 8px rgba(24, 32, 36, 0.06);
  --sidebar-w: 260px;
}

html[data-theme='dark'] {
  --bg: #141718;
  --bg-elevated: #1a1e20;
  --surface: #1d2224;
  --surface-2: #252b2e;
  --surface-3: #30383b;
  --border: #394246;
  --border-strong: #526066;
  --border-soft: #2b3235;
  --text: #f3f5f5;
  --text-muted: #a7b1b5;
  --muted: #a7b1b5;
  --accent: #6b9fe8;
  --accent-hover: #8ab5ef;
  --accent-soft: rgba(107, 159, 232, 0.14);
  --ok: #58bd82;
  --ok-soft: rgba(88, 189, 130, 0.13);
  --warn: #e6a14d;
  --warn-soft: rgba(230, 161, 77, 0.13);
  --danger: #ef7a80;
  --danger-soft: rgba(239, 122, 128, 0.13);
}

*,
*::before,
*::after {
  letter-spacing: 0 !important;
}

.top {
  background: var(--surface) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none;
}
.brand-mark {
  border-radius: 8px;
  background: var(--accent);
  box-shadow: none;
}
.sidebar {
  box-shadow: none;
}
.sidebar-nav .nav-tab {
  border-radius: 6px;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}
.sidebar-nav .nav-tab::before {
  border-radius: 0 2px 2px 0;
}

.card {
  border-radius: 8px;
  box-shadow: none;
  transition: border-color 0.15s ease;
}
.card:hover {
  box-shadow: none;
  transform: none;
}
.panel-intro.card {
  padding: 0.2rem 0 0.85rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
}
.dash-hero {
  padding: 1.1rem 0 1.2rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.dash-hero h2 {
  font-size: 1.55rem;
}
.kpi-grid .card.kpi {
  border-radius: 8px;
}
.kpi-grid .card.kpi:hover {
  transform: none;
  box-shadow: none;
}
.kpi .num {
  font-size: 1.8rem;
}

button,
button.btn-primary,
.btn-primary,
button.ghost,
.quick-btn,
.dash-hero-actions .btn-primary,
.dash-hero-actions .ghost,
.map-lot-hi,
#panel-map .map-feature-panel,
#panel-map .map-basemap-row,
#panel-map .map-layer-toggles,
.login-card,
.leaflet-container .leaflet-popup-content-wrapper {
  border-radius: 6px !important;
}
button.btn-primary:hover,
.btn-primary:hover,
.dash-hero-actions .btn-primary:hover {
  box-shadow: none;
  transform: none;
}
input,
select,
textarea {
  border-radius: 6px;
}
.data-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: none;
}
.data-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
.map-float-search-input,
.map-v-toolbar {
  border-radius: 6px;
  background: var(--surface);
  backdrop-filter: none;
}

@media (max-width: 800px) {
  .dash-main {
    padding: 0.75rem 0.7rem 1.35rem;
  }
  .dash-hero h2 {
    font-size: 1.35rem;
  }
  .kpi .num {
    font-size: 1.55rem;
  }
}

/* Mapa operacional: área útil integral e uma única inspeção lateral. */
.modal-panel-detail {
  width: min(1180px, 98vw);
  max-width: min(1180px, 98vw);
}
body.map-tab-active main {
  max-width: none;
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}
body.map-tab-active .dash-shell {
  margin: 0;
  width: 100%;
}
body.map-tab-active .dash-main {
  width: 100%;
  padding-left: 1rem;
  padding-right: 0;
}
body.map-tab-active .map-workspace {
  border-radius: 6px;
  box-shadow: none;
}
body.map-tab-active .map-layers-drawer {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
}
body.map-tab-active .map-layout-workspace.has-side,
body.map-tab-active .map-layout-workspace.has-both-sides {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
}
body.map-tab-active .map-fichas-list-panel,
body.map-tab-active .map-feature-panel {
  height: 100%;
  max-height: none !important;
  overflow: auto;
  border-left: 1px solid var(--border);
  border-radius: 0 !important;
  box-shadow: none;
}
body.map-tab-active .map-v-toolbar {
  display: grid;
  grid-template-columns: repeat(2, 2.35rem);
  gap: 0.25rem;
  max-height: calc(100% - 5.5rem);
  padding: 0.3rem;
  overflow-y: auto;
}
body.map-tab-active .map-v-btn {
  width: 2.35rem;
  height: 2.35rem;
  overflow: hidden;
  white-space: nowrap;
}
body.map-tab-active .map-float-search {
  width: min(460px, calc(100% - 15rem));
}
body.map-tab-active .map-hud-item,
body.map-tab-active .map-workspace-meta,
body.map-tab-active .map-float-search-input {
  border-radius: 6px;
  background: var(--surface);
  backdrop-filter: none;
}
@media (max-width: 1100px) {
  body.map-tab-active .dash-main {
    padding-left: 0.5rem;
  }
  body.map-tab-active .map-layers-drawer {
    width: min(82vw, 300px);
    min-width: min(82vw, 300px);
    max-width: min(82vw, 300px);
  }
  body.map-tab-active .map-float-search {
    left: 6.25rem;
    right: 0.5rem;
    width: auto;
    transform: none;
  }
}
@media (max-width: 800px) {
  body.map-tab-active main,
  body.map-tab-active .dash-main {
    padding-left: max(0.35rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.35rem, env(safe-area-inset-right, 0px));
  }
  body.map-tab-active .map-layout-workspace.has-side,
  body.map-tab-active .map-layout-workspace.has-both-sides {
    grid-template-columns: 1fr;
  }
  body.map-tab-active .map-fichas-list-panel,
  body.map-tab-active .map-feature-panel {
    height: auto;
    max-height: min(40dvh, 320px) !important;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  body.map-tab-active .toolbar.toolbar-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }
  body.map-tab-active .toolbar > .toolbar-group:first-child {
    display: contents;
  }
  body.map-tab-active .toolbar-exports {
    grid-column: 1 / -1;
    width: 100%;
  }
  body.map-tab-active .toolbar-exports .toolbar-label,
  body.map-tab-active .toolbar-exports #btn-export,
  body.map-tab-active .toolbar-exports #btn-export-xls,
  body.map-tab-active .toolbar-exports .toolbar-exports-more {
    display: none;
  }
  body.map-tab-active #btn-export-hub {
    width: 100%;
  }
}
@media (max-width: 420px) {
  .tb-label-full {
    display: none !important;
  }
  .tb-label-short {
    display: inline !important;
  }
}

/* Evita que regras de grid ampliem labels acessíveis e criem overflow global. */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Fichas: as visoes salvas ocupam uma linha propria dentro das acoes flexiveis. */
#panel-fichas .filter-actions-secondary .saved-filter-controls {
  flex: 1 0 100%;
  max-width: 100%;
}

#panel-fichas .saved-filter-controls button {
  white-space: nowrap;
}

/* WCAG AA: tokens de primeiro plano separados das cores de ação/branding. */
:root,
html[data-theme='light'] {
  --accent-fg: #194b99;
  --ok-fg: #0b6b3a;
}

html[data-theme='dark'] {
  --accent-fg: #8ab5ef;
  --ok-fg: #75d69b;
}

.page-kicker,
.sidebar-nav .nav-tab.active,
.sidebar-nav .nav-tab[aria-current='page'] {
  color: var(--accent-fg);
}

.dash-badge.is-online {
  color: var(--ok-fg);
}

.last-refresh,
.user-badge-tenant,
.profile-caps-count {
  opacity: 1;
}

html[data-theme='light'] .pill-pred {
  color: #065f46;
  background: #d1fae5;
  border-color: #6ee7b7;
}

html[data-theme='light'] .pill-terr,
html[data-theme='light'] .pill-role-admin {
  color: #1e3a8a;
  background: #dbeafe;
  border-color: #93c5fd;
}

html[data-theme='light'] .pill-warn,
html[data-theme='light'] .pill-role-coordinator {
  color: #78350f;
  background: #fef3c7;
  border-color: #fbbf24;
}

html[data-theme='light'] .pill-role-viewer {
  color: #334155;
  background: #e2e8f0;
  border-color: #94a3b8;
}

html[data-theme='light'] .data-table th,
html[data-theme='light'] .list-loading-label {
  color: #4b5960;
  opacity: 1;
}

/* ==========================================================================
   Camada de refinamento (2026-07-19) — acessibilidade e consistência
   Anexada ao final para vencer regras anteriores sem alterar componentes.
   ========================================================================== */

/* 1) Rede de segurança de foco: todo elemento interativo focado por teclado
   recebe um anel visível e consistente (WCAG 2.4.7). Não afeta clique do mouse. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
[role='button']:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 2) Alto contraste: reforça bordas e texto secundário para quem usa
   prefers-contrast: more (não existia antes). */
@media (prefers-contrast: more) {
  :root,
  html[data-theme='light'],
  html[data-theme='dark'] {
    --border: var(--border-strong);
    --muted: var(--text);
  }
  .btn,
  .data-table th,
  .data-table td,
  .card,
  input,
  select,
  textarea {
    border-color: var(--border-strong) !important;
  }
}

/* 3) Movimento reduzido: rede de segurança global (WCAG 2.3.3) — desliga
   animações/transições para quem pediu, mesmo em componentes novos. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 3.5) Componente padrão de estado vazio (B4) — para painéis que ainda usam
   texto simples. Uso: <div class="empty-state"><div class="empty-state-icon">…</div>
   <p class="empty-state-title">…</p><p class="empty-state-hint">…</p>
   <button class="btn btn-sm">Ação</button></div> */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.6rem 1rem;
  text-align: center;
  color: var(--muted);
}
.empty-state-icon {
  font-size: 1.6rem;
  opacity: 0.75;
}
.empty-state-title {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}
.empty-state-hint {
  margin: 0;
  font-size: 0.86rem;
  max-width: 42ch;
}
.empty-state .btn {
  margin-top: 0.5rem;
}

/* 4) Alvos de toque em telas pequenas: garante mínimo ~44px (WCAG 2.5.5)
   para botões/links de ação, melhorando uso em campo (tablet/celular). */
@media (max-width: 640px) {
  .btn,
  .nav-tab,
  .top-actions button,
  .pager button,
  [role='button'] {
    min-height: 44px;
  }
}

/* Layout operacional: corrige rolagens concorrentes e sobreposicoes. */
.dash-shell.sidebar-collapsed .sidebar {
  flex: 0 0 var(--sidebar-collapsed, 72px);
  width: var(--sidebar-collapsed, 72px);
  min-width: var(--sidebar-collapsed, 72px);
  max-width: var(--sidebar-collapsed, 72px);
}
.dash-shell.sidebar-collapsed .sidebar-brand,
.dash-shell.sidebar-collapsed .sidebar-section-label,
.dash-shell.sidebar-collapsed .sidebar-foot {
  display: none;
}
.dash-shell.sidebar-collapsed .sidebar-head {
  justify-content: center;
  padding-inline: 0.35rem;
}
.dash-shell.sidebar-collapsed .sidebar-nav {
  padding-inline: 0.45rem;
  overflow-x: hidden;
}
.dash-shell.sidebar-collapsed .sidebar-nav .nav-tab {
  min-height: 2.75rem;
  padding-inline: 0.35rem;
  font-size: 0.9rem;
  justify-content: center;
}
.dash-shell.sidebar-collapsed .sidebar-nav .nav-tab > span:not(.nav-ico) {
  display: none;
}
.dash-shell.sidebar-collapsed .sidebar-nav .nav-ico {
  flex-basis: auto;
  width: auto;
  font-size: 1rem;
}

#detail-modal {
  overflow: hidden;
}
#detail-modal .modal-panel-detail.card {
  display: flex;
  flex-direction: column;
  width: min(1180px, calc(100vw - 2rem));
  max-width: min(1180px, calc(100vw - 2rem));
  height: min(90dvh, 960px);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow: hidden;
}
#detail-modal .modal-panel-detail > .modal-head {
  position: relative;
  top: auto;
  flex: 0 0 auto;
  margin: 0;
  padding: 1rem 1rem 0.8rem;
  background: var(--surface);
}
#detail-modal .detail-scroll-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.75rem 1rem 1.25rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}
#detail-modal .detail-scroll-body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
#detail-modal .detail-tablist {
  top: 0;
}

body.map-tab-active .map-layers-drawer {
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  contain: layout paint;
}
#panel-map .map-layer-toggles {
  display: block;
  flex: 0 0 auto;
  max-height: none;
  overflow: visible;
  padding: 0;
  border: 0;
  background: transparent;
  min-height: 0;
}
#panel-map .map-layer-group {
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
}
#panel-map .map-layer-group:first-child {
  padding-top: 0;
  border-top: 0;
}
#panel-map .map-layer-group-head {
  margin: 0 0 0.35rem;
}
#panel-map .map-layer-group-chips {
  display: grid;
  gap: 0.3rem;
}
#panel-map .map-layer-group-chips .map-layer-toggle {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  width: 100%;
  min-height: 2.4rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}
#panel-map .map-layer-group-chips .map-layer-toggle:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}
#panel-map .map-layer-label-text {
  min-width: 0;
  overflow-wrap: anywhere;
}
#panel-map .map-layer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}
#panel-map .map-layer-actions .btn-sm {
  min-width: 0;
  margin: 0;
  white-space: normal;
}

body.map-tab-active .map-v-toolbar {
  display: flex;
  grid-template-columns: none;
  width: auto;
  max-height: calc(100% - 5rem);
  overflow: visible;
}
.map-workspace.is-layers-collapsed .map-v-toolbar {
  top: 3.85rem;
  max-height: calc(100% - 8.1rem);
}
body.map-tab-active .map-tools-overflow {
  position: relative;
}
body.map-tab-active .map-tools-overflow > summary {
  list-style: none;
}
body.map-tab-active .map-tools-overflow > summary::-webkit-details-marker {
  display: none;
}
body.map-tab-active .map-tools-overflow[open] > summary {
  border-color: var(--accent);
  background: var(--accent-soft);
}
body.map-tab-active .map-tools-overflow-body {
  position: absolute;
  top: 0;
  left: calc(100% + 0.45rem);
  display: grid;
  grid-template-columns: repeat(3, 2.35rem);
  gap: 0.25rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
body.map-tab-active .map-tools-overflow-body .map-v-btn {
  flex: 0 0 auto;
}
body.map-tab-active:has(.map-layout-workspace.has-side) .map-hud {
  right: calc(340px + 1rem);
}
body.map-tab-active:has(.map-layout-workspace.has-side) .map-float-search {
  left: calc((100% - 340px) / 2);
  width: min(420px, calc(100% - 440px));
}
.map-minimap:not(.is-ready) {
  display: none;
}
body.map-tab-active .map-workspace-meta,
body.map-tab-active .map-orto-status {
  position: static;
  flex: 0 0 auto;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0 !important;
  padding: 0.35rem 0.65rem;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
}
body.map-tab-active .map-orto-status:empty {
  display: none;
}

@media (max-width: 800px) {
  .dash-shell.sidebar-collapsed .sidebar {
    width: min(88vw, 320px);
    min-width: 0;
    max-width: none;
  }
  #detail-modal {
    padding: 0;
  }
  #detail-modal .modal-panel-detail.card {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0 !important;
  }
  #detail-modal .modal-panel-detail > .modal-head {
    padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem 0.65rem;
  }
  #detail-modal .detail-scroll-body {
    padding: 0.65rem 0.75rem max(1rem, env(safe-area-inset-bottom));
  }
  body.map-tab-active:has(.map-layout-workspace.has-side) .map-hud {
    right: 0.5rem;
  }
  body.map-tab-active:has(.map-layout-workspace.has-side) .map-float-search {
    left: 6.25rem;
    right: 0.5rem;
    width: auto;
  }
}
