@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Syne:wght@700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f8f6;
  --white: #ffffff;
  --ink: #111110;
  --ink-mid: #3a3a38;
  --ink-soft: #6b6b68;
  --ink-muted: #a8a8a4;
  --accent: #c0392b;
  --accent-light: #fdf0ee;
  --border: #e4e4e0;
  --border-strong: #c8c8c4;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ── HEADER ── */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Brasão oficial do batalhão. Altura fixa e largura automática: ele é
   mais alto que largo, e travar os dois deformaria o escudo. */
.brand-mark {
  height: 46px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand-text h1 {
  font-family: 'Syne', sans-serif;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--ink);
  line-height: 1;
}

.brand-text h1 span {
  color: var(--accent);
}

.brand-text p {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.5px;
  color: var(--ink-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.reg-num {
  font-family: 'Inter', monospace;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 1px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent-light);
  border: 1px solid rgba(192,57,43,0.15);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
}

.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.7;
}

.status-pill.foragido {
  background: #c0392b;
  border-color: #922b21;
  color: #fff;
}
.status-pill.foragido::before { background: #fff; opacity: 1; }

.btn-foragido {
  padding: 6px 14px;
  border-radius: 20px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid #c0392b;
  background: transparent;
  color: #c0392b;
  transition: all 0.15s;
}
.btn-foragido:hover { background: #c0392b; color: #fff; }
.btn-foragido.ativo { background: #c0392b; color: #fff; border-color: #922b21; }
.btn-foragido.ativo:hover { background: #922b21; }

.banner-foragido {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #c0392b;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px;
  margin-bottom: 16px;
  border-radius: 8px;
}
.banner-foragido.show { display: flex; }

/* ── LAYOUT ── */
.wrapper {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ── SECTION ── */
.section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
}

.section-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.section-icon svg { display: block; }

.section-head h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-mid);
}

.section-body { padding: 24px; }

/* ── FIELDS ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 90px; gap: 16px 20px; }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }

/* ── CEP (autopreenchimento) ── */
.cep-field { max-width: 260px; margin-bottom: 20px; }
.cep-hint { font-size: 10px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink-muted); }
.cep-input-wrap { position: relative; }
.cep-input-wrap input { padding-right: 38px; }
.cep-spinner {
  display: none;
  position: absolute; top: 50%; right: 13px; transform: translateY(-50%);
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: cep-spin 0.7s linear infinite;
}
.cep-spinner.show { display: block; }
@keyframes cep-spin { to { transform: translateY(-50%) rotate(360deg); } }
.cep-check {
  display: none;
  position: absolute; top: 50%; right: 11px; transform: translateY(-50%);
}
.cep-check.show { display: block; animation: cep-check-pop 0.25s ease; }
@keyframes cep-check-pop { from { transform: translateY(-50%) scale(0.5); opacity: 0; } to { transform: translateY(-50%) scale(1); opacity: 1; } }

.field-autofilled input {
  animation: field-flash 1.1s ease;
}
@keyframes field-flash {
  0% { background: #e6f7ec; border-color: #1f8a4c; }
  100% { background: var(--bg); border-color: var(--border); }
}

.field { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

label .req { color: var(--accent); margin-left: 2px; }

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 10px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  width: 100%;
}

input:hover, select:hover { border-color: var(--border-strong); }

input:focus, select:focus, textarea:focus {
  border-color: var(--ink);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(17,17,16,0.06);
}

input::placeholder, textarea::placeholder { color: var(--ink-muted); font-size: 13px; }
select option { background: var(--white); color: var(--ink); }
textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
.field-hint { font-size: 11px; color: var(--ink-muted); }

/* iOS da largura intrinseca ao campo de data e ele nao encolhe sozinho */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  max-width: 100%;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-calendar-picker-indicator { margin-left: auto; }

/* iOS Safari da zoom em qualquer campo com fonte < 16px ao receber foco */
@media (max-width: 768px) {
  input, select, textarea { font-size: 16px; }
  input::placeholder, textarea::placeholder { font-size: 15px; }
}

/* ── FOTO PERFIL ── */
.top-block { display: flex; gap: 24px; }

.photo-col { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }

.photo-box {
  width: 130px;
  height: 163px;
  background: var(--bg);
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color 0.2s, background 0.15s;
  position: relative; overflow: hidden;
}
.photo-box:hover { border-color: var(--ink); background: #f0f0ec; }
.photo-box img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.photo-ph { display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.photo-ph svg { opacity: 0.3; }
.photo-ph span { font-size: 10px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-muted); text-align: center; line-height: 1.4; }
.photo-caption { font-size: 10px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-muted); }
#photoInput { display: none; }

.fields-col { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }

/* ── MAPS ── */
.maps-wrap {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.maps-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.maps-bar-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--ink-soft);
}

.maps-open-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 6px;
  background: transparent; border: 1px solid var(--border-strong);
  color: var(--ink-mid); font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; letter-spacing: 0.5px;
}
.maps-open-btn:hover { border-color: var(--ink); color: var(--ink); background: var(--bg); }

.maps-frame { position: relative; height: 240px; }
.maps-frame iframe { width: 100%; height: 100%; border: none; display: block; }
.maps-ph {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--ink-muted); background: var(--bg);
}
.maps-ph svg { opacity: 0.25; }
.maps-ph span { font-size: 11px; font-weight: 500; letter-spacing: 0.5px; color: var(--ink-muted); }

/* ── ALBUM ── */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.album-item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--bg);
}
.album-item:hover { border-color: var(--ink); box-shadow: var(--shadow-md); }
.album-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-item .rm {
  position: absolute; top: 5px; right: 5px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity 0.15s;
  font-size: 11px; color: var(--ink); font-weight: 600;
}
.album-item:hover .rm { opacity: 1; }

.album-add {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1.5px dashed var(--border-strong);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; cursor: pointer; transition: border-color 0.15s, background 0.15s;
  background: var(--bg);
}
.album-add:hover { border-color: var(--ink); background: #f0f0ec; }
.album-add svg { opacity: 0.3; }
.album-add span { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-muted); }
#albumInput { display: none; }

.album-count-tag {
  margin-left: auto;
  padding: 2px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
}

/* ── LIGHTBOX ── */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 999;
  background: rgba(17,17,16,0.9);
  align-items: center; justify-content: center; flex-direction: column; gap: 20px;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 88vw; max-height: 76vh; border-radius: 10px; object-fit: contain; box-shadow: 0 24px 64px rgba(0,0,0,0.5); }
.lb-close {
  position: absolute; top: 20px; right: 24px;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s;
}
.lb-close:hover { background: rgba(255,255,255,0.2); color: white; }
.lb-nav { display: flex; gap: 12px; align-items: center; }
.lb-nav button {
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; color: rgba(255,255,255,0.8);
  padding: 8px 18px; font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.lb-nav button:hover { background: rgba(255,255,255,0.18); color: white; }
.lb-counter { font-size: 11px; font-weight: 500; color: rgba(255,255,255,0.4); letter-spacing: 1px; min-width: 52px; text-align: center; }

/* ── ACTIONS ── */
.page-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 24px;
  padding: 20px 24px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.actions-ts { font-size: 11px; font-weight: 500; color: var(--ink-muted); letter-spacing: 0.5px; }

.btn-group { display: flex; gap: 10px; }

.btn {
  padding: 10px 22px; border-radius: var(--radius);
  font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s;
}
.btn-ghost {
  background: transparent; border: 1px solid var(--border-strong); color: var(--ink-soft);
}
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); background: var(--bg); }
.btn-save {
  background: var(--ink); color: var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.btn-save:hover { background: #2a2a28; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.btn-save:active { transform: translateY(0); }

.toast {
  display: none; align-items: center; gap: 10px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  margin-top: 12px; font-size: 13px; color: var(--ink-mid);
  box-shadow: var(--shadow);
}
.toast.show { display: flex; }
.toast.error { border-color: rgba(192,57,43,0.25); background: var(--accent-light); color: var(--accent); }
.toast.success { border-left: 3px solid #27ae60; }
.toast.error { border-left: 3px solid var(--accent); }

/* ── AUTH ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 48px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}
.auth-card h1 {
  font-family: 'Syne', sans-serif;
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
  text-align: center;
}
.auth-card h1 span { color: var(--accent); }
.auth-sub {
  font-size: 12px;
  color: var(--ink-muted);
  margin-bottom: 28px;
  text-align: center;
}

/* ── LISTA ── */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.search-bar input { flex: 1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:hover { background: var(--bg); }
tbody td { padding: 12px 14px; font-size: 13px; }
.avatar-mini {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
  display: block;
}
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pagination button {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--white);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-mid);
  font-family: 'Inter', sans-serif;
  transition: all 0.15s;
}
.pagination button.active { background: var(--ink); color: var(--white); border-color: var(--ink); }
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── VÍNCULOS ── */
.vinculos-list { display: flex; flex-direction: column; gap: 2px; }
.vinculo-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: 8px;
  text-decoration: none; transition: background 0.12s;
}
.vinculo-item:hover { background: var(--bg); }
.vinculo-photo {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  background: var(--bg); border: 1px solid var(--border); flex-shrink: 0;
}
.vinculo-photo-ph {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.vinculo-info { flex: 1; min-width: 0; }
.vinculo-nome { font-size: 13px; font-weight: 600; color: var(--ink); }
.vinculo-numero { font-size: 10.5px; color: var(--ink-muted); font-family: monospace; }
.vinculo-obs { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; font-style: italic; }
.vinculo-tipo {
  font-size: 10.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  white-space: nowrap; flex-shrink: 0;
}
.vinculo-tipo.pai_mae      { background: #e0eafc; color: #2255aa; }
.vinculo-tipo.avo_neto     { background: #e7e3fa; color: #4c3aa8; }
.vinculo-tipo.tio_sobrinho { background: #dff3f1; color: #157a72; }
.vinculo-tipo.irmao        { background: #e6f7ec; color: #1f8a4c; }
.vinculo-tipo.primo        { background: #f1f7e0; color: #6b8f1f; }
.vinculo-tipo.conjuge      { background: #fde8f1; color: #b8317a; }
.vinculo-tipo.ex_conjuge   { background: #f3e8ee; color: #9a5a78; }
.vinculo-tipo.amigo        { background: #e0f3f7; color: #1a8fa3; }
.vinculo-tipo.associado    { background: #fdeee0; color: #b8611a; }
.vinculo-tipo.vitima       { background: #fbe5e2; color: #c0392b; }
.vinculo-tipo.outro        { background: var(--bg); color: var(--ink-muted); border: 1px solid var(--border); }
.vinculo-del {
  background: none; border: none; cursor: pointer; color: var(--border-strong);
  padding: 4px; flex-shrink: 0; display: flex;
}
.vinculo-del:hover { color: #c0392b; }

/* ── MODAL OCORRÊNCIA ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(17,17,16,0.5);
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-card {
  background: var(--white);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  margin: 0 16px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-head h3 { font-size: 14px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink-muted);
  line-height: 1;
}

/* ── OCORRÊNCIAS LIST ── */
.oc-list { display: flex; flex-direction: column; gap: 12px; }
.oc-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.oc-meta { font-size: 11px; color: var(--ink-muted); margin-bottom: 6px; }
.oc-meta strong { color: var(--accent); font-weight: 600; }
.oc-desc { font-size: 13px; color: var(--ink); line-height: 1.6; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-muted);
  font-size: 13px;
}

/* ── RESPONSIVO / MOBILE ── */
@media (max-width: 640px) {
  .header {
    padding: 0 14px;
    height: 60px;
    gap: 8px;
  }
  .header-brand { gap: 10px; }
  .brand-mark { height: 38px; width: auto; }
  .brand-text h1 { font-size: 15px; }
  .brand-text p { display: none; }
  .header-right { gap: 8px; }
  .header-right .reg-num { display: none; }
  .status-pill { padding: 4px 9px; font-size: 9px; }
  .header-right .btn { padding: 7px 12px; font-size: 12px; }

  .wrapper { padding: 16px 12px 60px; }

  /* foto centralizada (o próprio .photo-col/.view-photo-col já se centraliza),
     mas os campos de informação ocupam a largura toda e ficam alinhados à esquerda */
  .top-block { flex-direction: column; gap: 14px; }
  .fields-col, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2, .span-full { grid-column: 1; }

  .page-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 16px;
  }
  .actions-ts { text-align: center; }
  .btn-group { flex-direction: column; }
  .btn-group .btn { width: 100%; }

  .album-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

  .section-head {
    padding: 14px 16px;
    flex-wrap: wrap;
  }
  .section-head h2 { font-size: 13px; }
  .section-head > a, .section-head > button {
    margin-left: 0 !important;
    order: 3;
  }
  .section-body { padding: 16px; }
}
