:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --yellow: #f59e0b;
  --red: #dc2626;
  --primary: #1d4ed8;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ─── Pantalla de login ──────────────────────────────────────────────────── */
.pantalla-login {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, #1e3a8a 0%, #0f172a 55%, #020617 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  text-align: center;
}
.login-brand { font-size: 2.2rem; }
.login-card h1 { font-size: 1.15rem; color: var(--text); line-height: 1.35; }
.login-sub { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.login-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}
.login-field input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  color: var(--text);
  background: #f8fafc;
}
.login-field input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.login-btn { padding: 12px; font-size: 0.95rem; }
.login-hint { font-size: 0.72rem; color: #94a3b8; }
.login-hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 5px; color: var(--primary); }

.topbar {
  background: #0f172a;
  color: #fff;
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h1 { font-size: 1.2rem; }
.topbar p { font-size: 0.8rem; color: #94a3b8; }
.fecha { font-size: 0.8rem; color: #94a3b8; }
.top-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.ciudad-label { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: #94a3b8; }
.ciudad-label select {
  background: #1e293b;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

main { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  border-top: 4px solid var(--primary);
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.stat-card.verde { border-top-color: var(--green); }
.stat-card.amarillo { border-top-color: var(--yellow); }
.stat-card.rojo { border-top-color: var(--red); }
.stat-card.total { border-top-color: var(--primary); }
.stat-card .num { font-size: 1.9rem; font-weight: 800; display: block; }
.stat-card .lbl { font-size: 0.75rem; color: var(--muted); }

.panel {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  margin-bottom: 24px;
}
.panel h2 { font-size: 1rem; margin-bottom: 16px; color: #334155; }

.map-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.map-head h2 { margin-bottom: 0; }
.map-actions { display: flex; align-items: center; gap: 10px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--muted); cursor: pointer; }
.switch input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--red); }
#btnRefrescarMapa { font-size: 1.15rem; cursor: pointer; color: var(--primary); }
#btnRefrescarMapa:disabled { cursor: wait; opacity: .5; }
#btnRefrescarMapa.girando { animation: girar .7s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

.mapa-geo {
  height: 480px;
  border-radius: 10px;
  border: 1px solid var(--border);
  z-index: 1;
}

.pin-wrap { background: transparent; border: none; }
.pin {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,.4);
}

.leyenda { display: flex; gap: 16px; margin-top: 12px; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.ley-extra { margin-left: auto; font-style: italic; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; }

.mapa { display: flex; flex-direction: column; gap: 10px; }
.comuna-row {
  display: grid;
  grid-template-columns: 140px 1fr 70px 70px 70px;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
.comuna-row .name { font-weight: 600; }
.bar-track { background: #f1f5f9; border-radius: 6px; height: 20px; overflow: hidden; display: flex; }
.bar-track .g { background: var(--green); }
.bar-track .y { background: var(--yellow); }
.bar-track .r { background: var(--red); }
.cell { text-align: right; font-weight: 700; }
.cell.g { color: var(--green); }
.cell.y { color: #b45309; }
.cell.r { color: var(--red); }

.two-col { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; }

.barras { display: flex; flex-direction: column; gap: 10px; }
.barra-tipo { display: grid; grid-template-columns: 130px 1fr 40px; align-items: center; gap: 8px; font-size: 0.8rem; }
.barra-tipo .bt-track { background: #f1f5f9; height: 16px; border-radius: 6px; overflow: hidden; }
.barra-tipo .bt-fill { background: var(--primary); height: 100%; }
.barra-tipo .bt-num { text-align: right; font-weight: 700; }

.tabla { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.tabla th, .tabla td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); }
.tabla th { color: var(--muted); font-weight: 600; }
.tag { padding: 2px 8px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; color: #fff; }
.muted { color: var(--muted); font-size: 0.72rem; }
.hash { font-family: ui-monospace, monospace; font-size: 0.7rem; color: #0f766e; background: #ecfeff; padding: 2px 5px; border-radius: 4px; }
.tag.VERDE { background: var(--green); }
.tag.AMARILLO { background: var(--yellow); color: #451a03; }
.tag.ROJO { background: var(--red); }
.tag.ANULADA, .tag.INACTIVO { background: #64748b; }

/* ─── Tabs / navegación ─────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 8px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 20px 0;
}
.tab {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.tab.active {
  color: var(--primary);
  border-top: 3px solid var(--primary);
  background: var(--bg);
}
.hidden { display: none !important; }

/* ─── Administración ────────────────────────────────────────────────────── */
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.sub-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.sub-tab {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.sub-tab:hover { border-color: var(--primary); color: var(--primary); }
.sub-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.admin-head h2 { margin-bottom: 0; }
.admin-filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admin-filtros input, .admin-filtros select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  background: #fff;
}
.admin-tabla td { vertical-align: top; }
.admin-tabla .acciones { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-tabla button {
  padding: 5px 10px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.admin-tabla button:hover { background: #f1f5f9; }
.admin-tabla button.peligro { color: var(--red); border-color: #fecaca; }
.admin-tabla button.peligro:hover { background: #fef2f2; }

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.peligro { color: var(--red); border-color: #fecaca; }
.btn.peligro:hover { background: #fef2f2; }
.btn.icono { border: none; background: transparent; font-size: 1rem; }
.btn.link { border: none; background: transparent; color: var(--red); padding: 4px 6px; font-weight: 500; }
.btn.link:hover { background: #fef2f2; text-decoration: underline; }
.btn.small { padding: 4px 10px; font-size: 0.78rem; }
/* Botón de cerrar sesión sobre la barra superior oscura */
.top-actions .btn.icono { color: #fff; font-size: 1.2rem; padding: 6px 10px; border-radius: 8px; }
.top-actions .btn.icono:hover { background: rgba(255, 255, 255, 0.12); color: #f87171; }

/* ─── Configuración de dictámenes ───────────────────────────────────────── */
.cfg-title { font-size: 0.9rem; color: #334155; margin: 20px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.cfg-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.cfg-grid input, .cfg-grid select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
  background: #fff;
}
.cfg-grid input[type="color"] { height: 40px; padding: 4px; cursor: pointer; }
.cfg-grid .check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
.cfg-grid .check.upload { flex-wrap: wrap; }
.logo-preview { max-width: 120px; max-height: 56px; object-fit: contain; border: 1px dashed var(--border); border-radius: 8px; padding: 4px; }
.cfg-note { margin-top: 16px; }
.cfg-note code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; }

/* ─── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 1000;
  overflow-y: auto;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1rem; }
.modal #modalBody { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.modal input, .modal select, .modal textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
}
.modal label.check { flex-direction: row; align-items: center; gap: 8px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.modal-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dano-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dano-row { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }

.modal.login { max-width: 380px; }
.modal.login #loginBody { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal.login label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.modal.login input { padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; color: var(--text); }
.error { color: #dc2626; font-size: 0.8rem; margin: 0; }
.user-info { font-size: 0.8rem; color: #cbd5e1; background: #1e293b; padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.btn.icono { padding: 6px 10px; }

@media (max-width: 700px) {
  .modal-row2, .dano-grid { grid-template-columns: 1fr; }
  .admin-tabla { font-size: 0.72rem; }
}

@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
  .comuna-row { grid-template-columns: 100px 1fr 50px 50px 50px; }
}
