:root {
  /* Marca */
  --navy: #0a1e36;
  --navy-soft: #16334f;
  --green: #7ed957;
  --green-deep: #6bc845;
  --green-deeper: #58b134;

  /* Superfícies */
  --bg: #f4f6f5;
  --surface: #fff;
  --surface-sunken: #eceff0;
  --border: #dde3e0;
  --border-strong: #c7d0cd;

  /* Texto — tons do navy em vez de cinzas avulsos, pra hierarquia
     ficar consistente com a marca em vez de três cinzas diferentes. */
  --text: #0a1e36;
  --text-muted: #5c6b7a;
  --text-subtle: #8593a0;

  /* Estado */
  --danger: #c0392b;
  --danger-border: #e5c0b9;
  --danger-tint: #fdf4f2;
  --success: #1e7a34;

  /* Elevação — sombras tingidas de navy, não preto puro: preto sobre
     fundo levemente esverdeado suja a cor. */
  --shadow-sm: 0 1px 2px rgba(10, 30, 54, 0.05);
  --shadow-md: 0 2px 10px rgba(10, 30, 54, 0.07);
  --shadow-lg: 0 10px 40px rgba(10, 30, 54, 0.18);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --ring: 0 0 0 3px rgba(126, 217, 87, 0.45);
  --ring-danger: 0 0 0 3px rgba(192, 57, 43, 0.25);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  /* Marcas de seleção e checkbox/radio saem na cor da marca sem precisar
     estilizar cada controle à mão. */
  accent-color: var(--green-deeper);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Foco visível em tudo que recebe teclado. Antes não havia regra nenhuma
   de :focus, então o anel padrão do navegador era a única pista — e ele
   some em cima do verde da marca. :focus-visible, não :focus: o anel
   aparece pra quem navega por teclado sem piscar a cada clique de mouse. */
:focus-visible {
  outline: 2px solid var(--green-deeper);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Movimento é decoração aqui — quem pediu pra reduzir, não recebe. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* --- Login screen --- */

#login-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Gradiente sutil em vez de navy chapado — dá profundidade ao cartão
     sem virar decoração que compete com o formulário. */
  background:
    radial-gradient(circle at 20% 15%, rgba(126, 217, 87, 0.14), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(126, 217, 87, 0.08), transparent 40%),
    var(--navy);
  padding: 24px;
}

#login-form {
  width: min(440px, calc(100vw - 48px));
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 44px 42px 36px;
  box-shadow: var(--shadow-lg);
}

#login-mark {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

#login-form h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.2px;
}

#login-submit {
  width: 100%;
  min-height: 50px;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--green);
  color: var(--navy);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s ease, transform 0.1s ease;
}

#login-submit:hover {
  background: var(--green-deep);
}

#login-submit:active {
  transform: translateY(1px);
}

#login-feedback {
  min-height: 18px;
  font-size: 12px;
  color: var(--danger);
  margin: 8px 0 0;
}

#app {
  display: flex;
  height: 100vh;
  /* dvh accounts for mobile browser chrome (address bar) showing/hiding —
     100vh on a phone is taller than the visible area and gets clipped by
     the overflow:hidden below. Declared after vh so older browsers that
     don't understand dvh keep the vh fallback instead of dropping the rule. */
  height: 100dvh;
  overflow: hidden;
}

#mobile-header,
#nav-backdrop {
  display: none;
}

#nav {
  width: 268px;
  flex-shrink: 0;
  min-height: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 18px 12px 14px;
  overflow-y: auto;
  transition: width 0.2s ease, padding 0.2s ease;
}

#nav-brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  text-align: left;
  line-height: 1.3;
  margin: 0 8px 24px;
  letter-spacing: 0.5px;
}

.nav-brand-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

#nav-collapse {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

#nav-collapse:hover {
  background: rgba(255, 255, 255, 0.16);
}

#nav.is-collapsed {
  width: 78px;
  padding-inline: 10px;
}

#nav.is-collapsed #nav-brand {
  justify-content: center;
  margin-inline: 0;
}

#nav.is-collapsed .nav-brand-identity,
#nav.is-collapsed .nav-label {
  display: none;
}

#nav.is-collapsed .nav-item {
  justify-content: center;
  gap: 0;
  padding-inline: 0;
}

#nav.is-collapsed .nav-icon {
  width: 28px;
}

#nav.is-collapsed .nav-profile {
  justify-content: center;
}

#nav.is-collapsed .avatar {
  margin: 0;
}

#nav-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: block;
}

.nav-item {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 11px;
  margin-bottom: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 16px;
}

.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: var(--green);
  color: var(--navy);
  font-weight: 700;
}

/* Sobre o navy, o anel verde some. Aqui o contraste vem do branco. */
#nav :focus-visible {
  outline-color: #fff;
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-profile {
  margin-top: 10px;
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--green);
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  margin: 0 auto;
  flex-shrink: 0;
}

.view {
  flex: 1;
  display: flex;
  min-width: 0;
  /* Flex items default to min-height:auto, which lets tall content (e.g. a
     fence detail with many bubble/node/offer cards) grow the row past
     #app's 100vh instead of scrolling internally — that's what was dragging
     #nav along with the page scroll. min-height:0 lets each panel's own
     overflow-y:auto do the scrolling instead. */
  min-height: 0;
}

#view-cercas {
  position: relative;
}

#panel {
  width: 300px;
  flex-shrink: 0;
  min-height: 0;
  padding: 24px 20px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: width 0.2s ease, padding 0.2s ease, max-height 0.2s ease;
}

#fence-panel-collapse {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 18px auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

#fence-panel-collapse span {
  display: none;
}

#fence-panel-collapse:hover {
  color: var(--text);
  border-color: var(--green-deep);
}

#view-cercas.fence-panel-collapsed #panel {
  width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

#view-cercas.fence-panel-collapsed #panel > :not(#fence-panel-collapse) {
  display: none;
}

#view-cercas.fence-panel-collapsed #fence-panel-collapse {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
}

#view-cercas.fence-panel-collapsed #fence-panel-collapse span {
  display: none;
}

#view-cercas.fence-panel-collapsed #map .leaflet-top.leaflet-left {
  top: 68px;
  left: 6px;
}

.subtitle {
  margin: 2px 0 20px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text-muted);
}

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* :not(checkbox/radio) importa: sem isso o width:100% também pega a caixinha
   de marcar (que mora dentro de um .field), esticando-a pela largura do
   painel e jogando o texto do label pra linha de baixo. */
.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  /* 16px, not 14px: below 16px iOS Safari auto-zooms the page on focus —
     disorienting on a phone in the field. */
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:not([type="checkbox"]):not([type="radio"]):hover,
.field select:hover,
.field textarea:hover {
  border-color: var(--border-strong);
}

.field input[type="checkbox"],
.field input[type="radio"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}

/* Campo focado troca o anel externo por borda + halo: dentro de um
   formulário denso, o anel de outline encosta no campo vizinho. Caixinhas
   de marcar ficam de fora e mantêm o anel global — elas não têm borda
   própria pra tingir. */
.field input:not([type="checkbox"]):not([type="radio"]):focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--green-deeper);
  box-shadow: var(--ring);
}

.field select {
  /* A seta nativa do select fica desalinhada quando a altura é custom;
     desenhá-la aqui mantém o mesmo padding dos inputs de texto. */
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235c6b7a' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 32px;
}

.field textarea {
  min-height: 90px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

/* Bloco de mídia do nó: seletor de arquivo, botão de envio, status e
   miniatura. Fica em linha própria (ver comentário no nodeCardHtml). */
.media-field {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--bg);
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-row input[type="file"] {
  /* min-width:0 é o que deixa o input encolher: o tamanho intrínseco dele
     inclui o nome do arquivo, e sem isso o flex se recusa a espremê-lo e
     o texto escapa do card. */
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  padding: 0;
  border: none;
  background: none;
  font-size: 12px;
  color: var(--text-muted);
}

.upload-row .node-upload-btn {
  flex-shrink: 0;
}

/* O botão nativo do input[type=file] ignora estilo do próprio input —
   ::file-selector-button é o único jeito de casá-lo com .btn-secondary. */
.upload-row input[type="file"]::file-selector-button {
  margin-right: 8px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.upload-row input[type="file"]::file-selector-button:hover {
  background: var(--surface-sunken);
  border-color: var(--border-strong);
}

.node-upload-status {
  display: block;
  font-size: 12px;
  color: var(--success);
  font-weight: 600;
}

.node-upload-status:not(:empty) {
  margin-top: 8px;
}

.node-media-preview {
  display: block;
  margin-top: 10px;
  max-width: 240px;
  max-height: 120px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  background: var(--surface-sunken);
}

.field.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* O input mora dentro do próprio label (é ele quem carrega o texto), então
   o alinhamento tem que acontecer aqui, não no .field. */
.field.checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
}

.coords {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  line-height: 1.5;
}

button {
  font-family: inherit;
}

#fence-save,
#config-save,
.btn-primary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--green);
  color: var(--navy);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

#fence-save:hover:not(:disabled),
#config-save:hover,
.btn-primary:hover:not(:disabled) {
  background: var(--green-deep);
}

#fence-save:active:not(:disabled),
#config-save:active,
.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
}

#fence-save:disabled,
.btn-primary:disabled {
  background: #cdd4d1;
  color: #889;
  cursor: not-allowed;
}

.btn-secondary {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--surface-sunken);
  border-color: var(--border-strong);
}

.btn-danger {
  padding: 6px 11px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-danger:hover {
  background: var(--danger-tint);
  border-color: var(--danger);
}

.btn-danger:focus-visible {
  outline-color: var(--danger);
}

#fence-feedback,
#config-feedback,
.feedback {
  min-height: 18px;
  font-size: 12px;
  margin: 8px 0 0;
}

.feedback.error,
#fence-feedback.error,
#config-feedback.error {
  color: var(--danger);
}

.feedback.ok,
#fence-feedback.ok,
#config-feedback.ok {
  color: var(--success);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-subtle);
  margin: 0 0 10px;
}

#fence-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
}

#fence-list li {
  padding: 9px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  /* Faixa lateral em vez de borda inferior: ela marca o item selecionado
     sem mexer no espaçamento quando aparece/some. */
  border-left: 3px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#fence-list li:hover {
  background: var(--surface);
  border-left-color: var(--border-strong);
}

#fence-list li.active {
  background: var(--surface);
  border-left-color: var(--green-deeper);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

#fence-list li .meta {
  display: block;
  font-size: 11px;
  color: var(--text-subtle);
  font-weight: 400;
  margin-top: 2px;
}

#map {
  flex: 1;
  min-height: 0;
}

/* --- Detail panel: selected fence's edit form + bubbles/nodes/offers --- */

#detail-panel {
  width: 540px;
  flex-shrink: 0;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  box-shadow: -8px 0 24px rgba(10, 30, 54, 0.06);
}

/* Cabeçalho próprio, grudado no topo. Antes o X era absoluto sobre o
   conteúdo: espremido no canto e, mais grave, fora de alcance assim que a
   rolagem passava do começo — justamente num painel que agora rola bastante.
   Como barra fixa ele ganha folga e continua acessível, e o nome da cerca
   fica visível por mais fundo que se esteja na hierarquia. */
#detail-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#detail-title {
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#fence-detail {
  padding: 20px;
}

.close-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-subtle);
  transition: background 0.15s ease, color 0.15s ease;
}

.close-btn:hover {
  background: var(--surface-sunken);
  color: var(--text);
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--bg);
}

/* Cartão dentro de cartão (bolha > nó, bolha > grupo de ofertas) volta pro
   branco: dois níveis com o mesmo fundo viram um bloco só, e é exatamente
   nesse painel que a hierarquia importa pra saber a que bolha um nó pertence. */
.card .card {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.card .card .card {
  background: var(--bg);
  box-shadow: none;
}

/* Cartão recolhível (details/summary). O padding sai do .card e vai pro
   summary e pro corpo, senão o cartão fechado fica com sobra embaixo. */
details.card {
  padding: 0;
  overflow: hidden;
}

.card-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  transition: background 0.15s ease;
}

/* O triângulo padrão do summary é desenhado pelo navegador e não aceita
   estilo; matamos ele nos dois motores e desenhamos o nosso no ::before. */
.card-summary::-webkit-details-marker {
  display: none;
}

.card-summary::before {
  content: "";
  flex-shrink: 0;
  width: 0;
  height: 0;
  border-left: 5px solid var(--text-subtle);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: translateY(-1px);
  transition: transform 0.15s ease;
}

details[open] > .card-summary::before {
  transform: rotate(90deg) translateX(-1px);
}

.card-summary:hover {
  background: var(--surface-sunken);
}

details[open] > .card-summary {
  border-bottom: 1px solid var(--border);
}

.summary-title {
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* O resumo é o que permite decidir se vale abrir a seção, mas não deve
   competir com o título — daí menor, mais claro e empurrado pra direita. */
.summary-meta {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-subtle);
}

.card-body {
  padding: 14px;
}

.card-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: 12px;
}

/* Nas ofertas os botões fecham a linha em vez de abri-la. */
.repeatable-item .card-actions {
  margin: 6px 0 0;
}

/* Títulos de seção dentro da gaveta ganham respiro acima: sem o <hr /> que
   os separava antes, eles encostavam no cartão anterior. */
#fence-detail h2 {
  margin-top: 22px;
}

#fence-detail > .fence-edit-card + h2 {
  margin-top: 24px;
}

/* flex-end alinha os campos pela base: se o label de um deles quebrar em
   duas linhas, o input dele desceria e sairia do prumo do vizinho. Com o
   alinhamento pela base os inputs continuam na mesma linha e a quebra
   empurra só o label pra cima. */
.row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.row .field {
  flex: 1;
  min-width: 0;
}

.unlock-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.unlock-list label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 400;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.unlock-list label:hover {
  border-color: var(--border-strong);
  background: var(--surface-sunken);
}

.repeatable-item {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
  background: var(--surface);
}

.repeatable-item .row {
  margin-bottom: 6px;
}

/* Config e Perfil são formulários estreitos numa view larga. Sem um
   contêiner visível eles ficam soltos encostados na borda esquerda, como
   se a página não tivesse terminado de carregar; num cartão sobre o fundo
   cinza, a largura curta vira decisão em vez de sobra. A rolagem sobe pra
   view — o cartão fica do tamanho do conteúdo, não da tela. */
#view-config,
#view-profile {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#config-panel {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 28px;
}

/* Barras de rolagem discretas — o painel de detalhe tem várias áreas
   roláveis aninhadas e as barras nativas do Windows pesam visualmente. */
#panel,
#detail-panel,
#config-panel,
#nav {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* --- Responsive ---
   Field-use note: this panel gets used on a phone, standing next to a
   fence, editing it live — not just "doesn't break at narrow widths".
   Below 960px, list + map + editor no longer fit side by side, so they
   stack; the editor (#detail-panel) is the surface that actually needs
   room to work in, so once it's open it takes over the whole view instead
   of sharing a cramped 45vh slice with the list and map (see the
   :has() rule below). */
@media (max-width: 960px) {
  .view {
    flex-direction: column;
  }

  #panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  #view-cercas.fence-panel-collapsed #panel {
    width: 0;
    height: 0;
    max-height: 0;
    padding: 0;
  }

  #map {
    min-height: 30vh;
  }

  #detail-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 55vh;
    box-shadow: none;
  }

  #view-cercas:has(#detail-panel:not(.hidden):not(.is-collapsed)) #panel,
  #view-cercas:has(#detail-panel:not(.hidden):not(.is-collapsed)) #map {
    display: none;
  }

  #view-cercas:has(#detail-panel:not(.hidden):not(.is-collapsed)) #detail-panel {
    flex: 1;
    max-height: none;
    border-top: none;
  }

  /* Multi-field rows (spawn min/max/float, hotspot yaw/pitch, etc.) are
     three inputs across — fine on a tablet, unusable squeezed into a phone
     width, so stack them once the layout has already gone to one column.
     align-items volta pro padrão: empilhado, o eixo cruzado é a largura, e
     o flex-end do layout largo encolheria cada campo pro canto direito. */
  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  /* Bigger tap targets — a thumb in the field is less precise than a mouse. */
  .btn-secondary,
  .btn-danger {
    padding: 10px 14px;
    font-size: 13px;
  }

  #fence-list li,
  .unlock-list label {
    padding: 10px 8px;
  }

  .close-btn {
    width: 36px;
    height: 36px;
  }
}

@media (min-width: 721px) and (max-width: 1100px) {
  #nav {
    width: 238px;
    padding: 16px 10px;
  }

  #nav.is-collapsed {
    width: 78px;
    padding-inline: 10px;
  }
}

@media (max-width: 720px) {
  #login-form {
    width: 90vw;
    max-width: 440px;
    padding: 32px 26px 26px;
  }

  #app {
    flex-direction: column;
  }

  #mobile-header {
    height: 58px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    background: var(--navy);
    color: #fff;
    z-index: 31;
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-brand img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  #nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 11px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
  }

  #nav-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 58px 0 0;
    z-index: 29;
    background: rgba(10, 30, 54, 0.48);
  }

  #nav {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    width: min(290px, 86vw);
    z-index: 30;
    padding: 18px 12px 14px;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }

  #nav.is-collapsed {
    width: min(290px, 86vw);
    padding: 18px 12px 14px;
  }

  #nav-collapse {
    display: none;
  }

#nav.is-collapsed .nav-label {
    display: initial;
  }

  #nav.is-collapsed .nav-item {
    justify-content: flex-start;
    gap: 11px;
    padding: 11px 12px;
  }

  #nav.is-collapsed .nav-icon {
    width: 24px;
  }

  #nav.is-collapsed .nav-profile {
    justify-content: flex-start;
  }

  #nav.open {
    transform: translateX(0);
  }

  #nav-brand {
    display: none;
  }

  .nav-item {
    flex-direction: row;
    padding: 11px 12px;
    font-size: 13px;
    margin-bottom: 2px;
  }

  .nav-section {
    margin-bottom: 18px;
  }

  .view {
    min-height: 0;
  }
}

/* Linha de cerca filha no painel de detalhe. O botão é a navegação — clicar
   nele seleciona a filha e move o mapa até ela —, e a meta fica ao lado para
   dar contexto sem exigir abrir. */
.child-fence-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.child-fence-row .summary-meta {
  white-space: nowrap;
}

/* Campo de coordenada: os dois números lado a lado, com o aviso de "não salvo"
   logo abaixo — perto do que ele descreve, não no rodapé do formulário. */
.coord-field .row input {
  flex: 1;
}

.coord-dirty {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: #e0a33a;
}

.coord-dirty.hidden {
  display: none;
}

/* --- View: Mídia --- */

/* Larga, não os 480px de Config/Perfil: uma galeria precisa da tela toda
   pra render mais de uma coluna de miniaturas. */
#view-midia {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#media-panel {
  width: 100%;
}

#media-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

#media-toolbar h2 {
  margin: 0 0 2px;
}

#media-toolbar .subtitle {
  margin-bottom: 0;
}

#media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.pagination-bar {
  margin-top: 22px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.pagination-bar[hidden] {
  display: none;
}

.pagination-summary {
  color: var(--text-muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.pagination-actions,
.page-controls,
.page-numbers,
.page-size-control {
  display: flex;
  align-items: center;
}

.pagination-actions {
  gap: 18px;
}

.page-size-control {
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.page-size-control select {
  appearance: none;
  -webkit-appearance: none;
  width: auto;
  min-width: 80px;
  height: 36px;
  margin: 0;
  padding: 6px 32px 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.page-size-control select:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (pointer: coarse) {
  .page-size-control select {
    min-height: 44px;
    font-size: 16px;
  }
}

.page-controls,
.page-numbers {
  gap: 5px;
}

.page-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 650;
  cursor: pointer;
}

.page-button:hover:not(:disabled):not(.active) {
  border-color: var(--green-deep);
  background: rgba(126, 217, 87, 0.1);
}

.page-button.active {
  color: var(--navy);
  background: var(--green);
  border-color: var(--green);
}

.page-button:disabled {
  opacity: 0.34;
  cursor: default;
}

.page-ellipsis {
  width: 24px;
  text-align: center;
  color: var(--text-subtle);
}

@media (max-width: 760px) {
  .pagination-bar,
  .pagination-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions {
    gap: 12px;
  }

  .page-controls {
    justify-content: center;
  }

  .page-size-control {
    justify-content: space-between;
  }
}

.media-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.media-card-thumb {
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: var(--surface-sunken);
  display: block;
}

.media-card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.media-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.media-card-name {
  font-size: 11px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.media-card-meta {
  font-size: 11px;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.media-badge-used {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--danger-tint);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  font-weight: 700;
  font-size: 10px;
}

.media-card-body .btn-danger {
  margin-top: 2px;
}

/* --- Modal de confirmação de exclusão de mídia ---
   confirm() nativo só tem OK/Cancelar; apagar mídia tem três desfechos
   (recuperável, definitivo, cancelar), então precisa de UI própria. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 54, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px;
}

.modal-box h3 {
  margin: 0 0 8px;
}

.modal-box p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-actions .btn-danger,
.modal-actions .btn-secondary {
  width: 100%;
  padding: 10px;
  font-size: 13px;
}

/* --- View: Usuários --- */

#view-usuarios {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#usuarios-panel {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
}

#usuarios-panel h2 {
  margin: 0 0 2px;
}

#editor-fence-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.usuario-card-email {
  font-size: 0.98rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 10px;
  flex-shrink: 0;
}

.role-badge.role-admin {
  background: var(--navy-soft);
  color: #fff;
}

.role-badge.role-editor {
  background: rgba(126, 217, 87, 0.18);
  color: var(--green-deeper);
  border: 1px solid rgba(126, 217, 87, 0.4);
}

.usuario-card-fences {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 820px) {
  #view-usuarios {
    padding: 20px;
  }

}

/* --- View: Cadastros do app --- */

#view-cadastros {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#cadastros-panel {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
}

#cadastros-panel > h2 {
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1.15;
  letter-spacing: -0.03em;
  text-transform: none;
  margin: 0 0 5px;
}

#cadastros-resumo {
  display: inline-flex;
  padding: 6px 10px;
  margin: 0 0 14px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 650;
}

@media (max-width: 720px) {
  #view-cadastros {
    padding: 20px;
  }
}

.fence-checklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.fence-checklist-item input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* --- View: Métricas --- */

#view-metricas {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#metricas-panel {
  width: 100%;
  max-width: 1440px;
  margin-inline: auto;
}

#metricas-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

#metricas-header h2,
#usuarios-panel > h2 {
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1.15;
  letter-spacing: -0.03em;
  text-transform: none;
  margin: 0 0 5px;
}

#metricas-header .subtitle {
  margin-bottom: 0;
}

#metricas-filtros {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

#metricas-filtros .field {
  margin: 0;
}

.metric-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-kpi-card,
.metric-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.metric-kpi-card {
  position: relative;
  min-height: 160px;
  padding: 18px;
}

.metric-kpi-card.featured {
  border-color: rgba(88, 177, 52, 0.65);
  background: linear-gradient(135deg, rgba(126, 217, 87, 0.11), var(--surface) 72%);
}

.metric-kpi-icon {
  position: absolute;
  top: 17px;
  right: 17px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--navy-soft);
  background: var(--surface-sunken);
  border-radius: 50%;
}

.metric-kpi-card.featured .metric-kpi-icon {
  color: var(--green-deeper);
  background: rgba(126, 217, 87, 0.2);
}

.metric-kpi-value {
  padding-right: 42px;
  color: var(--text);
  font-size: 2rem;
  font-weight: 750;
  line-height: 1;
}

.metric-kpi-label {
  margin-top: 8px;
  font-size: 0.88rem;
  font-weight: 700;
}

.metric-kpi-card p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.metric-section {
  padding: 18px;
}

.metric-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  font-size: 1rem;
}

.metric-section h3 i {
  color: var(--green-deeper);
}

.metric-chart-card {
  margin-bottom: 16px;
}

.metric-line-chart {
  width: 100%;
  height: auto;
  min-height: 210px;
  overflow: visible;
}

.metric-grid-line {
  stroke: #e6ebe9;
  stroke-width: 1;
}

.metric-axis-label {
  fill: var(--text-subtle);
  font-size: 11px;
}

.metric-chart-line {
  fill: none;
  stroke: #109a67;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.metric-chart-dot {
  fill: #fff;
  stroke: #109a67;
  stroke-width: 3;
}

.metric-bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 16px;
}

.metric-ranking {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-ranking-row {
  display: grid;
  grid-template-columns: 26px minmax(110px, 0.8fr) minmax(90px, 1fr) 32px;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
}

.metric-rank {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.metric-ranking-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-ranking-track {
  height: 8px;
  overflow: hidden;
  background: var(--surface-sunken);
  border-radius: 999px;
}

.metric-ranking-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #18a875, #57c896);
  border-radius: inherit;
}

.metric-fence-layout {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: center;
  gap: 20px;
}

.metric-donut {
  width: 140px;
  height: 140px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--metric-segments));
}

.metric-donut::before {
  content: '';
  grid-area: 1 / 1;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: var(--surface);
}

.metric-donut > div {
  z-index: 1;
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-donut strong {
  font-size: 1.4rem;
}

.metric-donut span {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.metric-fence-legend {
  min-width: 0;
}

.metric-legend-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  padding: 5px 0;
  font-size: 0.75rem;
}

.metric-legend-color {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.metric-legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-legend-row small {
  grid-column: 2 / -1;
  color: var(--text-subtle);
}

.metric-empty {
  color: var(--text-muted);
  font-size: 0.84rem;
}

@media (max-width: 1180px) {
  .metric-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  #view-metricas {
    padding: 20px;
  }

  #metricas-header,
  .metric-bottom-grid,
  #metricas-filtros {
    grid-template-columns: 1fr;
  }

  #metricas-header {
    flex-direction: column;
  }

  .metric-bottom-grid {
    display: grid;
  }
}

@media (max-width: 560px) {
  .metric-kpi-grid {
    grid-template-columns: 1fr;
  }

  .metric-fence-layout {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .metric-fence-legend {
    width: 100%;
  }
}

/* Ajustes finais: cidades, categorias, perfil e login. */
#login-form .subtitle {
  margin: 5px 0 24px;
  font-size: 15px;
}

#login-form .field {
  margin-bottom: 17px;
}

#login-form .field label {
  margin-bottom: 7px;
  font-size: 13px;
}

#login-form .field input {
  min-height: 50px;
  font-size: 16px;
}

#view-categorias {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#categorias-panel {
  width: 100%;
  max-width: none;
}

.catalog-create-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 120px;
  gap: 16px;
  align-items: end;
}

.category-create-grid {
  grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1fr) minmax(220px, 0.8fr);
  align-items: start;
}

.cidade-background-field {
  grid-column: 1 / -1;
}

.catalog-form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.catalog-form-actions button {
  width: auto;
  min-width: 150px;
  margin: 0;
}

.optional-label {
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 500;
}

.city-background-picker {
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 380px);
  gap: 24px;
  align-items: center;
}

#cidade-background-preview {
  aspect-ratio: 16 / 9;
  min-height: 0;
}

#cidade-background-preview.is-empty span { text-align: center; }
.city-create-upload { min-width: 0; }
.city-create-upload #cidade-background {
  min-width: 0;
  padding: 8px;
  font-size: 13px;
}
.city-create-upload #cidade-background::file-selector-button {
  padding: 8px 12px;
  margin-right: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--navy);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.city-create-upload .field-hint { margin-top: 8px; }

.city-background-preview {
  position: relative;
  min-height: 132px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--navy);
  background-position: center;
  background-size: cover;
  color: #fff;
}

.city-background-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 18, 31, 0.06), rgba(5, 18, 31, 0.66));
}

.city-background-preview > * {
  position: relative;
  z-index: 1;
}

.city-background-preview.is-empty {
  flex-direction: column;
  background-image: none !important;
  color: rgba(255, 255, 255, 0.72);
}

.city-background-preview.is-empty i {
  font-size: 1.6rem;
}

.city-background-preview span {
  align-self: flex-end;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.75rem;
  font-weight: 700;
}

.city-table-background {
  width: 104px;
  height: 54px;
  display: block;
  object-fit: cover;
  border-radius: 8px;
  background: var(--navy);
}

.default-background-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.default-background-badge i {
  color: var(--navy-soft);
}

.city-edit-modal {
  width: min(720px, calc(100vw - 32px));
  max-width: 720px;
  max-height: calc(100dvh - 40px);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.city-modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--border);
}

.city-modal-heading h3 { font-size: 22px; }
.city-modal-heading p { margin: 0; }
.city-modal-body { padding: 24px 28px; overflow-y: auto; min-height: 0; }
.city-edit-modal .city-background-picker { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.city-edit-modal .city-background-picker > * { min-width: 0; }
.city-edit-modal .city-background-preview { aspect-ratio: 16 / 9; min-height: 150px; }
.city-edit-modal .city-background-preview.is-empty span { text-align: center; }
.city-image-upload { position: relative; }
.city-image-upload #city-edit-background {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}
.city-image-upload .city-upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--navy);
  font-size: 13px;
  cursor: pointer;
}
.city-upload-button:hover { background: var(--bg); }
.city-image-upload:focus-within .city-upload-button { outline: 2px solid var(--green); outline-offset: 3px; }
#city-image-filename { display: block; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; margin-bottom: 8px; }
.city-remove-image { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin: 12px 0 24px; }
.city-remove-image input { flex: 0 0 auto; margin: 0; width: 16px; height: 16px; }
.city-remove-image:has(input:disabled) { opacity: .55; }
.city-status-setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.city-status-setting strong { display: block; font-size: 14px; margin-bottom: 4px; }
.city-status-setting small { display: block; color: var(--text-muted); font-size: 12px; }
.city-status-setting input { appearance: none; flex: 0 0 42px; width: 42px; height: 24px; margin: 0; padding: 3px; border: 0; border-radius: 20px; background: var(--border-strong); cursor: pointer; }
.city-status-setting input::before { content: ''; display: block; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 3px #0002; transition: transform .15s ease; }
.city-status-setting input:checked { background: var(--green); }
.city-status-setting input:checked::before { transform: translateX(18px); }
.city-status-setting input:focus-visible { outline: 2px solid var(--navy); outline-offset: 3px; }
.city-modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 28px; border-top: 1px solid var(--border); }
.city-modal-footer button { width: auto; min-height: 42px; padding: 10px 18px; margin: 0; }

@media (max-width: 560px) {
  .city-modal-heading, .city-modal-body, .city-modal-footer { padding: 18px; }
  .city-edit-modal .city-background-picker { grid-template-columns: minmax(0, 1fr); }
  .city-modal-footer button { flex: 1; min-width: 0; }
}

.form-grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.28fr);
  gap: 14px;
}

#view-profile {
  padding: 32px;
}

@media (max-width: 980px) {

  .category-create-grid,
  .catalog-create-grid {
    grid-template-columns: 1fr;
  }

  .cidade-background-field,
  .catalog-form-actions {
    grid-column: 1;
  }
}

@media (max-width: 640px) {
.city-background-picker,
.form-grid-2 {
    grid-template-columns: 1fr;
  }

  .city-background-preview {
    min-height: 150px;
  }

}

/* --- View: Clientes --- */

#view-clientes {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#clientes-panel {
  width: 100%;
  max-width: 780px;
}

#clientes-panel h2 {
  margin: 0 0 2px;
}

/* --- View: Concierge --- */

#view-concierge {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#concierge-panel {
  width: 100%;
  max-width: 820px;
}

#concierge-panel h2 {
  margin: 0 0 2px;
}

.concierge-edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.concierge-fence-checklist {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 560px) {
  .concierge-edit-row {
    grid-template-columns: 1fr 1fr;
  }

  .concierge-edit-row input {
    grid-column: 1 / -1;
  }

  .concierge-edit-row button {
    width: 100%;
  }

}

/* --- Shell do editor --- */

#editor-app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#editor-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--navy);
  flex-shrink: 0;
}

#editor-topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
}

#editor-topbar-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: block;
}

#editor-nav {
  display: flex;
  gap: 6px;
  flex: 1;
}

.editor-nav-item {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.editor-nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.editor-nav-item.active {
  background: var(--green);
  color: var(--navy);
}

.editor-nav-avatar-item {
  padding: 3px;
  border-radius: 50%;
  flex-shrink: 0;
}

.editor-nav-avatar-item.active {
  background: none;
  box-shadow: 0 0 0 2px var(--green);
}

.editor-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

#editor-fences-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
  margin-top: 12px;
}

.editor-node-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.editor-node-label:first-child {
  margin-top: 0;
}

.editor-node-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.editor-node-row:last-child {
  border-bottom: none;
}

.editor-node-thumb {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-sunken);
}

.editor-node-thumb.clickable {
  cursor: zoom-in;
}

.modal-box-wide {
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}

.modal-box-wide h3 {
  text-align: left;
  overflow-wrap: anywhere;
}

.modal-preview-media {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 12px auto;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}

.editor-node-thumb img,
.editor-node-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* renderMediaPreview() é compartilhado com o editor de nó do admin, que
   traz max-width/margin-top pensados pra um preview solto num formulário
   — aqui o preview vive dentro de uma miniatura de 72px fixa e precisa
   preencher, não flutuar. Especificidade (.editor-node-thumb + classe)
   vence .node-media-preview sem precisar de !important. */
.editor-node-thumb .editor-node-thumb-fill {
  margin-top: 0;
  max-width: none;
  max-height: none;
  border: none;
  box-shadow: none;
}

.editor-node-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-subtle);
  text-align: center;
  padding: 4px;
}

.editor-node-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.editor-node-title {
  font-weight: 600;
  font-size: 13px;
}

.editor-node-status {
  font-size: 11px;
  color: var(--success);
}

/* ---------------- view: locais (índice de cercas gerais) ---------------- */

/* Cada view carrega o próprio padding e o próprio scroll — `.view` só resolve o
   flex. Sem esta regra o conteúdo cola no topo e a página inteira rola junto,
   que foi como esta tela subiu na primeira vez. */
#view-locais {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#locais-panel {
  width: 100%;
  max-width: 980px;
}

#locais-panel h2 {
  margin: 0 0 2px;
}

#locais-tabela {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

#locais-tabela th,
#locais-tabela td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border, #2a3b57);
  vertical-align: middle;
  white-space: nowrap;
}

#locais-tabela th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

#locais-tabela .col-num {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}

/* Coordenadas em uma única linha, imediatamente ao lado do endereço. */
#locais-tabela .col-coordenadas {
  width: 1%;
  font-variant-numeric: tabular-nums;
}
#locais-tabela td.col-coordenadas {
  color: var(--text-muted);
  font-size: 0.82rem;
}

#locais-tabela tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* display:flex vence o atributo hidden, que só vale enquanto ninguém
   declara display — a paginação ficava visível com uma página só. Esta regra
   devolve o comportamento que o atributo promete. */
#locais-paginacao[hidden] {
  display: none;
}

#locais-paginacao {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

#locais-paginacao button {
  width: auto;
  padding: 7px 14px;
  font-size: 0.9rem;
}

#locais-paginacao button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------------- view: local (detalhe) ---------------- */

#view-local {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#local-panel { width: 100%; max-width: 1480px; }

/* Coluna do conteúdo elástica, coluna do mapa com teto: acima de ~460px o
   mapa só ganha área vazia em volta do ponto, enquanto o formulário é quem
   sofre com pouca largura. */
#local-corpo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: 28px;
  align-items: start;
}

#local-lado {
  position: sticky;
  /* Zero porque quem rola aqui é #view-local (overflow-y:auto), não a janela:
     o topo da área rolável já vem depois do padding do painel. */
  top: 0;
  /* Sem isto o item de grid estica até a altura da linha, e um item da altura
     do próprio container nunca chega a grudar. */
  align-self: start;
}

/* O primeiro título da coluna esquerda encosta no subtítulo agora que o mapa
   saiu de cima dele — a régua que separava seções não separa nada aqui. */
#local-coluna > .local-secao:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.btn-voltar {
  width: auto;
  background: none;
  border: 0;
  color: var(--accent, #4ade9b);
  padding: 0;
  margin-bottom: 14px;
  cursor: pointer;
  font-size: 0.92rem;
}

#local-panel h2 { margin: 0 0 2px; }

#local-mapa {
  height: min(66vh, 560px);
  border-radius: 12px;
  margin: 0 0 12px;
  border: 1px solid var(--border, #2a3b57);
}

/* Uma coluna abaixo disto: com o mapa em 320px o formulário ficaria com menos
   de 500px, e as linhas de três campos (ícone / versão / moedas) viram três
   caixas de texto ilegíveis. Empilhado, o mapa volta a ser uma faixa no topo e
   deixa de grudar — numa tela estreita ele comeria metade do que se rola. */
@media (max-width: 1100px) {
  #local-corpo {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  #local-lado {
    position: static;
    order: -1;
    margin-bottom: 20px;
  }

  #local-mapa { height: 340px; }
}

.local-secao {
  margin: 30px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--border, #2a3b57);
  font-size: 1rem;
}

#local-dados,
.dados-inline {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px 20px;
  margin: 0;
}

.dado dt {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.55;
}

.dado dd {
  margin: 2px 0 0;
  font-size: 0.94rem;
  word-break: break-word;
}

.filha-card {
  border: 1px solid var(--border, #2a3b57);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 14px;
}

.filha-card h4 { margin: 0 0 12px; font-size: 1rem; }

.filha-meta {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  opacity: 0.5;
  margin-top: 3px;
}

.bolha-card {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
  padding: 14px;
  margin-top: 10px;
}

.bolha-coord {
  margin: 10px 0 12px;
}

/* A bolha que está sendo movida no mapa. Fica marcada até outra ser pegada:
   um piscar rápido some antes de a pessoa terminar o arrasto, que é
   exatamente quando ela precisa saber qual cartão está olhando. */
.bolha-card.em-foco {
  background: rgba(74, 222, 155, 0.07);
  box-shadow: inset 3px 0 0 var(--green, #4ade9b);
}

/* O ponto da bolha no mapa. Era um circleMarker do Leaflet; virou marker com
   ícone de CSS porque só marker arrasta. A borda escura é o que o separa do
   preenchimento da cerca, que é da mesma família de verde. */
.bolha-pino {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--green, #4ade9b);
  border: 2px solid var(--navy, #0a1e36);
  box-sizing: border-box;
  cursor: grab;
}

.bolha-pino:active {
  cursor: grabbing;
}

/* A ação mora na última coluna, encostada à direita. A linha inteira já foi
   clicável e saiu: a célula do meio é justamente a que se quer selecionar para
   copiar o endereço, e arrastar sobre o texto abria o detalhe sem querer. */
#locais-tabela .col-acoes {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

/* O formulário reusa .row/.field da gaveta de Cercas. Aqui eles não estão
   dentro de um cartão, então o bloco precisa do próprio respiro em relação ao
   mapa logo acima. */
#local-form {
  margin-top: 4px;
}

/* Os três filtros de Locais numa linha só. A busca ocupa o espaço que sobra;
   os selects ficam do tamanho do conteúdo, porque "Todas as categorias (27)"
   não precisa de meia tela. */
#locais-filtros {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

#locais-filtros .field:first-child { flex: 1 1 260px; }
#locais-filtros .field { margin-bottom: 0; }
#locais-filtros select { min-width: 190px; }

/* Thumb do local na tabela de Locais. Largura fixa e `object-fit: cover`: as
   imagens enviadas têm proporções diferentes entre si, e deixar cada uma impor
   a própria altura desalinharia as linhas. */
#locais-tabela .col-thumb {
  width: 1%;
  padding-right: 0;
}

#locais-tabela .locais-thumb,
#locais-tabela .locais-thumb-placeholder {
  width: 56px;
  height: 40px;
  border-radius: 4px;
  background: var(--surface-sunken);
  display: block;
}

#locais-tabela .locais-thumb {
  object-fit: cover;
}

/* O placeholder existe só para segurar o espaço da coluna quando o local não
   tem thumb — sem texto, porque "sem thumb" repetido em meia tabela é ruído. */
#locais-tabela .locais-thumb-placeholder {
  border: 1px dashed var(--border, #2a3b57);
  background: transparent;
}

/* Dica de formato ao lado dos campos de upload. O painel exibe WebP sem
   problema — quem não abre é o app, que decodifica só JPG e PNG. Sem esta
   linha, o upload parecia ter dado certo e a imagem sumia só no aparelho. */
.upload-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-subtle, #8b98a8);
}

/* --- View: Cadastros do app --- */

/* Linha de resumo acima da lista ("12 contas"). */
#cadastros-resumo {
  margin: 4px 0 14px;
}

.cadastro-nome {
  font-weight: 600;
  color: var(--text);
  /* Nome longo corta com reticências em vez de quebrar o cartão em duas
     alturas diferentes — numa lista, altura irregular atrapalha a varredura. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cadastro-email {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cadastro-selos {
  display: flex;
  gap: 6px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.cadastro-selo {
  font-size: 11px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  background: var(--bg);
  white-space: nowrap;
}

/* Aviso, não erro: e-mail não verificado é o estado normal hoje — não há
   envio de e-mail no servidor. Vermelho aqui seria alarme falso em 100%
   das linhas. */
.cadastro-selo-atencao {
  border-color: var(--border-strong);
  color: var(--text-subtle);
  font-style: italic;
}

/* Abaixo de ~720px a grade de quatro colunas não cabe: vira duas linhas,
   com avatar+identidade em cima e números+ação embaixo. */


/* ---------- Tabelas da tela de Métricas ----------
   O painel não tinha nenhuma tabela até 2026-09-11 — tudo era card. As
   métricas pedem tabela de verdade: são pares rótulo/número que a pessoa
   compara na vertical, e card por linha transformaria dez itens numa rolagem
   longa onde comparar é impossível.

   Cores das variáveis da marca, não cinzas avulsos, pelo mesmo motivo que a
   seção de texto lá em cima explica. */
.tabela {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.tabela th,
.tabela td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.tabela th {
  color: var(--text-muted);
  font-weight: 600;
  border-bottom-color: var(--border-strong);
}

/* Números à direita: alinhados pela unidade, a comparação entre linhas é
   visual em vez de exigir leitura dígito a dígito. */
.tabela td:not(:first-child),
.tabela th:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tabela tr:last-child td {
  border-bottom: none;
}

/* ==================================================================
   Padrão único de listagens administrativas
   ================================================================== */

#view-locais,
#view-cidades,
#view-usuarios,
#view-clientes,
#view-cadastros,
#view-midia {
  background: var(--bg);
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px;
}

#locais-panel,
#cidades-panel,
#usuarios-panel,
#clientes-panel,
#cadastros-panel,
#media-panel {
  width: 100%;
  max-width: none;
  margin: 0;
}

.list-page-header,
#cidades-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.list-page-header h2,
#cidades-header h2,
#locais-panel > h2,
#media-toolbar h2 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 1.65rem;
  line-height: 1.15;
  letter-spacing: -0.03em;
  text-transform: none;
}

.list-page-header .subtitle,
#cidades-header .subtitle {
  margin: 0;
}

.list-page-header > button,
#cidades-header > button {
  width: auto;
  flex: 0 0 auto;
}

.list-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

.list-header-actions > button {
  width: auto;
  margin: 0;
}

.list-title-line {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

#cadastros-resumo {
  margin: 0;
}

.list-toolbar,
#cidades-toolbar {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) repeat(2, minmax(180px, 230px));
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.list-toolbar.list-filters-3 {
  grid-template-columns: minmax(360px, 1.7fr) minmax(220px, 1fr) minmax(220px, 1fr);
}

.list-toolbar.list-filters-2 {
  grid-template-columns: minmax(360px, 1.7fr) minmax(220px, 1fr);
}

#cidades-toolbar {
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 230px);
}

.list-toolbar select,
.list-toolbar input,
.list-search input,
#cidades-toolbar select,
#cidades-toolbar input {
  width: 100%;
  min-width: 0;
  appearance: none;
  margin: 0;
  height: 44px;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.list-toolbar select,
#cidades-toolbar select,
.page-size-control select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235c6b7a' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
}

.list-toolbar input:hover,
.list-toolbar select:hover,
.list-search input:hover,
#cidades-toolbar input:hover,
#cidades-toolbar select:hover,
.page-size-control select:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.list-toolbar input:focus,
.list-toolbar select:focus,
.list-search input:focus,
#cidades-toolbar input:focus,
#cidades-toolbar select:focus,
.page-size-control select:focus {
  outline: none;
  border-color: var(--green-deeper);
  box-shadow: var(--ring);
}

.list-search {
  position: relative;
}

.list-search > i {
  position: absolute;
  top: 50%;
  left: 14px;
  z-index: 1;
  color: var(--text-muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.list-search input {
  padding-left: 40px;
}

.list-table-card {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

#clientes-grid,
#usuarios-list,
#cadastros-lista {
  display: block;
  grid-template-columns: none;
  gap: 0;
  margin-top: 0;
}

.list-table-card > .subtitle,
.list-table-card > .feedback {
  margin: 0;
  padding: 24px;
}

.admin-list-table,
#cidades-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

.admin-list-table th,
.admin-list-table td,
#cidades-table th,
#cidades-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.admin-list-table th,
#cidades-table th {
  color: var(--text-muted);
  background: rgba(236, 239, 240, 0.45);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  white-space: nowrap;
}

.admin-list-table tbody tr:last-child td,
#cidades-table tbody tr:last-child td {
  border-bottom: 0;
}

.admin-list-table tbody tr:hover,
#cidades-table tbody tr:hover {
  background: rgba(126, 217, 87, 0.045);
}

.admin-list-table .col-acoes,
#cidades-table .col-acoes {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.table-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.table-identity > span:last-child {
  min-width: 0;
}

.table-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-sunken);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 750;
}

.table-thumb {
  width: 62px;
  height: 44px;
  flex: 0 0 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-subtle);
}

.table-subline,
.cadastro-email {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  font-weight: 400;
}

.numeric-cell {
  font-variant-numeric: tabular-nums;
  text-align: center !important;
}

.status-badge,
.state-code-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.active {
  color: var(--success);
  background: rgba(126, 217, 87, 0.18);
}

.status-badge.inactive {
  color: var(--text-muted);
  background: var(--surface-sunken);
}

.state-code-badge {
  color: var(--navy-soft);
  background: var(--surface-sunken);
}

.muted-cell {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.usuario-card,
.client-card,
.cadastro-card {
  display: table-row;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.client-card {
  cursor: pointer;
}

.usuario-card:hover,
.client-card:hover {
  box-shadow: none;
}

.usuario-card-fences {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.cadastro-selos {
  margin: 0;
}

#usuario-create-details,
#cliente-create-details,
#cidade-form {
  width: 100%;
  margin: 0 0 18px;
}

#cidades-panel .list-table-card {
  margin-top: 0;
}

#cidade-form .row {
  align-items: flex-end;
}

.cidade-name-field {
  flex: 1 1 360px;
}

.cidade-state-field {
  flex: 0 0 100px;
}

#locais-panel {
  max-width: none;
}

#locais-tabela {
  min-width: 980px;
  margin-top: 0;
  border: 0;
  background: var(--surface);
}

#locais-filtros {
  margin-bottom: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

#locais-status {
  margin: 10px 0 12px;
}

#locais-paginacao {
  justify-content: space-between;
  gap: 18px;
  margin-top: 22px;
}

#locais-paginacao .page-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  font-size: 0.86rem;
}

.empty-state {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 30px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state > i {
  color: var(--green-deeper);
  font-size: 1.5rem;
}

@media (max-width: 900px) {
  .list-toolbar,
  #cidades-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .list-search {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  #view-locais,
  #view-cidades,
  #view-usuarios,
  #view-clientes,
  #view-cadastros,
  #view-midia {
    padding: 20px;
  }

  .list-page-header,
  #cidades-header {
    align-items: stretch;
    flex-direction: column;
  }

  .list-page-header > button,
  #cidades-header > button {
    width: 100%;
  }

  .list-header-actions {
    width: 100%;
  }

  .list-header-actions > button {
    flex: 1;
  }

  .list-toolbar,
  #cidades-toolbar {
    grid-template-columns: 1fr;
  }

  .list-search {
    grid-column: auto;
  }
}

/* Edição de cliente: formulário e vínculos separados, sem uma coluna estreita
   que transforme vinte locais numa rolagem interminável. */
.client-edit-modal {
  width: min(1180px, calc(100vw - 40px));
  max-width: 1180px;
  max-height: min(900px, calc(100vh - 40px));
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.client-edit-header,
.client-edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  background: var(--surface);
}

.client-edit-header {
  border-bottom: 1px solid var(--border);
}

.client-edit-header h3,
.client-edit-header p {
  margin: 0;
}

.client-edit-header p {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.icon-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}

.client-edit-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  flex: 1;
  overflow: hidden;
}

.client-edit-main,
.client-edit-side {
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
}

.client-edit-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.client-edit-side {
  border-left: 1px solid var(--border);
  background: rgba(236, 239, 240, 0.38);
}

.client-edit-section {
  margin: 0;
}

section.client-edit-section {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.client-edit-section h4,
.client-edit-side h4 {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 0.95rem;
}

.client-identity-editor {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.client-edit-preview {
  width: 150px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-subtle);
  font-size: 1.4rem;
}

.client-edit-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.client-staff-fields {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 10px;
}

.client-edit-side-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.client-edit-side-title h4,
.client-edit-side-title p {
  margin: 0;
}

.client-edit-side-title p {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.client-edit-side .list-search input {
  width: 100%;
  margin: 0;
}

.client-edit-side .list-search { margin-bottom: 12px; }

.client-fence-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.client-fence-option {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  align-items: flex-start;
}

.client-fence-option input {
  margin-top: 2px;
}

.client-fence-option span {
  min-width: 0;
}

.client-fence-option strong,
.client-fence-option small {
  display: block;
}

.client-fence-option strong {
  font-size: 0.82rem;
}

.client-fence-option small {
  margin-top: 2px;
  color: var(--text-subtle);
  font-size: 0.7rem;
  line-height: 1.3;
}

.client-edit-footer {
  border-top: 1px solid var(--border);
}

.client-edit-footer > div {
  display: flex;
  gap: 9px;
}

.client-edit-footer button {
  width: auto;
  min-width: 110px;
}

@media (max-width: 860px) {
  .client-edit-modal {
    max-height: calc(100vh - 20px);
  }

  .client-edit-layout {
    display: block;
    overflow-y: auto;
  }

  .client-edit-main,
  .client-edit-side {
    overflow: visible;
  }

  .client-edit-side {
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .client-staff-fields {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .client-identity-editor {
    grid-template-columns: 1fr;
  }

  .client-edit-preview {
    width: 100%;
    max-width: 220px;
  }

  .client-edit-footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .client-edit-footer > div,
  .client-edit-footer button {
    width: 100%;
  }
}
