:root {
  --bg: #10151d;
  --panel: #1a2433;
  --panel2: #223046;
  --text: #e8edf4;
  --muted: #8fa1b8;
  --accent: #3d9df2;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  overscroll-behavior: none;
}
main { flex: 1; overflow-y: auto; padding: 12px; padding-bottom: 76px; }
h2 { font-size: 1.1rem; margin: 8px 0; }
h3 { font-size: 0.95rem; margin: 6px 0; color: var(--muted); }

/* barra inferior */
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 900;
  display: flex; background: var(--panel); border-top: 1px solid #000;
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 4px 8px; font-size: 0.72rem; cursor: pointer;
}
nav button .ico { display: block; font-size: 1.35rem; margin-bottom: 2px; }
nav button.active { color: var(--accent); }

section.view { display: none; }
section.view.active { display: block; }

.card {
  background: var(--panel); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 0.85rem; }
.small { font-size: 0.8rem; }

.btn {
  display: inline-block; text-align: center; text-decoration: none;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius); padding: 12px 18px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.5; }
.btn.big { width: 100%; padding: 18px; font-size: 1.15rem; }
.btn.ghost { background: var(--panel2); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); color: #10241a; }
.btn.sm { padding: 8px 12px; font-size: 0.85rem; }

input, select, textarea {
  background: var(--panel2); border: 1px solid #31445f; color: var(--text);
  border-radius: 8px; padding: 11px; font-size: 1rem; width: 100%;
}
label { display: block; margin: 10px 0 4px; font-size: 0.85rem; color: var(--muted); }

/* GPS badge */
.gps { padding: 6px 12px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; }
.gps.good { background: #1d4d31; color: var(--green); }
.gps.ok { background: #4d431d; color: var(--yellow); }
.gps.bad { background: #4d1d1d; color: var(--red); }

/* fotos */
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.thumbs .ph { position: relative; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; }
.thumbs .kind {
  position: absolute; bottom: 2px; left: 2px; right: 2px;
  background: rgba(0,0,0,0.65); color: #fff; font-size: 0.62rem;
  text-align: center; border-radius: 4px; padding: 1px;
}
.thumbs .del {
  position: absolute; top: -6px; right: -6px; background: var(--red);
  border: none; color: #fff; width: 22px; height: 22px; border-radius: 50%;
  font-size: 0.8rem; line-height: 1; cursor: pointer;
}

/* fotos com descrição */
.photo-row {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel2); border-radius: 8px;
  padding: 8px; margin-bottom: 8px;
}
.photo-row img {
  width: 64px; height: 64px; object-fit: cover;
  border-radius: 6px; cursor: pointer; flex-shrink: 0;
}
.photo-row input { margin-top: 6px; padding: 8px; font-size: 0.9rem; }
.photo-row .del {
  background: var(--red); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; flex-shrink: 0;
}

/* chips tri-estado */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip {
  border: 1px solid #31445f; background: var(--panel2); color: var(--muted);
  border-radius: 20px; padding: 9px 14px; font-size: 0.9rem; cursor: pointer;
  user-select: none;
}
.chip.on { background: #1d4d31; border-color: var(--green); color: var(--green); }
.chip.off { background: #4d1d1d; border-color: var(--red); color: var(--red); text-decoration: line-through; }
.chip .conf { font-size: 0.7rem; opacity: 0.8; margin-left: 4px; }

/* mapa */
#map { height: calc(100vh - 120px); border-radius: var(--radius); }
.minimap { height: 230px; border-radius: 8px; margin: 8px 0; background: #223046; }
.minimap.tall { height: 34vh; }

/* tela cheia de captura */
#pole-form {
  position: fixed; inset: 0; z-index: 1400; background: var(--bg);
  overflow-y: auto; padding: 12px; display: none;
}
#pole-form.open { display: block; }
#pole-form header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.banner { border-radius: 8px; padding: 10px 12px; margin: 6px 0; font-size: 0.9rem; }
.banner.target { background: #143a5e; color: #7ec8ff; }
.banner.warn { background: #4d431d; color: var(--yellow); }
.photo-add { margin: 10px 0; }
.photo-add .btn { flex: 1; padding: 12px 4px; font-size: 0.8rem; line-height: 1.5; }
.savebar {
  position: sticky; bottom: 0; padding: 12px 0 8px;
  background: linear-gradient(transparent, var(--bg) 35%);
}

/* pino de mapa sem depender de imagem externa */
.pin-icon { font-size: 34px; line-height: 34px; text-align: center;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6)); }
.fieldmap { height: 40vh; border-radius: var(--radius); margin-bottom: 12px; background: #223046; }
.leaflet-popup-content button {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 12px; margin: 2px 4px 2px 0; font-size: 0.85rem; cursor: pointer;
}
.legend { display: flex; gap: 12px; margin: 8px 2px; font-size: 0.75rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }

/* painel do poste */
#pole-panel {
  position: fixed; inset: 0; z-index: 1500; background: var(--bg);
  overflow-y: auto; padding: 12px; padding-bottom: 30px; display: none;
}
#pole-panel.open { display: block; }
#pole-panel header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
#photo-zoom {
  position: fixed; inset: 0; z-index: 1600; background: rgba(0,0,0,0.95);
  display: none; align-items: center; justify-content: center;
}
#photo-zoom.open { display: flex; }
#photo-zoom img { max-width: 100%; max-height: 100%; }

/* login */
#login-overlay {
  position: fixed; inset: 0; z-index: 2000; background: var(--bg);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#login-overlay.open { display: flex; }
#login-overlay .card { width: 100%; max-width: 340px; }

/* toast */
#toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: #333f52; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 0.9rem; z-index: 2100; display: none; max-width: 90%;
  text-align: center;
}
#toast.error { background: var(--red); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
.stat { background: var(--panel2); border-radius: 8px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.25rem; }
.stat span { font-size: 0.7rem; color: var(--muted); }

/* lista de postes */
.pole-item {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  background: var(--panel2); border-radius: 8px; margin-bottom: 6px;
}
.pole-item .drag { cursor: grab; color: var(--muted); font-size: 1.1rem; touch-action: none; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; font-weight: 700; }
.badge.g { background: #1d4d31; color: var(--green); }
.badge.y { background: #4d431d; color: var(--yellow); }
.badge.r { background: #4d1d1d; color: var(--red); }
.badge.gray { background: #333f52; color: var(--muted); }

@media (min-width: 900px) {
  main { max-width: 960px; margin: 0 auto; width: 100%; }
}
