:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232831;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #4caf50;
  --accent-2: #2e7d32;
  --danger: #e53935;
  --border: #2a2f3a;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body {
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  max-width: 720px;
  margin: 0 auto;
}

header h1 {
  font-size: 22px;
  margin: 8px 0 4px;
}

header p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.captura {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 28px;
}

.btn {
  font-size: 16px;
  padding: 18px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: background .15s;
}

.btn:hover { background: var(--panel-2); }
.btn .ico { font-size: 28px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-2);
  color: white;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.hidden-input { display: none; }

section.lista h2 {
  font-size: 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0 0 12px;
}

#lista-vacas {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.vaca-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.vaca-item:hover { background: var(--panel-2); }

.vaca-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--panel-2);
}

.vaca-info {
  display: flex;
  flex-direction: column;
}

.vaca-info strong { font-size: 18px; }
.vaca-info span { color: var(--muted); font-size: 13px; }

#lista-vacia {
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: min(92vw, 480px);
  max-height: 90vh;
  overflow: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

dialog h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.proc {
  text-align: center;
  padding: 8px 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.foto-preview {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--panel-2);
  display: block;
  margin-bottom: 12px;
}

.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 12px;
  margin: 8px 0 16px;
  font-size: 15px;
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

#v-numero { font-size: 22px; font-weight: 700; }

form .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

form label {
  font-size: 13px;
  color: var(--muted);
}

form input[type="text"],
form input[type="date"] {
  font-size: 16px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
}

form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.radio-row {
  display: flex;
  gap: 16px;
  font-size: 16px;
  align-items: center;
}

.radio-row label {
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.hint {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.crop-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  margin-bottom: 12px;
  line-height: 0;
}

.crop-wrap img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  border-radius: 8px;
  -webkit-user-drag: none;
  pointer-events: none;
}

#crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  cursor: move;
  box-sizing: border-box;
}

.crop-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  background: var(--accent);
  border: 2px solid white;
  border-radius: 50%;
  touch-action: none;
}

.crop-handle.tl { top: -12px; left: -12px; cursor: nwse-resize; }
.crop-handle.tr { top: -12px; right: -12px; cursor: nesw-resize; }
.crop-handle.bl { bottom: -12px; left: -12px; cursor: nesw-resize; }
.crop-handle.br { bottom: -12px; right: -12px; cursor: nwse-resize; }

.candidatos {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.candidatos-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}

.candidatos-chip:hover { background: var(--accent); border-color: var(--accent); color: white; }

.region-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.region-preview canvas {
  display: block;
  max-width: 140px;
  max-height: 100px;
  height: auto;
  width: auto;
  border-radius: 6px;
  background: white;
  flex-shrink: 0;
}

.region-preview .hint { margin: 0; }
